From 70fdcb85c62a88dbbc277e652043e19a18513442 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 29 Jun 2020 12:37:36 -0400 Subject: [PATCH] feat: add asset selector in send modal --- src/app/wallet/views/account_list.nim | 1 - src/app/wallet/views/asset_list.nim | 10 ++++++ ui/app/AppLayouts/Wallet/SendModal.qml | 14 +++++++- .../Wallet/components/SendModalContent.qml | 33 ++++++++++++++++--- ui/app/img/token-icons/eth.svg | 9 ----- ui/app/img/token-icons/snt.svg | 4 --- ui/shared/Select.qml | 4 +-- 7 files changed, 54 insertions(+), 21 deletions(-) delete mode 100644 ui/app/img/token-icons/eth.svg delete mode 100644 ui/app/img/token-icons/snt.svg diff --git a/src/app/wallet/views/account_list.nim b/src/app/wallet/views/account_list.nim index 64a1d111cd..bc5d691064 100644 --- a/src/app/wallet/views/account_list.nim +++ b/src/app/wallet/views/account_list.nim @@ -41,7 +41,6 @@ QtObject: of "path": result = account.path of "walletType": result = account.walletType - proc getAccountindexByAddress*(self: AccountList, address: string): int = var i = 0 for account in self.accounts: diff --git a/src/app/wallet/views/asset_list.nim b/src/app/wallet/views/asset_list.nim index 5266d19b57..2c90ae6696 100644 --- a/src/app/wallet/views/asset_list.nim +++ b/src/app/wallet/views/asset_list.nim @@ -23,6 +23,16 @@ QtObject: result.assets = @[] result.setup + proc rowData(self: AssetList, index: int, column: string): string {.slot.} = + if (index >= self.assets.len): + return + let asset = self.assets[index] + case column: + of "name": result = asset.name + of "symbol": result = asset.symbol + of "value": result = asset.value + of "fiatValue": result = asset.fiatValue + method rowCount(self: AssetList, index: QModelIndex = nil): int = return self.assets.len diff --git a/ui/app/AppLayouts/Wallet/SendModal.qml b/ui/app/AppLayouts/Wallet/SendModal.qml index 7e0fbc9422..ddd64c90f9 100644 --- a/ui/app/AppLayouts/Wallet/SendModal.qml +++ b/ui/app/AppLayouts/Wallet/SendModal.qml @@ -10,6 +10,7 @@ ModalPopup { id: popup title: qsTr("Send") + height: 600 onOpened: { sendModalContent.amountInput.text = "" @@ -26,11 +27,22 @@ ModalPopup { }) } sendModalContent.accounts = accountsData + + const assets = walletModel.assets + const numAssets = assets.rowCount() + const assetsData = [] + for (let f = 0; f < numAssets; f++) { + assetsData.push({ + name: assets.rowData(f, 'name'), + symbol: assets.rowData(f, 'symbol'), + value: assets.rowData(f, 'value') + }) + } + sendModalContent.assets = assetsData } SendModalContent { id: sendModalContent - accounts: [] } footer: StyledButton { diff --git a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml index bff1b48646..5875ef1bef 100644 --- a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml +++ b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml @@ -8,13 +8,19 @@ Item { property alias amountText: txtAmount.text property alias toText: txtTo.text property alias passwordText: txtPassword.text - property var accounts + property var accounts: [] + property var assets: [] property string defaultAccount: "0x1234" + property int selectedAccountIndex: 0 property string selectedAccountAddress: accounts && accounts.length ? accounts[selectedAccountIndex].address : "" property string selectedAccountName: accounts && accounts.length ? accounts[selectedAccountIndex].name : "" property string selectedAccountIconColor: accounts && accounts.length ? accounts[selectedAccountIndex].iconColor : "" + property int selectedAssetIndex: 0 + property string selectedAssetName: assets && assets.length ? assets[selectedAssetIndex].name : "" + property string selectedAssetSymbol: assets && assets.length ? assets[selectedAssetIndex].symbol : "" + property string selectedAccountValue: assets && assets.length ? assets[selectedAssetIndex].value : "" property string passwordValidationError: "" property string toValidationError: "" @@ -55,12 +61,31 @@ Item { Input { id: txtAmount label: qsTr("Amount") - icon: "../../../img/token-icons/eth.svg" anchors.top: parent.top - placeholderText: qsTr("Enter ETH") + placeholderText: qsTr("Enter amount...") validationError: amountValidationError } + + Select { + id: assetTypeSelect + iconHeight: 24 + iconWidth: 24 + icon: "../../../img/tokens/" + selectedAssetSymbol.toUpperCase() + ".png" + label: qsTr("Select the asset") + anchors.top: txtAmount.bottom + anchors.topMargin: Theme.padding + selectedText: selectedAssetName + selectOptions: sendModalContent.assets.map(function (asset, index) { + return { + text: asset.name, + onClicked: function () { + selectedAssetIndex = index + } + } + }) + } + Select { id: txtFrom iconHeight: 12 @@ -68,7 +93,7 @@ Item { icon: "../../../img/walletIcon.svg" iconColor: selectedAccountIconColor label: qsTr("From account") - anchors.top: txtAmount.bottom + anchors.top: assetTypeSelect.bottom anchors.topMargin: Theme.padding selectedText: selectedAccountName selectOptions: sendModalContent.accounts.map(function (account, index) { diff --git a/ui/app/img/token-icons/eth.svg b/ui/app/img/token-icons/eth.svg deleted file mode 100644 index dcbba16b1c..0000000000 --- a/ui/app/img/token-icons/eth.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/ui/app/img/token-icons/snt.svg b/ui/app/img/token-icons/snt.svg deleted file mode 100644 index 6a7b5d8f38..0000000000 --- a/ui/app/img/token-icons/snt.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/ui/shared/Select.qml b/ui/shared/Select.qml index b1efecc30d..f695247e08 100644 --- a/ui/shared/Select.qml +++ b/ui/shared/Select.qml @@ -15,7 +15,7 @@ Item { property url icon: "" property int iconHeight: 24 property int iconWidth: 24 - property color iconColor + property color iconColor: Theme.transparent readonly property bool hasIcon: icon.toString() !== "" @@ -63,7 +63,7 @@ Item { ColorOverlay { anchors.fill: iconImg source: iconImg - color: iconColor ? iconColor : Theme.transparent + color: iconColor } StyledText {