feat: toast messages for sticker and ens trxs

This commit is contained in:
Richard Ramos 2020-09-14 13:38:23 -04:00 committed by Iuri Matias
parent 17aa8d274e
commit 0091fded3a
7 changed files with 90 additions and 12 deletions

View File

@ -77,11 +77,9 @@ 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)
if tx.success:
self.view.installStickerPack(tx.data.parseInt)
else:
discard
# TODO: self.view.toastMessage(message = tx.revertReason, error = true) # for when the toast messages in the design are implemented
proc handleMailserverEvents(self: ChatController) =
self.status.events.on("mailserverTopics") do(e: Args):

View File

@ -112,10 +112,15 @@ QtObject:
except:
result = 325000
proc transactionWasSent*(self: ChatsView, txResult: string) {.signal.}
proc transactionCompleted*(self: ChatsView, success: bool, txHash: string) {.signal.}
proc buyStickerPack*(self: ChatsView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} =
try:
let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password)
result = $(%* { "result": %response })
self.transactionWasSent(response)
# TODO:
# check if response["error"] is not null and handle the error
except RpcException as e:

View File

@ -83,15 +83,13 @@ proc init*(self: ProfileController, account: Account) =
self.status.events.on(PendingTransactionType.RegisterENS.confirmed) do(e: Args):
let tx = TransactionMinedArgs(e)
if tx.success:
self.view.ens.confirm(TransactionMinedArgs(e).data)
self.view.ens.confirm(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash)
else:
discard
# TODO: show toast message indicating transaction reverted
self.view.ens.revert(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash)
self.status.events.on(PendingTransactionType.SetPubKey.confirmed) do(e: Args):
let tx = TransactionMinedArgs(e)
if tx.success:
self.view.ens.confirm(TransactionMinedArgs(e).data)
self.view.ens.confirm(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash)
else:
discard
# TODO: show toast message indicating transaction reverted
self.view.ens.revert(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash)

View File

@ -156,8 +156,10 @@ QtObject:
}.toTable
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 confirm*(self: EnsManager, ensUsername: string) =
proc confirm*(self: EnsManager, trxType: PendingTransactionType, ensUsername: string, transactionHash: string) =
self.connect(ensUsername)
self.pendingUsernames.excl ensUsername
let msgIdx = self.usernames.find(ensUsername)
@ -165,6 +167,8 @@ QtObject:
let bottomRight = self.createIndex(msgIdx, 0, nil)
self.dataChanged(topLeft, bottomRight, @[EnsRoles.IsPending.int])
self.usernameConfirmed(ensUsername)
self.transactionCompleted(true, transactionHash, ensUsername, $trxType)
proc getPrice(self: EnsManager): string {.slot.} =
result = libstatus_utils.wei2Eth(getPrice())
@ -188,12 +192,25 @@ QtObject:
self.connect(ensUsername)
proc revert*(self: EnsManager, trxType: PendingTransactionType, ensUsername: string, transactionHash: string) =
self.pendingUsernames.excl ensUsername
let msgIdx = self.usernames.find(ensUsername)
if msgIdx == -1: return
self.beginResetModel()
self.usernames.del(msgIdx)
self.endResetModel()
self.transactionCompleted(false, transactionHash, ensUsername, $trxType)
proc registerENS(self: EnsManager, username: string, password: string) {.slot.} =
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
let address = status_wallet.getWalletAccounts()[0].address
let walletAddress = parseAddress(address)
let trxHash = registerUsername(username, walletAddress, pubKey, password)
self.transactionWasSent(trxHash)
# TODO: handle transaction failure
var ensUsername = formatUsername(username, true)
self.pendingUsernames.incl(ensUsername)
@ -205,6 +222,8 @@ QtObject:
let walletAddress = parseAddress(address)
let trxHash = setPubKey(username, walletAddress, pubKey, password)
self.transactionWasSent(trxHash)
# TODO: handle transaction failure
self.pendingUsernames.incl(username)
self.add username

View File

@ -59,7 +59,7 @@ ModalPopup {
return sendingError.open()
}
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: %2/%1").arg(response.result).arg(walletModel.etherscanLink)
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: %2%1").arg(response.result).arg(walletModel.etherscanLink)
sendingSuccess.open()
}

View File

@ -52,7 +52,7 @@ ModalPopup {
return sendingError.open()
}
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: %2/%1").arg(response.result).arg(walletModel.etherscanLink)
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: %2%1").arg(response.result).arg(walletModel.etherscanLink)
sendingSuccess.open()
}
@ -225,6 +225,31 @@ ModalPopup {
}
}
}
Connections {
target: chatsModel
onTransactionWasSent: {
toastMessage.title = qsTr("Transaction pending...")
toastMessage.source = "../../../img/loading.svg"
toastMessage.iconColor = Style.current.primary
toastMessage.iconRotates = true
toastMessage.link = `${walletModel.etherscanLink}/${txResult}`
toastMessage.open()
}
onTransactionCompleted: {
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
} else {
toastMessage.source = "../../../img/block-icon.svg"
toastMessage.iconColor = Style.current.danger
}
toastMessage.link = `${walletModel.etherscanLink}/${txHash}`
toastMessage.open()
}
}
}
}

View File

@ -273,4 +273,37 @@ Item {
addedUsername = ensUsername;
}
}
Connections {
target: profileModel.ens
onTransactionWasSent: {
toastMessage.title = qsTr("Transaction pending...")
toastMessage.source = "../../../img/loading.svg"
toastMessage.iconColor = Style.current.primary
toastMessage.iconRotates = true
toastMessage.link = `${walletModel.etherscanLink}/${txResult}`
toastMessage.open()
}
onTransactionCompleted: {
switch(trxType){
case "RegisterENS":
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");
break;
}
if (success) {
toastMessage.source = "../../../img/check-circle.svg"
toastMessage.iconColor = Style.current.success
} else {
toastMessage.source = "../../../img/block-icon.svg"
toastMessage.iconColor = Style.current.danger
}
toastMessage.link = `${walletModel.etherscanLink}/${txHash}`
toastMessage.open()
}
}
}