2020-08-25 18:44:29 +00:00
|
|
|
import QtQuick 2.3
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
2021-10-28 20:23:30 +00:00
|
|
|
import shared.popups 1.0
|
|
|
|
import shared.views.chat 1.0
|
2022-01-10 16:42:36 +00:00
|
|
|
import shared.controls 1.0
|
2021-10-28 20:23:30 +00:00
|
|
|
import shared.controls.chat 1.0
|
2020-09-03 20:43:08 +00:00
|
|
|
|
|
|
|
Item {
|
2021-10-21 00:41:54 +00:00
|
|
|
id: root
|
|
|
|
width: rectangleBubble.width
|
|
|
|
height: rectangleBubble.height
|
|
|
|
|
2021-10-21 22:39:53 +00:00
|
|
|
property var store
|
2020-09-03 20:43:08 +00:00
|
|
|
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
|
|
|
}
|
2021-10-21 22:39:53 +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"
|
|
|
|
}
|
2021-10-21 22:39:53 +00:00
|
|
|
var defaultFiatSymbol = root.store.walletModelInst.balanceView.defaultCurrency
|
|
|
|
return root.store.walletModelInst.balanceView.getFiatValue(tokenAmount, token.symbol, defaultFiatSymbol) + " " + defaultFiatSymbol.toUpperCase()
|
2020-09-03 20:43:08 +00:00
|
|
|
}
|
|
|
|
property int state: commandParametersObject.commandState
|
2021-07-12 19:30:17 +00:00
|
|
|
|
|
|
|
// Any transaction where isCurrentUser is true is actually outgoing transaction.
|
|
|
|
property bool outgoing: isCurrentUser
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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) {
|
2021-07-12 19:30:17 +00:00
|
|
|
let prefix = outgoing? "↑ " : "↓ "
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Transaction request"
|
|
|
|
return prefix + qsTrId("transaction-request")
|
2020-10-16 07:37:07 +00:00
|
|
|
}
|
2021-07-12 19:30:17 +00:00
|
|
|
|
|
|
|
return outgoing ?
|
2020-10-16 07:37:07 +00:00
|
|
|
//% "↑ 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
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Something has gone wrong"
|
|
|
|
text: qsTrId("something-has-gone-wrong")
|
2020-10-16 07:37:07 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-10-01 15:58:36 +00:00
|
|
|
AcceptTransactionView {
|
2020-09-03 20:43:08 +00:00
|
|
|
state: root.state
|
2021-10-21 22:39:53 +00:00
|
|
|
store: root.store
|
2020-09-03 20:43:08 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2022-01-10 16:42:36 +00:00
|
|
|
acc: root.store.currentAccount
|
2021-10-01 15:58:36 +00:00
|
|
|
selectedAsset: token
|
|
|
|
selectedAmount: tokenAmount
|
|
|
|
selectedFiatAmount: fiatValue
|
|
|
|
fromAddress: commandParametersObject.fromAddress
|
|
|
|
selectedRecipient: {
|
|
|
|
return {
|
|
|
|
address: commandParametersObject.address,
|
2021-10-21 22:39:53 +00:00
|
|
|
identicon: root.store.chatsModelInst.channelView.activeChannel.identicon,
|
|
|
|
name: root.store.chatsModelInst.channelView.activeChannel.name,
|
2021-10-01 15:58:36 +00:00
|
|
|
type: RecipientSelector.Type.Contact
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSendTransaction: {
|
2021-10-21 22:39:53 +00:00
|
|
|
root.store.walletModelInst.accountsView.setFocusedAccountByAddress(fromAddress);
|
2021-10-22 20:49:47 +00:00
|
|
|
//TODO remove dynamic scoping
|
|
|
|
openPopup(signTxComponent, {selectedAccount: {
|
|
|
|
name: acc.name,
|
|
|
|
address: fromAddress,
|
|
|
|
iconColor: acc.iconColor,
|
|
|
|
assets: acc.assets
|
|
|
|
}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: signTxComponent
|
|
|
|
SignTransactionModal {
|
2022-01-10 16:42:36 +00:00
|
|
|
anchors.centerIn: parent
|
2021-10-22 20:49:47 +00:00
|
|
|
store: root.store
|
2022-01-10 16:42:36 +00:00
|
|
|
selectedAsset: token
|
|
|
|
selectedAmount: tokenAmount
|
|
|
|
selectedRecipient: {
|
|
|
|
return {
|
|
|
|
address: commandParametersObject.address,
|
|
|
|
identicon: root.store.chatsModelInst.channelView.activeChannel.identicon,
|
|
|
|
name: root.store.chatsModelInst.channelView.activeChannel.name,
|
|
|
|
type: RecipientSelector.Type.Contact
|
|
|
|
}
|
2021-10-01 15:58:36 +00:00
|
|
|
}
|
2022-01-10 16:42:36 +00:00
|
|
|
selectedFiatAmount: fiatValue
|
|
|
|
onOpened: root.store.walletModelInst.gasView.getGasPrice();
|
|
|
|
onClosed: destroy();
|
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
|
|
|
}
|
|
|
|
}
|