feat: toast messages for sticker and ens trxs
This commit is contained in:
parent
17aa8d274e
commit
0091fded3a
|
@ -77,11 +77,9 @@ proc handleChatEvents(self: ChatController) =
|
||||||
|
|
||||||
self.status.events.on(PendingTransactionType.BuyStickerPack.confirmed) do(e: Args):
|
self.status.events.on(PendingTransactionType.BuyStickerPack.confirmed) do(e: Args):
|
||||||
var tx = TransactionMinedArgs(e)
|
var tx = TransactionMinedArgs(e)
|
||||||
|
self.view.transactionCompleted(tx.success, tx.transactionHash)
|
||||||
if tx.success:
|
if tx.success:
|
||||||
self.view.installStickerPack(tx.data.parseInt)
|
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) =
|
proc handleMailserverEvents(self: ChatController) =
|
||||||
self.status.events.on("mailserverTopics") do(e: Args):
|
self.status.events.on("mailserverTopics") do(e: Args):
|
||||||
|
|
|
@ -112,10 +112,15 @@ QtObject:
|
||||||
except:
|
except:
|
||||||
result = 325000
|
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.} =
|
proc buyStickerPack*(self: ChatsView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} =
|
||||||
try:
|
try:
|
||||||
let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password)
|
let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password)
|
||||||
result = $(%* { "result": %response })
|
result = $(%* { "result": %response })
|
||||||
|
self.transactionWasSent(response)
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# check if response["error"] is not null and handle the error
|
# check if response["error"] is not null and handle the error
|
||||||
except RpcException as e:
|
except RpcException as e:
|
||||||
|
|
|
@ -83,15 +83,13 @@ proc init*(self: ProfileController, account: Account) =
|
||||||
self.status.events.on(PendingTransactionType.RegisterENS.confirmed) do(e: Args):
|
self.status.events.on(PendingTransactionType.RegisterENS.confirmed) do(e: Args):
|
||||||
let tx = TransactionMinedArgs(e)
|
let tx = TransactionMinedArgs(e)
|
||||||
if tx.success:
|
if tx.success:
|
||||||
self.view.ens.confirm(TransactionMinedArgs(e).data)
|
self.view.ens.confirm(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash)
|
||||||
else:
|
else:
|
||||||
discard
|
self.view.ens.revert(PendingTransactionType.RegisterENS, tx.data, tx.transactionHash)
|
||||||
# TODO: show toast message indicating transaction reverted
|
|
||||||
|
|
||||||
self.status.events.on(PendingTransactionType.SetPubKey.confirmed) do(e: Args):
|
self.status.events.on(PendingTransactionType.SetPubKey.confirmed) do(e: Args):
|
||||||
let tx = TransactionMinedArgs(e)
|
let tx = TransactionMinedArgs(e)
|
||||||
if tx.success:
|
if tx.success:
|
||||||
self.view.ens.confirm(TransactionMinedArgs(e).data)
|
self.view.ens.confirm(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash)
|
||||||
else:
|
else:
|
||||||
discard
|
self.view.ens.revert(PendingTransactionType.SetPubKey, tx.data, tx.transactionHash)
|
||||||
# TODO: show toast message indicating transaction reverted
|
|
||||||
|
|
|
@ -156,8 +156,10 @@ QtObject:
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc usernameConfirmed(self: EnsManager, username: string) {.signal.}
|
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.connect(ensUsername)
|
||||||
self.pendingUsernames.excl ensUsername
|
self.pendingUsernames.excl ensUsername
|
||||||
let msgIdx = self.usernames.find(ensUsername)
|
let msgIdx = self.usernames.find(ensUsername)
|
||||||
|
@ -165,6 +167,8 @@ QtObject:
|
||||||
let bottomRight = self.createIndex(msgIdx, 0, nil)
|
let bottomRight = self.createIndex(msgIdx, 0, nil)
|
||||||
self.dataChanged(topLeft, bottomRight, @[EnsRoles.IsPending.int])
|
self.dataChanged(topLeft, bottomRight, @[EnsRoles.IsPending.int])
|
||||||
self.usernameConfirmed(ensUsername)
|
self.usernameConfirmed(ensUsername)
|
||||||
|
self.transactionCompleted(true, transactionHash, ensUsername, $trxType)
|
||||||
|
|
||||||
|
|
||||||
proc getPrice(self: EnsManager): string {.slot.} =
|
proc getPrice(self: EnsManager): string {.slot.} =
|
||||||
result = libstatus_utils.wei2Eth(getPrice())
|
result = libstatus_utils.wei2Eth(getPrice())
|
||||||
|
@ -188,12 +192,25 @@ QtObject:
|
||||||
|
|
||||||
self.connect(ensUsername)
|
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.} =
|
proc registerENS(self: EnsManager, username: string, password: string) {.slot.} =
|
||||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||||
let address = status_wallet.getWalletAccounts()[0].address
|
let address = status_wallet.getWalletAccounts()[0].address
|
||||||
let walletAddress = parseAddress(address)
|
let walletAddress = parseAddress(address)
|
||||||
let trxHash = registerUsername(username, walletAddress, pubKey, password)
|
let trxHash = registerUsername(username, walletAddress, pubKey, password)
|
||||||
|
|
||||||
|
self.transactionWasSent(trxHash)
|
||||||
|
|
||||||
# TODO: handle transaction failure
|
# TODO: handle transaction failure
|
||||||
var ensUsername = formatUsername(username, true)
|
var ensUsername = formatUsername(username, true)
|
||||||
self.pendingUsernames.incl(ensUsername)
|
self.pendingUsernames.incl(ensUsername)
|
||||||
|
@ -205,6 +222,8 @@ QtObject:
|
||||||
let walletAddress = parseAddress(address)
|
let walletAddress = parseAddress(address)
|
||||||
let trxHash = setPubKey(username, walletAddress, pubKey, password)
|
let trxHash = setPubKey(username, walletAddress, pubKey, password)
|
||||||
|
|
||||||
|
self.transactionWasSent(trxHash)
|
||||||
|
|
||||||
# TODO: handle transaction failure
|
# TODO: handle transaction failure
|
||||||
self.pendingUsernames.incl(username)
|
self.pendingUsernames.incl(username)
|
||||||
self.add username
|
self.add username
|
||||||
|
|
|
@ -59,7 +59,7 @@ ModalPopup {
|
||||||
return sendingError.open()
|
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()
|
sendingSuccess.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ ModalPopup {
|
||||||
return sendingError.open()
|
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()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,4 +273,37 @@ Item {
|
||||||
addedUsername = ensUsername;
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue