Stars: Pass payment purpose to server (#6545)

This commit is contained in:
zubiden 2025-12-22 22:54:27 +01:00 committed by Alexander Zinchuk
parent eab1559134
commit ea288f912a
4 changed files with 34 additions and 3 deletions

View File

@ -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,
});
}

View File

@ -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 = {

View File

@ -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,
});
});

View File

@ -79,9 +79,11 @@ export function getRequestInputInvoice<T extends GlobalState>(
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<T extends GlobalState>(
stars,
amount,
currency,
spendPurposePeer,
},
};
}