2020-08-25 18:44:29 +00:00
|
|
|
import QtQuick 2.3
|
|
|
|
import "../../../../../shared"
|
|
|
|
import "../../../../../imports"
|
|
|
|
import "./TransactionComponents"
|
2020-09-03 20:43:08 +00:00
|
|
|
import "../../../Wallet/data"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
property var commandParametersObject: {
|
|
|
|
try {
|
2020-09-03 20:14:44 +00:00
|
|
|
return JSON.parse(commandParameters)
|
2020-09-03 20:43:08 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing command parameters')
|
|
|
|
console.error('JSON:', commandParameters)
|
|
|
|
console.error('Error:', e)
|
|
|
|
return {
|
|
|
|
id: "",
|
2020-09-03 20:14:44 +00:00
|
|
|
fromAddress: "",
|
2020-09-03 20:43:08 +00:00
|
|
|
address: "",
|
|
|
|
contract: "",
|
|
|
|
value: "",
|
|
|
|
transactionHash: "",
|
|
|
|
commandState: 1,
|
|
|
|
signature: null
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
}
|
2020-10-16 07:37:07 +00:00
|
|
|
property var token: JSON.parse(commandParametersObject.contract) // TODO: handle {}
|
|
|
|
property string tokenAmount: commandParametersObject.value
|
|
|
|
property string tokenSymbol: token.symbol || ""
|
2020-09-03 20:43:08 +00:00
|
|
|
property string fiatValue: {
|
|
|
|
if (!tokenAmount || !token.symbol) {
|
|
|
|
return "0"
|
|
|
|
}
|
|
|
|
var defaultFiatSymbol = walletModel.defaultCurrency
|
|
|
|
return walletModel.getFiatValue(tokenAmount, token.symbol, defaultFiatSymbol) + " " + defaultFiatSymbol.toUpperCase()
|
|
|
|
}
|
|
|
|
property int state: commandParametersObject.commandState
|
|
|
|
property bool outgoing: {
|
|
|
|
switch (root.state) {
|
|
|
|
case Constants.pending:
|
|
|
|
case Constants.confirmed:
|
2020-10-16 07:37:07 +00:00
|
|
|
case Constants.transactionRequested:
|
2020-10-16 13:21:57 +00:00
|
|
|
case Constants.addressRequested: return isCurrentUser
|
2020-09-03 20:43:08 +00:00
|
|
|
case Constants.declined:
|
|
|
|
case Constants.transactionDeclined:
|
|
|
|
case Constants.addressReceived: return !isCurrentUser
|
|
|
|
default: return false
|
2020-08-25 18:44:29 +00:00
|
|
|
}
|
2020-09-03 20:43:08 +00:00
|
|
|
}
|
|
|
|
property int innerMargin: 12
|
2020-10-16 07:37:07 +00:00
|
|
|
property bool isError: commandParametersObject.contract === "{}"
|
|
|
|
onTokenSymbolChanged: {
|
|
|
|
if (!!tokenSymbol) {
|
|
|
|
tokenImage.source = `../../../../img/tokens/${root.tokenSymbol}.png`
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 20:43:08 +00:00
|
|
|
|
|
|
|
id: root
|
|
|
|
anchors.left: parent.left
|
2020-10-20 10:11:45 +00:00
|
|
|
anchors.leftMargin: isCurrentUser ? 0 :
|
|
|
|
appSettings.compactMode ? Style.current.padding : 48;
|
2020-09-03 20:43:08 +00:00
|
|
|
width: rectangleBubble.width
|
|
|
|
height: rectangleBubble.height
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: rectangleBubble
|
|
|
|
width: (bubbleLoader.active ? bubbleLoader.width : valueContainer.width)
|
|
|
|
+ timeText.width + 3 * root.innerMargin
|
|
|
|
height: childrenRect.height + root.innerMargin
|
|
|
|
radius: 16
|
|
|
|
color: Style.current.background
|
|
|
|
border.color: Style.current.border
|
|
|
|
border.width: 1
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-10-20 10:11:45 +00:00
|
|
|
anchors.right: isCurrentUser ? parent.right : undefined
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.left: !isCurrentUser ? parent.left : undefined
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
|
2020-08-25 18:44:29 +00:00
|
|
|
StyledText {
|
2020-09-03 20:43:08 +00:00
|
|
|
id: title
|
2020-08-25 18:44:29 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-10-16 07:37:07 +00:00
|
|
|
text: {
|
|
|
|
if (root.state === Constants.transactionRequested) {
|
2020-10-16 13:21:57 +00:00
|
|
|
let prefix = root.outgoing ? "↓ ": "↑ "
|
2020-10-16 07:37:07 +00:00
|
|
|
return prefix + qsTr("Transaction request")
|
|
|
|
}
|
|
|
|
return root.outgoing ?
|
|
|
|
//% "↑ Outgoing transaction"
|
|
|
|
qsTrId("--outgoing-transaction") :
|
|
|
|
//% "↓ Incoming transaction"
|
|
|
|
qsTrId("--incoming-transaction")
|
|
|
|
}
|
2020-09-03 20:43:08 +00:00
|
|
|
font.weight: Font.Medium
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: root.innerMargin
|
2020-08-25 18:44:29 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
Item {
|
|
|
|
id: valueContainer
|
|
|
|
width: childrenRect.width
|
|
|
|
height: tokenText.height + fiatText.height
|
|
|
|
anchors.top: title.bottom
|
|
|
|
anchors.topMargin: 4
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: root.innerMargin
|
|
|
|
|
2020-10-16 07:37:07 +00:00
|
|
|
StyledText {
|
|
|
|
id: txtError
|
|
|
|
color: Style.current.danger
|
|
|
|
visible: root.isError
|
|
|
|
text: qsTr("Something has gone wrong")
|
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
Image {
|
|
|
|
id: tokenImage
|
2020-10-16 07:37:07 +00:00
|
|
|
visible: !root.isError
|
2020-09-03 20:43:08 +00:00
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: tokenText
|
2020-10-16 07:37:07 +00:00
|
|
|
visible: !root.isError
|
2020-09-03 20:43:08 +00:00
|
|
|
color: Style.current.textColor
|
|
|
|
text: `${root.tokenAmount} ${root.tokenSymbol}`
|
|
|
|
anchors.left: tokenImage.right
|
|
|
|
anchors.leftMargin: Style.current.halfPadding
|
|
|
|
font.pixelSize: 22
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: fiatText
|
2020-10-16 07:37:07 +00:00
|
|
|
visible: !root.isError
|
2020-09-03 20:43:08 +00:00
|
|
|
color: Style.current.secondaryText
|
|
|
|
text: root.fiatValue
|
|
|
|
anchors.top: tokenText.bottom
|
|
|
|
anchors.left: tokenText.left
|
|
|
|
font.pixelSize: 13
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: bubbleLoader
|
2020-10-16 07:37:07 +00:00
|
|
|
active: {
|
|
|
|
return !root.isError && (
|
|
|
|
isCurrentUser ||
|
|
|
|
(!isCurrentUser &&
|
|
|
|
!(root.state === Constants.addressRequested ||
|
|
|
|
root.state === Constants.transactionRequested)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2020-09-03 20:43:08 +00:00
|
|
|
sourceComponent: stateBubbleComponent
|
|
|
|
anchors.top: valueContainer.bottom
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: root.innerMargin
|
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
Component {
|
|
|
|
id: stateBubbleComponent
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
StateBubble {
|
|
|
|
state: root.state
|
|
|
|
outgoing: root.outgoing
|
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
Loader {
|
|
|
|
id: buttonsLoader
|
2020-10-16 07:37:07 +00:00
|
|
|
active: !root.isError && (
|
|
|
|
(root.state === Constants.addressRequested && !root.outgoing) ||
|
2020-09-03 20:43:08 +00:00
|
|
|
(root.state === Constants.addressReceived && root.outgoing) ||
|
2020-10-16 13:21:57 +00:00
|
|
|
(root.state === Constants.transactionRequested && !root.outgoing)
|
2020-10-16 07:37:07 +00:00
|
|
|
)
|
2020-09-03 20:43:08 +00:00
|
|
|
sourceComponent: root.outgoing ? signAndSendComponent : acceptTransactionComponent
|
|
|
|
anchors.top: bubbleLoader.active ? bubbleLoader.bottom : valueContainer.bottom
|
|
|
|
anchors.topMargin: bubbleLoader.active ? root.innerMargin : 20
|
|
|
|
width: parent.width
|
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
Component {
|
|
|
|
id: acceptTransactionComponent
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
AcceptTransaction {
|
|
|
|
state: root.state
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
Component {
|
|
|
|
id: signAndSendComponent
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-10-16 07:37:07 +00:00
|
|
|
SendTransactionButton {
|
2020-10-19 00:57:38 +00:00
|
|
|
// outgoing: root.outgoing
|
2020-10-16 07:37:07 +00:00
|
|
|
}
|
2020-09-03 20:43:08 +00:00
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
|
2020-09-03 20:43:08 +00:00
|
|
|
StyledText {
|
|
|
|
id: timeText
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
text: Utils.formatTime(timestamp)
|
|
|
|
anchors.left: bubbleLoader.active ? bubbleLoader.right : undefined
|
|
|
|
anchors.leftMargin: bubbleLoader.active ? 13 : 0
|
|
|
|
anchors.right: bubbleLoader.active ? undefined : parent.right
|
|
|
|
anchors.rightMargin: bubbleLoader.active ? 0 : root.innerMargin
|
|
|
|
anchors.bottom: bubbleLoader.active ? bubbleLoader.bottom : buttonsLoader.top
|
|
|
|
anchors.bottomMargin: bubbleLoader.active ? -root.innerMargin : 7
|
|
|
|
font.pixelSize: 10
|
|
|
|
}
|
2020-08-25 18:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;formeditorColor:"#4c4e50";formeditorZoom:1.25}
|
|
|
|
}
|
|
|
|
##^##*/
|