Browse Source

Fix displaying payment toast on failure

master
Eduard Kuzmenko 2 years ago
parent
commit
90f630a0cd
  1. 11
      src/components/popups/payment.ts
  2. 21
      src/lib/appManagers/appImManager.ts
  3. 3
      src/lib/appManagers/appMessagesManager.ts
  4. 2
      src/lib/rootScope.ts

11
src/components/popups/payment.ts

@ -136,17 +136,6 @@ export default class PopupPayment extends PopupElement {
} }
this.hide(); this.hide();
showSuccessToast();
};
const showSuccessToast = () => {
toastNew({
langPackKey: 'PaymentInfoHint',
langPackArguments: [
paymentsWrapCurrencyAmount(getTotalTotal(), currency),
wrapEmojiText(mediaInvoice.title)
]
});
}; };
this.listenerSetter.add(rootScope)('payment_sent', ({peerId, mid}) => { this.listenerSetter.add(rootScope)('payment_sent', ({peerId, mid}) => {

21
src/lib/appManagers/appImManager.ts

@ -24,8 +24,7 @@ import { MOUNT_CLASS_TO } from '../../config/debug';
import appNavigationController from '../../components/appNavigationController'; import appNavigationController from '../../components/appNavigationController';
import AppPrivateSearchTab from '../../components/sidebarRight/tabs/search'; import AppPrivateSearchTab from '../../components/sidebarRight/tabs/search';
import I18n, { i18n, join, LangPackKey } from '../langPack'; import I18n, { i18n, join, LangPackKey } from '../langPack';
import { ChatFull, ChatInvite, ChatParticipant, ChatParticipants, SendMessageAction } from '../../layer'; import { ChatFull, ChatInvite, ChatParticipants, Message, MessageAction, MessageMedia, SendMessageAction } from '../../layer';
import { hslaStringToHex } from '../../helpers/color';
import PeerTitle from '../../components/peerTitle'; import PeerTitle from '../../components/peerTitle';
import PopupPeer from '../../components/popups/peer'; import PopupPeer from '../../components/popups/peer';
import blurActiveElement from '../../helpers/dom/blurActiveElement'; import blurActiveElement from '../../helpers/dom/blurActiveElement';
@ -87,8 +86,8 @@ import groupCallsController from '../calls/groupCallsController';
import callsController from '../calls/callsController'; import callsController from '../calls/callsController';
import getFilesFromEvent from '../../helpers/files/getFilesFromEvent'; import getFilesFromEvent from '../../helpers/files/getFilesFromEvent';
import apiManagerProxy from '../mtproto/mtprotoworker'; import apiManagerProxy from '../mtproto/mtprotoworker';
import wrapPeerTitle from '../../components/wrappers/peerTitle';
import appRuntimeManager from './appRuntimeManager'; import appRuntimeManager from './appRuntimeManager';
import paymentsWrapCurrencyAmount from '../../helpers/paymentsWrapCurrencyAmount';
export const CHAT_ANIMATION_GROUP = 'chat'; export const CHAT_ANIMATION_GROUP = 'chat';
@ -343,6 +342,22 @@ export class AppImManager extends EventListenerBase<{
description: wrapRichText(update.message) description: wrapRichText(update.message)
}); });
}); });
rootScope.addEventListener('payment_sent', async({peerId, mid, receiptMessage}) => {
const message = await this.managers.appMessagesManager.getMessageByPeer(peerId, mid);
if(!message) {
return;
}
const action = receiptMessage.action as MessageAction.messageActionPaymentSent;
toastNew({
langPackKey: 'PaymentInfoHint',
langPackArguments: [
paymentsWrapCurrencyAmount(action.total_amount, action.currency),
wrapEmojiText(((message as Message.message).media as MessageMedia.messageMediaInvoice).title)
]
});
});
apiManagerProxy.addEventListener('notificationBuild', (options) => { apiManagerProxy.addEventListener('notificationBuild', (options) => {
if(this.chat.peerId === options.message.peerId && !idleController.isIdle) { if(this.chat.peerId === options.message.peerId && !idleController.isIdle) {

3
src/lib/appManagers/appMessagesManager.ts

@ -4030,7 +4030,8 @@ export class AppMessagesManager extends AppManager {
if(message._ === 'messageService' && message.action._ === 'messageActionPaymentSent') { if(message._ === 'messageService' && message.action._ === 'messageActionPaymentSent') {
this.rootScope.dispatchEvent('payment_sent', { this.rootScope.dispatchEvent('payment_sent', {
peerId: message.reply_to.reply_to_peer_id ? getPeerId(message.reply_to.reply_to_peer_id) : message.peerId, peerId: message.reply_to.reply_to_peer_id ? getPeerId(message.reply_to.reply_to_peer_id) : message.peerId,
mid: message.reply_to_mid mid: message.reply_to_mid,
receiptMessage: message
}); });
} }

2
src/lib/rootScope.ts

@ -138,7 +138,7 @@ export type BroadcastEvents = {
'logging_out': void, 'logging_out': void,
'payment_sent': {peerId: PeerId, mid: number} 'payment_sent': {peerId: PeerId, mid: number, receiptMessage: Message.messageService}
}; };
export type BroadcastEventsListeners = { export type BroadcastEventsListeners = {

Loading…
Cancel
Save