From ea288f912a1fee35902936baaf2f3e2818083003 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Mon, 22 Dec 2025 22:54:27 +0100 Subject: [PATCH] Stars: Pass payment purpose to server (#6545) --- src/api/gramjs/gramjsBuilders/index.ts | 8 +++++-- src/api/types/payments.ts | 2 ++ .../modals/stars/StarsBalanceModal.tsx | 22 +++++++++++++++++++ src/global/helpers/payments.ts | 5 ++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/api/gramjs/gramjsBuilders/index.ts b/src/api/gramjs/gramjsBuilders/index.ts index 0f453b571..94edb0ffe 100644 --- a/src/api/gramjs/gramjsBuilders/index.ts +++ b/src/api/gramjs/gramjsBuilders/index.ts @@ -615,13 +615,17 @@ export function buildInputPhoneCall({ id, accessHash }: ApiPhoneCall) { }); } -export function buildInputStorePaymentPurpose(purpose: ApiInputStorePaymentPurpose): -GramJs.TypeInputStorePaymentPurpose { +export function buildInputStorePaymentPurpose( + purpose: ApiInputStorePaymentPurpose, +): GramJs.TypeInputStorePaymentPurpose { if (purpose.type === 'stars') { return new GramJs.InputStorePaymentStarsTopup({ stars: BigInt(purpose.stars), currency: purpose.currency, amount: BigInt(purpose.amount), + spendPurposePeer: purpose.spendPurposePeer + ? buildInputPeer(purpose.spendPurposePeer.id, purpose.spendPurposePeer.accessHash) + : undefined, }); } diff --git a/src/api/types/payments.ts b/src/api/types/payments.ts index 327aa3644..f3460a76f 100644 --- a/src/api/types/payments.ts +++ b/src/api/types/payments.ts @@ -163,6 +163,7 @@ export type ApiInputStorePaymentStarsTopup = { stars: number; currency: string; amount: number; + spendPurposePeer?: ApiPeer; }; export type ApiInputStorePaymentStarsGift = { @@ -341,6 +342,7 @@ export type ApiInputInvoiceStars = { stars: number; currency: string; amount: number; + spendPurposePeerId?: string; }; export type ApiInputInvoiceStarsGift = { diff --git a/src/components/modals/stars/StarsBalanceModal.tsx b/src/components/modals/stars/StarsBalanceModal.tsx index 99f31bc61..cb9ffaf91 100644 --- a/src/components/modals/stars/StarsBalanceModal.tsx +++ b/src/components/modals/stars/StarsBalanceModal.tsx @@ -310,11 +310,33 @@ const StarsBalanceModal = ({ }); const handleBuyStars = useLastCallback((option: ApiStarTopupOption) => { + const originPaymentInputInvoice = originStarsPayment?.inputInvoice; + + let spendPurposePeerId: string | undefined; + + switch (originPaymentInputInvoice?.type) { + case 'message': { + spendPurposePeerId = originPaymentInputInvoice.chatId; + break; + } + + case 'slug': { + const form = originStarsPayment?.form; + spendPurposePeerId = form?.botId; + break; + } + } + + if (originReaction) { + spendPurposePeerId = originReaction.chatId; + } + openInvoice({ type: 'stars', stars: option.stars, currency: option.currency, amount: option.amount, + spendPurposePeerId, }); }); diff --git a/src/global/helpers/payments.ts b/src/global/helpers/payments.ts index ba8c5d3b7..13b2f2289 100644 --- a/src/global/helpers/payments.ts +++ b/src/global/helpers/payments.ts @@ -79,9 +79,11 @@ export function getRequestInputInvoice( if (inputInvoice.type === 'stars') { const { - stars, amount, currency, + stars, amount, currency, spendPurposePeerId, } = inputInvoice; + const spendPurposePeer = spendPurposePeerId ? selectPeer(global, spendPurposePeerId) : undefined; + return { type: 'stars', purpose: { @@ -89,6 +91,7 @@ export function getRequestInputInvoice( stars, amount, currency, + spendPurposePeer, }, }; }