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
|
|
|
|
import shared.controls.chat 1.0
|
2022-02-09 00:04:49 +00:00
|
|
|
import shared.controls 1.0
|
2022-04-01 10:30:55 +00:00
|
|
|
import shared.stores 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
|
2022-01-04 12:06:05 +00:00
|
|
|
property var contactsStore
|
|
|
|
|
2022-02-09 00:04:49 +00:00
|
|
|
property var transactionParams
|
|
|
|
|
|
|
|
property var transactionParamsObject: {
|
2020-09-03 20:43:08 +00:00
|
|
|
try {
|
2022-02-09 00:04:49 +00:00
|
|
|
return JSON.parse(transactionParams)
|
2020-09-03 20:43:08 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing command parameters')
|
2022-02-09 00:04:49 +00:00
|
|
|
console.error('JSON:', transactionParams)
|
2020-09-03 20:43:08 +00:00
|
|
|
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
|
|
|
|
2022-02-09 00:04:49 +00:00
|
|
|
property var token:{
|
|
|
|
try {
|
|
|
|
return JSON.parse(transactionParamsObject.contract)
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing command parameters')
|
|
|
|
console.error('JSON:', transactionParamsObject.contract)
|
|
|
|
console.error('Error:', e)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property var selectedRecipient: {
|
|
|
|
return {
|
|
|
|
address: transactionParamsObject.address,
|
|
|
|
name: senderDisplayName,
|
|
|
|
type: RecipientSelector.Type.Contact,
|
|
|
|
alias: senderDisplayName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property string tokenAmount: transactionParamsObject.value
|
2020-10-16 07:37:07 +00:00
|
|
|
property string tokenSymbol: token.symbol || ""
|
2020-09-03 20:43:08 +00:00
|
|
|
property string fiatValue: {
|
|
|
|
if (!tokenAmount || !token.symbol) {
|
|
|
|
return "0"
|
|
|
|
}
|
2022-02-09 00:04:49 +00:00
|
|
|
var defaultFiatSymbol = root.store.currentCurrency
|
|
|
|
return root.store.getFiatValue(tokenAmount, token.symbol, defaultFiatSymbol) + " " + defaultFiatSymbol.toUpperCase()
|
2020-09-03 20:43:08 +00:00
|
|
|
}
|
2022-02-09 00:04:49 +00:00
|
|
|
property int state: transactionParamsObject.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
|
2022-02-09 00:04:49 +00:00
|
|
|
property bool isError: transactionParamsObject.contract === "{}"
|
2020-10-16 07:37:07 +00:00
|
|
|
onTokenSymbolChanged: {
|
|
|
|
if (!!tokenSymbol) {
|
2022-02-09 00:04:49 +00:00
|
|
|
tokenImage.source = Style.png("tokens/"+root.tokenSymbol)
|
2020-10-16 07:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
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? "↑ " : "↓ "
|
2022-04-04 11:26:30 +00:00
|
|
|
return prefix + qsTr("Transaction request")
|
2020-10-16 07:37:07 +00:00
|
|
|
}
|
2021-07-12 19:30:17 +00:00
|
|
|
|
|
|
|
return outgoing ?
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("↑ Outgoing transaction") :
|
|
|
|
qsTr("↓ Incoming transaction")
|
2020-10-16 07:37:07 +00:00
|
|
|
}
|
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
|
2022-04-05 13:43:01 +00:00
|
|
|
text: qsTr("Token not found on your current network")
|
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 && (
|
2022-02-09 09:43:23 +00:00
|
|
|
isCurrentUser ||
|
|
|
|
(!isCurrentUser &&
|
|
|
|
!(root.state === Constants.addressRequested ||
|
2020-10-16 07:37:07 +00:00
|
|
|
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
|
2022-01-04 12:06:05 +00:00
|
|
|
contactsStore: root.contactsStore
|
2021-12-08 21:20:43 +00:00
|
|
|
token: root.token
|
|
|
|
fiatValue: root.fiatValue
|
|
|
|
tokenAmount: root.tokenAmount
|
2022-02-09 00:04:49 +00:00
|
|
|
selectedRecipient: root.selectedRecipient
|
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 {
|
2021-10-01 15:58:36 +00:00
|
|
|
selectedAsset: token
|
|
|
|
selectedAmount: tokenAmount
|
|
|
|
selectedFiatAmount: fiatValue
|
2022-02-09 00:04:49 +00:00
|
|
|
fromAddress: transactionParamsObject.fromAddress
|
|
|
|
selectedRecipient: root.selectedRecipient
|
2021-10-01 15:58:36 +00:00
|
|
|
onSendTransaction: {
|
2022-02-09 00:04:49 +00:00
|
|
|
Global.openPopup(signTxComponent, {selectedAccount: {
|
|
|
|
name: root.store.getAccountNameByAddress(fromAddress),
|
|
|
|
address: fromAddress,
|
|
|
|
color: root.store.getAccountIconColorByAddress(fromAddress),
|
|
|
|
assets: root.store.getAccountAssetsByAddress(fromAddress)
|
|
|
|
}})
|
2021-10-22 20:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: signTxComponent
|
|
|
|
SignTransactionModal {
|
2022-02-09 00:04:49 +00:00
|
|
|
anchors.centerIn: parent
|
2021-10-22 20:49:47 +00:00
|
|
|
store: root.store
|
2022-01-04 12:06:05 +00:00
|
|
|
contactsStore: root.contactsStore
|
2022-02-09 00:04:49 +00:00
|
|
|
selectedAsset: root.token
|
|
|
|
selectedAmount: root.tokenAmount
|
2021-12-13 14:24:21 +00:00
|
|
|
selectedRecipient: root.selectedRecipient
|
2022-02-09 00:04:49 +00:00
|
|
|
selectedFiatAmount: root.fiatValue
|
|
|
|
selectedType: RecipientSelector.Type.Contact
|
2022-05-19 08:53:57 +00:00
|
|
|
chainId: root.store.getChainIdForChat()
|
2022-02-09 00:04:49 +00:00
|
|
|
onClosed: destroy()
|
|
|
|
msgId: messageId
|
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
|
2022-07-05 10:12:27 +00:00
|
|
|
text: Utils.formatShortTime(messageTimestamp, RootStore.accountSensitiveSettings.is24hTimeFormat)
|
2020-09-03 20:43:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|