Payment Modal: Keep verification in the same tab (#6889)
This commit is contained in:
parent
5841fddd0e
commit
04d45b2275
@ -36,10 +36,15 @@ import {
|
|||||||
serializeBytes,
|
serializeBytes,
|
||||||
} from '../helpers/misc';
|
} from '../helpers/misc';
|
||||||
import localDb from '../localDb';
|
import localDb from '../localDb';
|
||||||
import { sendApiUpdate } from '../updates/apiUpdateEmitter';
|
|
||||||
import { handleGramJsUpdate, invokeRequest } from './client';
|
import { handleGramJsUpdate, invokeRequest } from './client';
|
||||||
import { getTemporaryPaymentPassword } from './twoFaSettings';
|
import { getTemporaryPaymentPassword } from './twoFaSettings';
|
||||||
|
|
||||||
|
type SendPaymentFormResult = {
|
||||||
|
completed: true;
|
||||||
|
} | {
|
||||||
|
verificationUrl: string;
|
||||||
|
};
|
||||||
|
|
||||||
export async function validateRequestedInfo({
|
export async function validateRequestedInfo({
|
||||||
inputInvoice,
|
inputInvoice,
|
||||||
requestInfo,
|
requestInfo,
|
||||||
@ -90,7 +95,7 @@ export async function sendPaymentForm({
|
|||||||
savedCredentialId?: string;
|
savedCredentialId?: string;
|
||||||
temporaryPassword?: string;
|
temporaryPassword?: string;
|
||||||
tipAmount?: number;
|
tipAmount?: number;
|
||||||
}) {
|
}): Promise<SendPaymentFormResult | undefined> {
|
||||||
const inputCredentials = temporaryPassword && savedCredentialId
|
const inputCredentials = temporaryPassword && savedCredentialId
|
||||||
? new GramJs.InputPaymentCredentialsSaved({
|
? new GramJs.InputPaymentCredentialsSaved({
|
||||||
id: savedCredentialId,
|
id: savedCredentialId,
|
||||||
@ -109,20 +114,19 @@ export async function sendPaymentForm({
|
|||||||
...(tipAmount && { tipAmount: BigInt(tipAmount) }),
|
...(tipAmount && { tipAmount: BigInt(tipAmount) }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (!result) return false;
|
if (!result) return undefined;
|
||||||
|
|
||||||
if (result instanceof GramJs.payments.PaymentVerificationNeeded) {
|
if (result instanceof GramJs.payments.PaymentVerificationNeeded) {
|
||||||
sendApiUpdate({
|
return {
|
||||||
'@type': 'updatePaymentVerificationNeeded',
|
verificationUrl: result.url,
|
||||||
url: result.url,
|
};
|
||||||
});
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
} else {
|
|
||||||
handleGramJsUpdate(result.updates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boolean(result);
|
handleGramJsUpdate(result.updates);
|
||||||
|
|
||||||
|
return {
|
||||||
|
completed: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendStarPaymentForm({
|
export async function sendStarPaymentForm({
|
||||||
|
|||||||
@ -610,11 +610,6 @@ export type ApiUpdatePeerBlocked = {
|
|||||||
isBlockedFromStories?: boolean;
|
isBlockedFromStories?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ApiUpdatePaymentVerificationNeeded = {
|
|
||||||
'@type': 'updatePaymentVerificationNeeded';
|
|
||||||
url: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ApiUpdatePaymentStateCompleted = {
|
export type ApiUpdatePaymentStateCompleted = {
|
||||||
'@type': 'updatePaymentStateCompleted';
|
'@type': 'updatePaymentStateCompleted';
|
||||||
paymentState: TabState['payment'];
|
paymentState: TabState['payment'];
|
||||||
@ -953,7 +948,7 @@ export type ApiUpdate = (
|
|||||||
ApiUpdateServerTimeOffset | ApiUpdateMessageReactions | ApiUpdateSavedReactionTags |
|
ApiUpdateServerTimeOffset | ApiUpdateMessageReactions | ApiUpdateSavedReactionTags |
|
||||||
ApiUpdateGroupCallParticipants | ApiUpdateGroupCallConnection | ApiUpdateGroupCall | ApiUpdateGroupCallStreams |
|
ApiUpdateGroupCallParticipants | ApiUpdateGroupCallConnection | ApiUpdateGroupCall | ApiUpdateGroupCallStreams |
|
||||||
ApiUpdateGroupCallConnectionState | ApiUpdateGroupCallLeavePresentation | ApiUpdateGroupCallChatId |
|
ApiUpdateGroupCallConnectionState | ApiUpdateGroupCallLeavePresentation | ApiUpdateGroupCallChatId |
|
||||||
ApiUpdatePendingJoinRequests | ApiUpdatePaymentVerificationNeeded | ApiUpdatePaymentStateCompleted |
|
ApiUpdatePendingJoinRequests | ApiUpdatePaymentStateCompleted |
|
||||||
ApiUpdatePhoneCall | ApiUpdatePhoneCallSignalingData | ApiUpdatePhoneCallMediaState |
|
ApiUpdatePhoneCall | ApiUpdatePhoneCallSignalingData | ApiUpdatePhoneCallMediaState |
|
||||||
ApiUpdatePhoneCallConnectionState | ApiUpdateBotMenuButton | ApiUpdateTranscribedAudio | ApiUpdateUserEmojiStatus |
|
ApiUpdatePhoneCallConnectionState | ApiUpdateBotMenuButton | ApiUpdateTranscribedAudio | ApiUpdateUserEmojiStatus |
|
||||||
ApiUpdateMessageExtendedMedia | ApiUpdateConfig | ApiUpdateTopicNotifySettings | ApiUpdatePinnedTopic |
|
ApiUpdateMessageExtendedMedia | ApiUpdateConfig | ApiUpdateTopicNotifySettings | ApiUpdatePinnedTopic |
|
||||||
|
|||||||
@ -85,7 +85,7 @@ const ConfirmPayment = ({
|
|||||||
src={url}
|
src={url}
|
||||||
title={lang('Checkout.WebConfirmation.Title')}
|
title={lang('Checkout.WebConfirmation.Title')}
|
||||||
allow="payment"
|
allow="payment"
|
||||||
sandbox="allow-modals allow-forms allow-scripts allow-top-navigation allow-same-origin"
|
sandbox="allow-modals allow-forms allow-scripts allow-same-origin"
|
||||||
className="ConfirmPayment__content"
|
className="ConfirmPayment__content"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -111,6 +111,7 @@ addActionHandler('openInvoice', async (global, actions, payload): Promise<void>
|
|||||||
form,
|
form,
|
||||||
isPaymentModalOpen: true,
|
isPaymentModalOpen: true,
|
||||||
isExtendedMedia: (payload as any).isExtendedMedia,
|
isExtendedMedia: (payload as any).isExtendedMedia,
|
||||||
|
confirmPaymentUrl: undefined,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
}, tabId);
|
}, tabId);
|
||||||
global = setPaymentStep(global, PaymentStep.Checkout, tabId);
|
global = setPaymentStep(global, PaymentStep.Checkout, tabId);
|
||||||
@ -280,11 +281,24 @@ addActionHandler('sendPaymentForm', async (global, actions, payload): Promise<vo
|
|||||||
tipAmount,
|
tipAmount,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
global = getGlobal();
|
||||||
|
if (selectTabState(global, tabId).payment.form?.formId !== formId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
global = getGlobal();
|
if ('verificationUrl' in result) {
|
||||||
|
global = updatePayment(global, {
|
||||||
|
confirmPaymentUrl: result.verificationUrl,
|
||||||
|
step: PaymentStep.ConfirmPayment,
|
||||||
|
}, tabId);
|
||||||
|
setGlobal(global);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
global = updatePayment(global, { status: 'paid' }, tabId);
|
global = updatePayment(global, { status: 'paid' }, tabId);
|
||||||
global = closeInvoice(global, tabId);
|
global = closeInvoice(global, tabId);
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import type { ActionReturnType } from '../../types';
|
import type { ActionReturnType } from '../../types';
|
||||||
import { PaymentStep } from '../../../types';
|
|
||||||
|
|
||||||
import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
|
import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
|
||||||
import { applyLangPackDifference, getTranslationFn, requestLangPackDifference } from '../../../util/localization';
|
import { applyLangPackDifference, getTranslationFn, requestLangPackDifference } from '../../../util/localization';
|
||||||
@ -13,8 +12,6 @@ import {
|
|||||||
removeBlockedUser,
|
removeBlockedUser,
|
||||||
removePeerStory,
|
removePeerStory,
|
||||||
replaceWebPage,
|
replaceWebPage,
|
||||||
setConfirmPaymentUrl,
|
|
||||||
setPaymentStep,
|
|
||||||
updateFullWebPage,
|
updateFullWebPage,
|
||||||
updateLastReadStoryForPeer,
|
updateLastReadStoryForPeer,
|
||||||
updatePeerStory,
|
updatePeerStory,
|
||||||
@ -149,14 +146,6 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
|||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'updatePaymentVerificationNeeded':
|
|
||||||
Object.values(global.byTabId).forEach(({ id: tabId }) => {
|
|
||||||
global = setConfirmPaymentUrl(global, update.url, tabId);
|
|
||||||
global = setPaymentStep(global, PaymentStep.ConfirmPayment, tabId);
|
|
||||||
});
|
|
||||||
setGlobal(global);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'updateWebViewResultSent':
|
case 'updateWebViewResultSent':
|
||||||
Object.values(global.byTabId).forEach((tabState) => {
|
Object.values(global.byTabId).forEach((tabState) => {
|
||||||
Object.entries(tabState.webApps.openedWebApps).forEach(([webAppKey, webApp]) => {
|
Object.entries(tabState.webApps.openedWebApps).forEach(([webAppKey, webApp]) => {
|
||||||
|
|||||||
@ -87,13 +87,6 @@ export function setSmartGlocalCardInfo<T extends GlobalState>(
|
|||||||
return updatePayment(global, { smartGlocalCredentials: { ...cardInfo } }, tabId);
|
return updatePayment(global, { smartGlocalCredentials: { ...cardInfo } }, tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setConfirmPaymentUrl<T extends GlobalState>(
|
|
||||||
global: T, url?: string,
|
|
||||||
...[tabId = getCurrentTabId()]: TabArgs<T>
|
|
||||||
): T {
|
|
||||||
return updatePayment(global, { confirmPaymentUrl: url }, tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setReceipt<T extends GlobalState>(
|
export function setReceipt<T extends GlobalState>(
|
||||||
global: T,
|
global: T,
|
||||||
receipt?: ApiReceiptRegular,
|
receipt?: ApiReceiptRegular,
|
||||||
@ -131,6 +124,7 @@ export function closeInvoice<T extends GlobalState>(
|
|||||||
...[tabId = getCurrentTabId()]: TabArgs<T>
|
...[tabId = getCurrentTabId()]: TabArgs<T>
|
||||||
): T {
|
): T {
|
||||||
global = updatePayment(global, {
|
global = updatePayment(global, {
|
||||||
|
confirmPaymentUrl: undefined,
|
||||||
isPaymentModalOpen: undefined,
|
isPaymentModalOpen: undefined,
|
||||||
isExtendedMedia: undefined,
|
isExtendedMedia: undefined,
|
||||||
}, tabId);
|
}, tabId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user