From 83b0c8057efaad1f3e025704de47f6c8573966b0 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 14 Sep 2020 15:41:09 -0400 Subject: [PATCH] fix: code review --- src/app/chat/event_handling.nim | 2 +- src/app/chat/view.nim | 2 +- src/app/profile/core.nim | 4 ++-- src/app/profile/views/ens_manager.nim | 8 ++++---- .../Chat/components/StickerPackPurchaseModal.qml | 5 ++++- ui/app/AppLayouts/Profile/Sections/EnsContainer.qml | 10 ++++++++-- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index 6848715b35..32122a5d85 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -77,7 +77,7 @@ proc handleChatEvents(self: ChatController) = self.status.events.on(PendingTransactionType.BuyStickerPack.confirmed) do(e: Args): var tx = TransactionMinedArgs(e) - self.view.transactionCompleted(tx.success, tx.transactionHash) + self.view.transactionCompleted(tx.success, tx.transactionHash, tx.revertReason) if tx.success: self.view.installStickerPack(tx.data.parseInt) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 90c346979b..9abd295bf5 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -113,7 +113,7 @@ QtObject: result = 325000 proc transactionWasSent*(self: ChatsView, txResult: string) {.signal.} - proc transactionCompleted*(self: ChatsView, success: bool, txHash: string) {.signal.} + proc transactionCompleted*(self: ChatsView, success: bool, txHash: string, revertReason: string = "") {.signal.} proc buyStickerPack*(self: ChatsView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} = try: diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index bd4d8ac91d..d79313f696 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -85,11 +85,11 @@ proc init*(self: ProfileController, account: Account) = if tx.success: self.view.ens.confirm(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash) else: - self.view.ens.revert(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash) + self.view.ens.revert(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash, tx.revertReason) self.status.events.on(PendingTransactionType.SetPubKey.confirmed) do(e: Args): let tx = TransactionMinedArgs(e) if tx.success: self.view.ens.confirm(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash) else: - self.view.ens.revert(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash) + self.view.ens.revert(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash, tx.revertReason) diff --git a/src/app/profile/views/ens_manager.nim b/src/app/profile/views/ens_manager.nim index bc3425dcd4..85d65d302e 100644 --- a/src/app/profile/views/ens_manager.nim +++ b/src/app/profile/views/ens_manager.nim @@ -157,7 +157,7 @@ QtObject: proc usernameConfirmed(self: EnsManager, username: string) {.signal.} proc transactionWasSent(self: EnsManager, txResult: string) {.signal.} - proc transactionCompleted(self: EnsManager, success: bool, txHash: string, username: string, trxType: string) {.signal.} + proc transactionCompleted(self: EnsManager, success: bool, txHash: string, username: string, trxType: string, revertReason: string) {.signal.} proc confirm*(self: EnsManager, trxType: PendingTransactionType, ensUsername: string, transactionHash: string) = self.connect(ensUsername) @@ -167,7 +167,7 @@ QtObject: let bottomRight = self.createIndex(msgIdx, 0, nil) self.dataChanged(topLeft, bottomRight, @[EnsRoles.IsPending.int]) self.usernameConfirmed(ensUsername) - self.transactionCompleted(true, transactionHash, ensUsername, $trxType) + self.transactionCompleted(true, transactionHash, ensUsername, $trxType, "") proc getPrice(self: EnsManager): string {.slot.} = @@ -192,7 +192,7 @@ QtObject: self.connect(ensUsername) - proc revert*(self: EnsManager, trxType: PendingTransactionType, ensUsername: string, transactionHash: string) = + proc revert*(self: EnsManager, trxType: PendingTransactionType, ensUsername: string, transactionHash: string, revertReason: string) = self.pendingUsernames.excl ensUsername let msgIdx = self.usernames.find(ensUsername) @@ -201,7 +201,7 @@ QtObject: self.beginResetModel() self.usernames.del(msgIdx) self.endResetModel() - self.transactionCompleted(false, transactionHash, ensUsername, $trxType) + self.transactionCompleted(false, transactionHash, ensUsername, $trxType, revertReason) proc registerENS(self: EnsManager, username: string, password: string) {.slot.} = let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0") diff --git a/ui/app/AppLayouts/Chat/components/StickerPackPurchaseModal.qml b/ui/app/AppLayouts/Chat/components/StickerPackPurchaseModal.qml index 0b6d763997..f374f9258c 100644 --- a/ui/app/AppLayouts/Chat/components/StickerPackPurchaseModal.qml +++ b/ui/app/AppLayouts/Chat/components/StickerPackPurchaseModal.qml @@ -237,7 +237,10 @@ ModalPopup { toastMessage.open() } onTransactionCompleted: { - toastMessage.title = !success ? qsTr("Could not buy Stickerpack"): qsTr("Stickerpack bought successfully"); + toastMessage.title = !success ? + qsTr("Could not buy Stickerpack") + : + qsTr("Stickerpack bought successfully"); if (success) { toastMessage.source = "../../../img/check-circle.svg" toastMessage.iconColor = Style.current.success diff --git a/ui/app/AppLayouts/Profile/Sections/EnsContainer.qml b/ui/app/AppLayouts/Profile/Sections/EnsContainer.qml index 459bedd6c0..e7c28690a7 100644 --- a/ui/app/AppLayouts/Profile/Sections/EnsContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/EnsContainer.qml @@ -287,10 +287,16 @@ Item { onTransactionCompleted: { switch(trxType){ case "RegisterENS": - toastMessage.title = !success ? qsTr("ENS Registration failed"): qsTr("ENS Registration completed"); + toastMessage.title = !success ? + qsTr("ENS Registration failed") + : + qsTr("ENS Registration completed"); break; case "SetPubKey": - toastMessage.title = !success ? qsTr("Updating ENS pubkey failed"): qsTr("Updating ENS pubkey completed"); + toastMessage.title = !success ? + qsTr("Updating ENS pubkey failed") + : + qsTr("Updating ENS pubkey completed"); break; }