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): export function buildInputStorePaymentPurpose(
GramJs.TypeInputStorePaymentPurpose { purpose: ApiInputStorePaymentPurpose,
): GramJs.TypeInputStorePaymentPurpose {
if (purpose.type === 'stars') { if (purpose.type === 'stars') {
return new GramJs.InputStorePaymentStarsTopup({ return new GramJs.InputStorePaymentStarsTopup({
stars: BigInt(purpose.stars), stars: BigInt(purpose.stars),
currency: purpose.currency, currency: purpose.currency,
amount: BigInt(purpose.amount), 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; stars: number;
currency: string; currency: string;
amount: number; amount: number;
spendPurposePeer?: ApiPeer;
}; };
export type ApiInputStorePaymentStarsGift = { export type ApiInputStorePaymentStarsGift = {
@ -341,6 +342,7 @@ export type ApiInputInvoiceStars = {
stars: number; stars: number;
currency: string; currency: string;
amount: number; amount: number;
spendPurposePeerId?: string;
}; };
export type ApiInputInvoiceStarsGift = { export type ApiInputInvoiceStarsGift = {

View File

@ -310,11 +310,33 @@ const StarsBalanceModal = ({
}); });
const handleBuyStars = useLastCallback((option: ApiStarTopupOption) => { 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({ openInvoice({
type: 'stars', type: 'stars',
stars: option.stars, stars: option.stars,
currency: option.currency, currency: option.currency,
amount: option.amount, amount: option.amount,
spendPurposePeerId,
}); });
}); });

View File

@ -79,9 +79,11 @@ export function getRequestInputInvoice<T extends GlobalState>(
if (inputInvoice.type === 'stars') { if (inputInvoice.type === 'stars') {
const { const {
stars, amount, currency, stars, amount, currency, spendPurposePeerId,
} = inputInvoice; } = inputInvoice;
const spendPurposePeer = spendPurposePeerId ? selectPeer(global, spendPurposePeerId) : undefined;
return { return {
type: 'stars', type: 'stars',
purpose: { purpose: {
@ -89,6 +91,7 @@ export function getRequestInputInvoice<T extends GlobalState>(
stars, stars,
amount, amount,
currency, currency,
spendPurposePeer,
}, },
}; };
} }