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 { @@ -136,17 +136,6 @@ export default class PopupPayment extends PopupElement {
}
this.hide();
showSuccessToast();
};
const showSuccessToast = () => {
toastNew({
langPackKey: 'PaymentInfoHint',
langPackArguments: [
paymentsWrapCurrencyAmount(getTotalTotal(), currency),
wrapEmojiText(mediaInvoice.title)
]
});
};
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'; @@ -24,8 +24,7 @@ import { MOUNT_CLASS_TO } from '../../config/debug';
import appNavigationController from '../../components/appNavigationController';
import AppPrivateSearchTab from '../../components/sidebarRight/tabs/search';
import I18n, { i18n, join, LangPackKey } from '../langPack';
import { ChatFull, ChatInvite, ChatParticipant, ChatParticipants, SendMessageAction } from '../../layer';
import { hslaStringToHex } from '../../helpers/color';
import { ChatFull, ChatInvite, ChatParticipants, Message, MessageAction, MessageMedia, SendMessageAction } from '../../layer';
import PeerTitle from '../../components/peerTitle';
import PopupPeer from '../../components/popups/peer';
import blurActiveElement from '../../helpers/dom/blurActiveElement';
@ -87,8 +86,8 @@ import groupCallsController from '../calls/groupCallsController'; @@ -87,8 +86,8 @@ import groupCallsController from '../calls/groupCallsController';
import callsController from '../calls/callsController';
import getFilesFromEvent from '../../helpers/files/getFilesFromEvent';
import apiManagerProxy from '../mtproto/mtprotoworker';
import wrapPeerTitle from '../../components/wrappers/peerTitle';
import appRuntimeManager from './appRuntimeManager';
import paymentsWrapCurrencyAmount from '../../helpers/paymentsWrapCurrencyAmount';
export const CHAT_ANIMATION_GROUP = 'chat';
@ -343,6 +342,22 @@ export class AppImManager extends EventListenerBase<{ @@ -343,6 +342,22 @@ export class AppImManager extends EventListenerBase<{
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) => {
if(this.chat.peerId === options.message.peerId && !idleController.isIdle) {

3
src/lib/appManagers/appMessagesManager.ts

@ -4030,7 +4030,8 @@ export class AppMessagesManager extends AppManager { @@ -4030,7 +4030,8 @@ export class AppMessagesManager extends AppManager {
if(message._ === 'messageService' && message.action._ === 'messageActionPaymentSent') {
this.rootScope.dispatchEvent('payment_sent', {
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 = { @@ -138,7 +138,7 @@ export type BroadcastEvents = {
'logging_out': void,
'payment_sent': {peerId: PeerId, mid: number}
'payment_sent': {peerId: PeerId, mid: number, receiptMessage: Message.messageService}
};
export type BroadcastEventsListeners = {

Loading…
Cancel
Save