Skip to content

Commit ea288f9

Browse files
zubidenAjaxy
authored andcommitted
Stars: Pass payment purpose to server (#6545)
1 parent eab1559 commit ea288f9

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/api/gramjs/gramjsBuilders/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,17 @@ export function buildInputPhoneCall({ id, accessHash }: ApiPhoneCall) {
615615
});
616616
}
617617

618-
export function buildInputStorePaymentPurpose(purpose: ApiInputStorePaymentPurpose):
619-
GramJs.TypeInputStorePaymentPurpose {
618+
export function buildInputStorePaymentPurpose(
619+
purpose: ApiInputStorePaymentPurpose,
620+
): GramJs.TypeInputStorePaymentPurpose {
620621
if (purpose.type === 'stars') {
621622
return new GramJs.InputStorePaymentStarsTopup({
622623
stars: BigInt(purpose.stars),
623624
currency: purpose.currency,
624625
amount: BigInt(purpose.amount),
626+
spendPurposePeer: purpose.spendPurposePeer
627+
? buildInputPeer(purpose.spendPurposePeer.id, purpose.spendPurposePeer.accessHash)
628+
: undefined,
625629
});
626630
}
627631

src/api/types/payments.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export type ApiInputStorePaymentStarsTopup = {
163163
stars: number;
164164
currency: string;
165165
amount: number;
166+
spendPurposePeer?: ApiPeer;
166167
};
167168

168169
export type ApiInputStorePaymentStarsGift = {
@@ -341,6 +342,7 @@ export type ApiInputInvoiceStars = {
341342
stars: number;
342343
currency: string;
343344
amount: number;
345+
spendPurposePeerId?: string;
344346
};
345347

346348
export type ApiInputInvoiceStarsGift = {

src/components/modals/stars/StarsBalanceModal.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,33 @@ const StarsBalanceModal = ({
310310
});
311311

312312
const handleBuyStars = useLastCallback((option: ApiStarTopupOption) => {
313+
const originPaymentInputInvoice = originStarsPayment?.inputInvoice;
314+
315+
let spendPurposePeerId: string | undefined;
316+
317+
switch (originPaymentInputInvoice?.type) {
318+
case 'message': {
319+
spendPurposePeerId = originPaymentInputInvoice.chatId;
320+
break;
321+
}
322+
323+
case 'slug': {
324+
const form = originStarsPayment?.form;
325+
spendPurposePeerId = form?.botId;
326+
break;
327+
}
328+
}
329+
330+
if (originReaction) {
331+
spendPurposePeerId = originReaction.chatId;
332+
}
333+
313334
openInvoice({
314335
type: 'stars',
315336
stars: option.stars,
316337
currency: option.currency,
317338
amount: option.amount,
339+
spendPurposePeerId,
318340
});
319341
});
320342

src/global/helpers/payments.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,19 @@ export function getRequestInputInvoice<T extends GlobalState>(
7979

8080
if (inputInvoice.type === 'stars') {
8181
const {
82-
stars, amount, currency,
82+
stars, amount, currency, spendPurposePeerId,
8383
} = inputInvoice;
8484

85+
const spendPurposePeer = spendPurposePeerId ? selectPeer(global, spendPurposePeerId) : undefined;
86+
8587
return {
8688
type: 'stars',
8789
purpose: {
8890
type: 'stars',
8991
stars,
9092
amount,
9193
currency,
94+
spendPurposePeer,
9295
},
9396
};
9497
}

0 commit comments

Comments
 (0)