From 2ed807e2092dc57da7727b0f0c09d53574621e4b Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 1 Mar 2025 17:59:56 +0100 Subject: [PATCH] Process Payment: Fix gift code payment processing (#5682) --- src/assets/localization/fallback.strings | 1 + src/global/actions/apiUpdaters/payments.ts | 19 ++++++++++++++++--- src/types/language.d.ts | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/assets/localization/fallback.strings b/src/assets/localization/fallback.strings index d75af56b4..ea525f05f 100644 --- a/src/assets/localization/fallback.strings +++ b/src/assets/localization/fallback.strings @@ -1813,3 +1813,4 @@ "PeerPersonalAccount" = "personal account"; "PeerChannel" = "channel"; "WebAppCollapse" = "Collapse"; +"GiftSent"= "Gift sent!"; diff --git a/src/global/actions/apiUpdaters/payments.ts b/src/global/actions/apiUpdaters/payments.ts index 20392e0bf..6b7ff2257 100644 --- a/src/global/actions/apiUpdaters/payments.ts +++ b/src/global/actions/apiUpdaters/payments.ts @@ -15,16 +15,29 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => { const { invoice } = form; const { totalAmount, currency } = invoice; - - if (paymentState.inputInvoice?.type === 'stars') { + const inputInvoice = paymentState.inputInvoice; + if (inputInvoice?.type === 'stars') { actions.closeStarsBalanceModal({ tabId }); actions.showNotification({ - message: langProvider.oldTranslate('StarsAcquiredInfo', paymentState.inputInvoice.stars), + message: langProvider.oldTranslate('StarsAcquiredInfo', inputInvoice.stars), title: langProvider.oldTranslate('StarsAcquired'), icon: 'star', tabId, }); actions.requestConfetti({ withStars: true, tabId }); + } else if (inputInvoice?.type === 'giftcode') { + const giftModalState = selectTabState(global, tabId).giftModal; + + if (giftModalState && inputInvoice?.userIds[0] === giftModalState.forPeerId) { + actions.showNotification({ + message: { + key: 'GiftSent', + }, + tabId, + }); + actions.requestConfetti({ withStars: true, tabId }); + actions.closeGiftModal({ tabId }); + } } else { actions.showNotification({ tabId, diff --git a/src/types/language.d.ts b/src/types/language.d.ts index 610179d64..ab14df7da 100644 --- a/src/types/language.d.ts +++ b/src/types/language.d.ts @@ -1403,6 +1403,7 @@ export interface LangPair { 'PeerPersonalAccount': undefined; 'PeerChannel': undefined; 'WebAppCollapse': undefined; + 'GiftSent': undefined; } export interface LangPairWithVariables {