Skip to content

Commit

Permalink
Fix stars bot payments
Browse files Browse the repository at this point in the history
  • Loading branch information
morethanwords committed Sep 28, 2024
1 parent dabb67a commit 8d96d3f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
28 changes: 21 additions & 7 deletions src/components/popups/stars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import PopupElement from '.';
import maybe2x from '../../helpers/maybe2x';
import {InputInvoice, MessageMedia, PaymentsPaymentForm, Photo, Document, StarsTopupOption, StarsTransaction, StarsTransactionPeer, MessageExtendedMedia, ChatInvite, StarsSubscription, StarsGiftOption, InputStorePaymentPurpose} from '../../layer';
import {InputInvoice, MessageMedia, PaymentsPaymentForm, Photo, Document, StarsTopupOption, StarsTransaction, StarsTransactionPeer, MessageExtendedMedia, ChatInvite, StarsSubscription, StarsGiftOption, InputStorePaymentPurpose, WebDocument} from '../../layer';
import I18n, {i18n, LangPackKey} from '../../lib/langPack';
import Section from '../section';
import {createMemo, createRoot, createSignal, For, JSX, untrack} from 'solid-js';
Expand Down Expand Up @@ -197,15 +197,17 @@ export async function getStarsTransactionTitleAndMedia({
paidMedia,
paidMediaPeerId,
chatInvite,
subscription
subscription,
photo
}: {
transaction: StarsTransaction,
middleware: Middleware,
size: number,
paidMedia?: MessageMedia.messageMediaPaidMedia,
paidMediaPeerId?: PeerId,
chatInvite?: ChatInvite.chatInvite,
subscription?: StarsSubscription
subscription?: StarsSubscription,
photo?: WebDocument.webDocument
}) {
const [title, media] = await Promise.all([
(() => {
Expand All @@ -221,8 +223,10 @@ export async function getStarsTransactionTitleAndMedia({
return wrapPeerTitle({peerId: paidMediaPeerId || getPeerId((transaction.peer as StarsTransactionPeer.starsTransactionPeer).peer)});
}

if(transaction.peer._ === 'starsTransactionPeer') {
return wrapPeerTitle({peerId: getPeerId(transaction.peer.peer)});
if(!transaction || transaction.peer._ === 'starsTransactionPeer') {
return wrapPeerTitle({
peerId: transaction ? getPeerId((transaction.peer as StarsTransactionPeer.starsTransactionPeer).peer) : paidMediaPeerId
});
}

return getStarsTransactionTitle(transaction);
Expand All @@ -237,12 +241,20 @@ export async function getStarsTransactionTitleAndMedia({
boxHeight: size,
middleware,
loadPromises,
withoutPreloader: true
withoutPreloader: true,
size: photo._ === 'webDocument' ? {_: 'photoSizeEmpty', type: ''} : undefined
});

await Promise.all(loadPromises);
};

if(photo) {
const container = document.createElement('div');
container.classList.add('popup-stars-pay-item');
await _wrapPhoto(container, photo);
return container;
}

if(chatInvite) {
const avatar = await wrapChatInviteAvatar(chatInvite, middleware, 90);
return avatar.node;
Expand Down Expand Up @@ -298,8 +310,10 @@ export async function getStarsTransactionTitleAndMedia({
let peerId: PeerId;
if(subscription) {
peerId = getPeerId(subscription.peer);
} else if(transaction.peer._ === 'starsTransactionPeer') {
} else if(transaction && transaction.peer._ === 'starsTransactionPeer') {
peerId = getPeerId(transaction.peer.peer);
} else if(paidMediaPeerId) {
peerId = paidMediaPeerId;
}

if(peerId) {
Expand Down
33 changes: 6 additions & 27 deletions src/components/popups/starsPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {renderImageFromUrlPromise} from '../../helpers/dom/renderImageFromUrl';
import toggleDisability from '../../helpers/dom/toggleDisability';
import maybe2x from '../../helpers/maybe2x';
import safeAssign from '../../helpers/object/safeAssign';
import {InputInvoice, MessageMedia, PaymentsPaymentForm, PaymentsPaymentReceipt, StarsTransaction, Message, MessageExtendedMedia, Photo, Document, ChatInvite, StarsSubscription, Chat, MessageAction, Boost} from '../../layer';
import {InputInvoice, MessageMedia, PaymentsPaymentForm, PaymentsPaymentReceipt, StarsTransaction, Message, MessageExtendedMedia, Photo, Document, ChatInvite, StarsSubscription, Chat, MessageAction, Boost, WebDocument} from '../../layer';
import appImManager from '../../lib/appManagers/appImManager';
import getPeerId from '../../lib/appManagers/utils/peers/getPeerId';
import {i18n} from '../../lib/langPack';
Expand Down Expand Up @@ -158,7 +158,6 @@ export default class PopupStarsPay extends PopupElement<{
image: HTMLElement,
_title: HTMLElement,
avatar: HTMLElement,
itemImage?: HTMLElement,
link?: string
) {
if(!this.isReceipt && (!this.subscription || tsNow(true) > this.subscription.until_date)) {
Expand Down Expand Up @@ -315,7 +314,7 @@ export default class PopupStarsPay extends PopupElement<{

const tablePeer = (this.isReceipt || this.subscription) && makeTablePeer(this.peerId);

const transactionIdSpan = (<span onClick={onTransactionClick}>{wrapRichText(transactionId, {entities: [{_: 'messageEntityCode', length: transactionId.length, offset: 0}]})}</span>);
const transactionIdSpan = transactionId && (<span onClick={onTransactionClick}>{wrapRichText(transactionId, {entities: [{_: 'messageEntityCode', length: transactionId.length, offset: 0}]})}</span>);

let tableContent: Parameters<typeof Table>[0]['content'];
if(this.subscription) {
Expand Down Expand Up @@ -355,7 +354,6 @@ export default class PopupStarsPay extends PopupElement<{
<div class="popup-stars-pay-padding">
{image}
<div class="popup-stars-pay-images">
{itemImage}
<div
class="popup-stars-pay-avatar"
onClick={async() => {
Expand Down Expand Up @@ -433,7 +431,7 @@ export default class PopupStarsPay extends PopupElement<{
this.peerId = getPeerId(this.transaction.peer.peer);
}

const [image, {title, media}, itemImage, link] = await Promise.all([
const [image, {title, media}, link] = await Promise.all([
(async() => {
const img = document.createElement('img');
img.classList.add('popup-stars-image');
Expand All @@ -448,7 +446,8 @@ export default class PopupStarsPay extends PopupElement<{
paidMedia: this.paidMedia,
paidMediaPeerId: this.message ? this.message.fwdFromId || this.message.fromId : this.peerId,
chatInvite: this.chatInvite,
subscription: this.subscription
subscription: this.subscription,
photo: this.form?.photo as WebDocument.webDocument
});

if(this.boost) {
Expand Down Expand Up @@ -477,26 +476,6 @@ export default class PopupStarsPay extends PopupElement<{

return result;
})(),
(async() => {
return undefined as HTMLElement;
// if(!this.form.photo || true) {
// return;
// }

// const div = document.createElement('div');
// div.classList.add('popup-stars-pay-item');
// const loadPromises: Promise<any>[] = [];
// wrapPhoto({
// photo: this.form.photo,
// container: div,
// boxWidth: 90,
// boxHeight: 90,
// size: {_: 'photoSizeEmpty', type: ''},
// loadPromises
// });
// await Promise.all(loadPromises);
// return div;
})(),
(async() => {
if(
(!this.transaction || (!this.transaction.extended_media && !this.transaction.pFlags.reaction && !this.transaction.giveaway_post_id)) ||
Expand All @@ -515,7 +494,7 @@ export default class PopupStarsPay extends PopupElement<{
})()
]);
this.body.classList.toggle('is-receipt', this.isReceipt);
this.appendSolid(() => this._construct(image, title, media, itemImage, link));
this.appendSolid(() => this._construct(image, title, media, link));
this.show();
}
}
7 changes: 7 additions & 0 deletions src/components/wrappers/messageActionTextNewUnsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@ export default async function wrapMessageActionTextNewUnsafe(options: WrapMessag
break;
}

case 'messageActionPaymentRefunded': {
const price = paymentsWrapCurrencyAmount(action.total_amount, action.currency, undefined, undefined, plain);
args = [getNameDivHTML(message.fromId, plain), price];
langPackKey = 'Chat.Service.Refund';
break;
}

case 'messageActionSetMessagesTTL': {
args = [];

Expand Down
2 changes: 1 addition & 1 deletion src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const App = {
version: import.meta.env.VITE_VERSION,
versionFull: import.meta.env.VITE_VERSION_FULL,
build: +import.meta.env.VITE_BUILD,
langPackVersion: '6.1.2',
langPackVersion: '6.1.4',
langPack: 'webk',
langPackCode: 'en',
domains: MAIN_DOMAINS,
Expand Down
3 changes: 2 additions & 1 deletion src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,8 @@ const lang = {
'Chat.UploadLimit.Text': {
'one_value': 'Subscribe to [Telegram Premium]() to increase upload speeds %d time.',
'other_value': 'Subscribe to [Telegram Premium]() to increase upload speeds %d times.'
}
},
'Chat.Service.Refund': '%@ refunded %@'
};

export default lang;

0 comments on commit 8d96d3f

Please sign in to comment.