feat: show toast message for transaction status changes

This commit is contained in:
Jonathan Rainville 2020-09-14 10:58:21 -04:00 committed by Iuri Matias
parent b0c9155e70
commit 103f02b289
7 changed files with 76 additions and 14 deletions

View File

@ -62,10 +62,7 @@ proc init*(self: WalletController) =
self.status.events.on(PendingTransactionType.WalletTransfer.confirmed) do(e: Args): self.status.events.on(PendingTransactionType.WalletTransfer.confirmed) do(e: Args):
let tx = TransactionMinedArgs(e) let tx = TransactionMinedArgs(e)
if tx.success: self.view.transactionCompleted(tx.success, tx.transactionHash, tx.revertReason)
debug "SUCCESSS TRANSACTION", transactionHash = tx.transactionHash
else:
debug "ERROR TRANSACTION", revertReason = tx.revertReason
proc checkPendingTransactions*(self: WalletController) = proc checkPendingTransactions*(self: WalletController) =
self.status.wallet.checkPendingTransactions() # TODO: consider doing this in a spawnAndSend self.status.wallet.checkPendingTransactions() # TODO: consider doing this in a spawnAndSend

View File

@ -562,3 +562,5 @@ QtObject:
proc ensResolved(self: WalletView, pubKey: string) {.slot.} = proc ensResolved(self: WalletView, pubKey: string) {.slot.} =
self.ensWasResolved(pubKey) self.ensWasResolved(pubKey)
proc transactionCompleted*(self: WalletView, success: bool, txHash: string, revertReason: string = "") {.signal.}

View File

@ -248,6 +248,7 @@ ModalPopup {
} }
} }
} }
Connections { Connections {
target: walletModel target: walletModel
onTransactionWasSent: { onTransactionWasSent: {
@ -265,6 +266,9 @@ ModalPopup {
} }
toastMessage.title = qsTr("Transaction pending...") toastMessage.title = qsTr("Transaction pending...")
toastMessage.source = "../../img/loading.svg"
toastMessage.iconColor = Style.current.primary
toastMessage.iconRotates = true
toastMessage.link = `${walletModel.etherscanLink}/${response.result}` toastMessage.link = `${walletModel.etherscanLink}/${response.result}`
toastMessage.open() toastMessage.open()
root.close() root.close()
@ -272,6 +276,19 @@ ModalPopup {
console.error('Error parsing the response', e) console.error('Error parsing the response', e)
} }
} }
onTransactionCompleted: {
if (success) {
toastMessage.title = qsTr("Transaction completed")
toastMessage.source = "../../img/check-circle.svg"
toastMessage.iconColor = Style.current.success
} else {
toastMessage.title = qsTr("Transaction failed")
toastMessage.source = "../../img/block-icon.svg"
toastMessage.iconColor = Style.current.danger
}
toastMessage.link = `${walletModel.etherscanLink}/${txHash}`
toastMessage.open()
}
} }
} }
} }

View File

@ -38,7 +38,9 @@ Theme {
property color backgroundHover: "#252528" property color backgroundHover: "#252528"
property color secondaryText: darkGrey property color secondaryText: darkGrey
property color secondaryHover: tenPercentWhite property color secondaryHover: tenPercentWhite
property color primary: blue
property color danger: red property color danger: red
property color success: green
property color primaryMenuItemHover: blue property color primaryMenuItemHover: blue
property color primaryMenuItemTextHover: almostBlack property color primaryMenuItemTextHover: almostBlack
property color backgroundTertiary: tenPercentBlue property color backgroundTertiary: tenPercentBlue

View File

@ -37,7 +37,9 @@ Theme {
property color backgroundHover: grey property color backgroundHover: grey
property color secondaryText: darkGrey property color secondaryText: darkGrey
property color secondaryHover: tenPercentBlack property color secondaryHover: tenPercentBlack
property color primary: blue
property color danger: red property color danger: red
property color success: green
property color primaryMenuItemHover: blue property color primaryMenuItemHover: blue
property color primaryMenuItemTextHover: white property color primaryMenuItemTextHover: white
property color backgroundTertiary: tenPercentBlue property color backgroundTertiary: tenPercentBlue

View File

@ -7,30 +7,61 @@ Rectangle {
property alias source: roundedIconImage.source property alias source: roundedIconImage.source
default property alias content: content.children default property alias content: content.children
property alias icon: roundedIconImage property alias icon: roundedIconImage
property bool rotates: false
signal clicked signal clicked
width: 36 width: 36
height: 36 height: 36
property alias iconWidth: roundedIconImage.width property alias iconWidth: roundedIconImage.width
property alias iconHeight: roundedIconImage.height property alias iconHeight: roundedIconImage.height
property alias rotation: roundedIconImage.rotation property alias rotation: roundedIconImage.rotation
property color iconColor: Style.current.transparent
color: Style.current.blue color: Style.current.blue
radius: width / 2 radius: width / 2
Item {
id: iconContainer
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: roundedIconImage.width
height: roundedIconImage.height
SVGImage { SVGImage {
id: roundedIconImage id: roundedIconImage
width: 12 width: 12
height: 12 height: 12
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: "../img/new_chat.svg" source: "../img/new_chat.svg"
} }
ColorOverlay {
anchors.fill: roundedIconImage
source: roundedIconImage
color: root.iconColor
}
}
Loader {
active: rotates
sourceComponent: rotatorComponent
}
Component {
id: rotatorComponent
RotationAnimator {
target: iconContainer
from: 0;
to: 360;
duration: 1200
running: true
loops: Animation.Infinite
}
}
Item { Item {
id: content id: content
anchors.left: roundedIconImage.right anchors.left: iconContainer.right
anchors.leftMargin: 6 + (root.width - roundedIconImage.width) anchors.leftMargin: 6 + (root.width - iconContainer.width)
} }
MouseArea { MouseArea {

View File

@ -6,8 +6,11 @@ import "."
Popup { Popup {
property url source: "../app/img/check-circle.svg" property url source: "../app/img/check-circle.svg"
property color iconColor: Style.current.primary
property bool iconRotates: false
property string title: "Transaction pending..." property string title: "Transaction pending..."
property string linkText: qsTr("View on Etherscan") readonly property string defaultLinkText: qsTr("View on Etherscan")
property string linkText: defaultLinkText
property string link: "https://etherscan.io/" property string link: "https://etherscan.io/"
id: root id: root
@ -24,6 +27,12 @@ Popup {
root.close() root.close()
}, 4000); }, 4000);
} }
onClosed: {
// Reset props
iconColor = Style.current.primary
iconRotates = false
linkText = defaultLinkText
}
Timer { Timer {
id: timer id: timer
@ -56,11 +65,13 @@ Popup {
height: 32 height: 32
iconHeight: 20 iconHeight: 20
iconWidth: 20 iconWidth: 20
color: Style.current.secondaryBackground color: Utils.setColorAlpha(root.iconColor, 0.1)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
source: root.source source: root.source
anchors.leftMargin: 12 anchors.leftMargin: 12
iconColor: root.iconColor
rotates: root.iconRotates
} }
StyledText { StyledText {