kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Refactor code
rodzic
0877e388d2
commit
575c81cde9
|
@ -1,4 +1,3 @@
|
||||||
import toast from 'soapbox/toast.tsx';
|
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth.ts';
|
import { isLoggedIn } from 'soapbox/utils/auth.ts';
|
||||||
|
|
||||||
import api from '../api/index.ts';
|
import api from '../api/index.ts';
|
||||||
|
@ -74,10 +73,6 @@ const FAVOURITES_EXPAND_FAIL = 'FAVOURITES_EXPAND_FAIL';
|
||||||
const REBLOGS_EXPAND_SUCCESS = 'REBLOGS_EXPAND_SUCCESS';
|
const REBLOGS_EXPAND_SUCCESS = 'REBLOGS_EXPAND_SUCCESS';
|
||||||
const REBLOGS_EXPAND_FAIL = 'REBLOGS_EXPAND_FAIL';
|
const REBLOGS_EXPAND_FAIL = 'REBLOGS_EXPAND_FAIL';
|
||||||
|
|
||||||
const NUTZAP_REQUEST = 'NUTZAP_REQUEST';
|
|
||||||
const NUTZAP_SUCCESS = 'NUTZAP_SUCCESS';
|
|
||||||
const NUTZAP_FAIL = 'NUTZAP_FAIL';
|
|
||||||
|
|
||||||
const ZAP_REQUEST = 'ZAP_REQUEST';
|
const ZAP_REQUEST = 'ZAP_REQUEST';
|
||||||
const ZAP_SUCCESS = 'ZAP_SUCCESS';
|
const ZAP_SUCCESS = 'ZAP_SUCCESS';
|
||||||
const ZAP_FAIL = 'ZAP_FAIL';
|
const ZAP_FAIL = 'ZAP_FAIL';
|
||||||
|
@ -362,57 +357,6 @@ const zapFail = (status: StatusEntity, error: unknown) => ({
|
||||||
skipLoading: true,
|
skipLoading: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const nutzap = (account: AccountEntity, status: StatusEntity | undefined, amount: number, comment: string) =>
|
|
||||||
async (dispatch: AppDispatch, getState: () => RootState) => {
|
|
||||||
if (!isLoggedIn(getState)) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await api(getState).post('/api/v1/ditto/cashu/nutzap', {
|
|
||||||
amount,
|
|
||||||
comment,
|
|
||||||
account_id: account.id,
|
|
||||||
status_id: status?.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
toast.success(data.message);
|
|
||||||
} else {
|
|
||||||
toast.success('Nutzap sent successfully!');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status) dispatch(nutzapSuccess(status));
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof Error) {
|
|
||||||
toast.error(e.message);
|
|
||||||
} else {
|
|
||||||
toast.error('An unexpected error occurred');
|
|
||||||
}
|
|
||||||
if (status) dispatch(nutzapFail(status, e));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const nutzapRequest = (status: StatusEntity) => ({
|
|
||||||
type: NUTZAP_REQUEST,
|
|
||||||
status: status,
|
|
||||||
skipLoading: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const nutzapSuccess = (status: StatusEntity) => ({
|
|
||||||
type: NUTZAP_SUCCESS,
|
|
||||||
status: status,
|
|
||||||
skipLoading: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const nutzapFail = (status: StatusEntity, error: unknown) => ({
|
|
||||||
type: NUTZAP_FAIL,
|
|
||||||
status: status,
|
|
||||||
error: error,
|
|
||||||
skipLoading: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const bookmarkRequest = (status: StatusEntity) => ({
|
const bookmarkRequest = (status: StatusEntity) => ({
|
||||||
type: BOOKMARK_REQUEST,
|
type: BOOKMARK_REQUEST,
|
||||||
status: status,
|
status: status,
|
||||||
|
@ -849,9 +793,6 @@ export {
|
||||||
FAVOURITES_EXPAND_FAIL,
|
FAVOURITES_EXPAND_FAIL,
|
||||||
REBLOGS_EXPAND_SUCCESS,
|
REBLOGS_EXPAND_SUCCESS,
|
||||||
REBLOGS_EXPAND_FAIL,
|
REBLOGS_EXPAND_FAIL,
|
||||||
NUTZAP_REQUEST,
|
|
||||||
NUTZAP_SUCCESS,
|
|
||||||
NUTZAP_FAIL,
|
|
||||||
ZAP_REQUEST,
|
ZAP_REQUEST,
|
||||||
ZAP_FAIL,
|
ZAP_FAIL,
|
||||||
ZAPS_FETCH_REQUEST,
|
ZAPS_FETCH_REQUEST,
|
||||||
|
@ -923,10 +864,6 @@ export {
|
||||||
remoteInteractionRequest,
|
remoteInteractionRequest,
|
||||||
remoteInteractionSuccess,
|
remoteInteractionSuccess,
|
||||||
remoteInteractionFail,
|
remoteInteractionFail,
|
||||||
nutzapRequest,
|
|
||||||
nutzapSuccess,
|
|
||||||
nutzapFail,
|
|
||||||
nutzap,
|
|
||||||
zap,
|
zap,
|
||||||
fetchZaps,
|
fetchZaps,
|
||||||
expandZaps,
|
expandZaps,
|
||||||
|
|
|
@ -25,7 +25,6 @@ import { useNutzapRequest } from 'soapbox/features/zap/hooks/useHooks.ts';
|
||||||
import { usePaymentMethod } from 'soapbox/features/zap/usePaymentMethod.ts';
|
import { usePaymentMethod } from 'soapbox/features/zap/usePaymentMethod.ts';
|
||||||
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
||||||
import { emojifyText } from 'soapbox/utils/emojify.tsx';
|
import { emojifyText } from 'soapbox/utils/emojify.tsx';
|
||||||
import { capitalize } from 'soapbox/utils/strings.ts';
|
|
||||||
|
|
||||||
import PaymentButton from './zap-button/payment-button.tsx';
|
import PaymentButton from './zap-button/payment-button.tsx';
|
||||||
|
|
||||||
|
@ -48,8 +47,8 @@ interface IPayRequestForm {
|
||||||
const closeIcon = xIcon;
|
const closeIcon = xIcon;
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
zap_button_rounded: { id: 'zap.button.text.rounded', defaultMessage: '{method} {amount}K sats' },
|
zap_button_rounded: { id: 'zap.button.text.rounded', defaultMessage: 'Zap {amount}K sats' },
|
||||||
zap_button: { id: 'payment_method.button.text.raw', defaultMessage: '{method} {amount} sats' },
|
zap_button: { id: 'payment_method.button.text.raw', defaultMessage: 'Zap {amount} sats' },
|
||||||
zap_commentPlaceholder: { id: 'payment_method.comment_input.placeholder', defaultMessage: 'Optional comment' },
|
zap_commentPlaceholder: { id: 'payment_method.comment_input.placeholder', defaultMessage: 'Optional comment' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -108,9 +107,9 @@ const PayRequestForm = ({ account, status, onClose }: IPayRequestForm) => {
|
||||||
|
|
||||||
const renderPaymentButtonText = () => {
|
const renderPaymentButtonText = () => {
|
||||||
if (amount >= 1000) {
|
if (amount >= 1000) {
|
||||||
return intl.formatMessage(messages.zap_button_rounded, { amount: Math.round((amount / 1000) * 10) / 10, method: isCashu ? 'Nutzap' : capitalize(paymentMethod) });
|
return intl.formatMessage(messages.zap_button_rounded, { amount: Math.round((amount / 1000) * 10) / 10 });
|
||||||
}
|
}
|
||||||
return intl.formatMessage(messages.zap_button, { amount: amount, method: isCashu ? 'Nutzap' : capitalize(paymentMethod) });
|
return intl.formatMessage(messages.zap_button, { amount: amount });
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -177,7 +177,7 @@ const useNutzapRequest = () => {
|
||||||
addNutzap(status.id, { status, amount, comment });
|
addNutzap(status.id, { status, amount, comment });
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success(data.message || 'Nutzap sent successfully!');
|
toast.success(data.message || 'Zap sent successfully!');
|
||||||
getWallet();
|
getWallet();
|
||||||
getTransactions();
|
getTransactions();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -1295,7 +1295,7 @@
|
||||||
"password_reset.reset": "Reset password",
|
"password_reset.reset": "Reset password",
|
||||||
"patron.donate": "Donate",
|
"patron.donate": "Donate",
|
||||||
"patron.title": "Funding Goal",
|
"patron.title": "Funding Goal",
|
||||||
"payment_method.button.text.raw": "{method} {amount} sats",
|
"payment_method.button.text.raw": "Zap {amount} sats",
|
||||||
"payment_method.comment_input.placeholder": "Optional comment",
|
"payment_method.comment_input.placeholder": "Optional comment",
|
||||||
"payment_method.send_to": "Send {method} to {target}",
|
"payment_method.send_to": "Send {method} to {target}",
|
||||||
"payment_method.split_message.deducted": "{amountDeducted} sats will deducted*",
|
"payment_method.split_message.deducted": "{amountDeducted} sats will deducted*",
|
||||||
|
@ -1743,7 +1743,7 @@
|
||||||
"wallet.transactions.no_transactions": "You don't have transactions yet.",
|
"wallet.transactions.no_transactions": "You don't have transactions yet.",
|
||||||
"wallet.transactions.show_more": "Show More",
|
"wallet.transactions.show_more": "Show More",
|
||||||
"who_to_follow.title": "People To Follow",
|
"who_to_follow.title": "People To Follow",
|
||||||
"zap.button.text.rounded": "{method} {amount}K sats",
|
"zap.button.text.rounded": "Zap {amount}K sats",
|
||||||
"zap.finish": "Finish",
|
"zap.finish": "Finish",
|
||||||
"zap.next": "Next",
|
"zap.next": "Next",
|
||||||
"zap.open_wallet": "Open Wallet",
|
"zap.open_wallet": "Open Wallet",
|
||||||
|
|
|
@ -1626,7 +1626,7 @@
|
||||||
"video.play": "Reproducir",
|
"video.play": "Reproducir",
|
||||||
"video.unmute": "Dejar de silenciar sonido",
|
"video.unmute": "Dejar de silenciar sonido",
|
||||||
"who_to_follow.title": "Personas a seguir",
|
"who_to_follow.title": "Personas a seguir",
|
||||||
"payment_method.button.text.raw": "{method} {amount} sats",
|
"payment_method.button.text.raw": "Zap {amount} sats",
|
||||||
"payment_method.comment_input.placeholder": "Comentario opcional",
|
"payment_method.comment_input.placeholder": "Comentario opcional",
|
||||||
"zap.open_wallet": "Abrir Wallet",
|
"zap.open_wallet": "Abrir Wallet",
|
||||||
"zap.send_to": "Enviar zaps a {target}",
|
"zap.send_to": "Enviar zaps a {target}",
|
||||||
|
|
|
@ -1679,8 +1679,8 @@
|
||||||
"video.play": "Seinn",
|
"video.play": "Seinn",
|
||||||
"video.unmute": "Fuaim gan iomrá",
|
"video.unmute": "Fuaim gan iomrá",
|
||||||
"who_to_follow.title": "Daoine le Leanúint",
|
"who_to_follow.title": "Daoine le Leanúint",
|
||||||
"payment_method.button.text.raw": "Suíonn {method} {amount}",
|
"payment_method.button.text.raw": "Suíonn Zap {amount}",
|
||||||
"zap.button.text.rounded": "{method} {amount}K shuíonn",
|
"zap.button.text.rounded": "Zap {amount}K shuíonn",
|
||||||
"payment_method.comment_input.placeholder": "Nóta roghnach",
|
"payment_method.comment_input.placeholder": "Nóta roghnach",
|
||||||
"zap.finish": "Críochnaigh",
|
"zap.finish": "Críochnaigh",
|
||||||
"zap.next": "Ar Aghaidh",
|
"zap.next": "Ar Aghaidh",
|
||||||
|
|
|
@ -1635,7 +1635,7 @@
|
||||||
"video.play": "Reproduzir",
|
"video.play": "Reproduzir",
|
||||||
"video.unmute": "Reativar som",
|
"video.unmute": "Reativar som",
|
||||||
"who_to_follow.title": "Quem seguir",
|
"who_to_follow.title": "Quem seguir",
|
||||||
"payment_method.button.text.raw": "{method} {amount} sats",
|
"payment_method.button.text.raw": "Zap {amount} sats",
|
||||||
"payment_method.comment_input.placeholder": "Comentário opcional",
|
"payment_method.comment_input.placeholder": "Comentário opcional",
|
||||||
"zap.open_wallet": "Abrir Carteira",
|
"zap.open_wallet": "Abrir Carteira",
|
||||||
"zap.send_to": "Enviar zaps para {target}",
|
"zap.send_to": "Enviar zaps para {target}",
|
||||||
|
|
|
@ -28,8 +28,6 @@ import {
|
||||||
DISLIKE_REQUEST,
|
DISLIKE_REQUEST,
|
||||||
UNDISLIKE_REQUEST,
|
UNDISLIKE_REQUEST,
|
||||||
DISLIKE_FAIL,
|
DISLIKE_FAIL,
|
||||||
NUTZAP_FAIL,
|
|
||||||
NUTZAP_SUCCESS,
|
|
||||||
ZAP_REQUEST,
|
ZAP_REQUEST,
|
||||||
ZAP_FAIL,
|
ZAP_FAIL,
|
||||||
} from '../actions/interactions.ts';
|
} from '../actions/interactions.ts';
|
||||||
|
@ -239,7 +237,6 @@ const simulatePayment = (state: State, statusId: string, paid: boolean, method:
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return state.set(statusId, updatedStatus);
|
return state.set(statusId, updatedStatus);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,10 +298,6 @@ export default function statuses(state = initialState, action: AnyAction): State
|
||||||
return simulatePayment(state, action.status.id, true, 'zap');
|
return simulatePayment(state, action.status.id, true, 'zap');
|
||||||
case ZAP_FAIL:
|
case ZAP_FAIL:
|
||||||
return simulatePayment(state, action.status.id, false, 'zap');
|
return simulatePayment(state, action.status.id, false, 'zap');
|
||||||
case NUTZAP_SUCCESS:
|
|
||||||
return simulatePayment(state, action.status.id, true, 'cashu');
|
|
||||||
case NUTZAP_FAIL:
|
|
||||||
return simulatePayment(state, action.status.id, false, 'cashu');
|
|
||||||
case REBLOG_REQUEST:
|
case REBLOG_REQUEST:
|
||||||
return state.setIn([action.status.id, 'reblogged'], true);
|
return state.setIn([action.status.id, 'reblogged'], true);
|
||||||
case REBLOG_FAIL:
|
case REBLOG_FAIL:
|
||||||
|
|
Ładowanie…
Reference in New Issue