support adding a custom token
support adding a custom token cleanup
This commit is contained in:
parent
eaad59f690
commit
36b2ae5a66
|
@ -160,3 +160,6 @@ QtObject:
|
|||
self.accountListChanged()
|
||||
self.accounts.forceUpdate()
|
||||
self.setCurrentAssetList(self.currentAccount.account.assetList)
|
||||
|
||||
proc addCustomToken*(self: WalletView, address: string, name: string, symbol: string, decimals: string) {.slot.} =
|
||||
self.status.wallet.toggleAsset(symbol, true, address, name, parseInt(decimals), "")
|
||||
|
|
|
@ -57,7 +57,7 @@ proc generateAccountConfiguredAssets*(self: WalletModel, accountAddress: string)
|
|||
assets.add(asset)
|
||||
for token in self.tokens:
|
||||
var symbol = token["symbol"].getStr
|
||||
var existingToken = Asset(name: token["name"].getStr, symbol: symbol, value: fmt"0.0", fiatValue: "$0.0", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg", hasIcon: true, accountAddress: accountAddress)
|
||||
var existingToken = Asset(name: token["name"].getStr, symbol: symbol, value: fmt"0.0", fiatValue: "$0.0", image: fmt"../../img/token-icons/{toLowerAscii(symbol)}.svg", hasIcon: true, accountAddress: accountAddress, address: token["address"].getStr)
|
||||
assets.add(existingToken)
|
||||
assets
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ type CurrencyArgs* = ref object of Args
|
|||
currency*: string
|
||||
|
||||
type Asset* = ref object
|
||||
name*, symbol*, value*, fiatValue*, image*, accountAddress*: string
|
||||
name*, symbol*, value*, fiatValue*, image*, accountAddress*, address*: string
|
||||
hasIcon*: bool
|
||||
|
||||
type WalletAccount* = ref object
|
||||
|
|
|
@ -2,7 +2,6 @@ import tables, strformat, strutils, stint, httpclient, json
|
|||
import ../libstatus/wallet as status_wallet
|
||||
import ../libstatus/tokens as status_tokens
|
||||
import account
|
||||
import token_list
|
||||
|
||||
type BalanceManager* = ref object
|
||||
pricePairs: Table[string, string]
|
||||
|
@ -29,20 +28,20 @@ proc getPrice(crypto: string, fiat: string): string =
|
|||
except Exception as e:
|
||||
echo "error getting price"
|
||||
echo e.msg
|
||||
result = "0.0"
|
||||
|
||||
proc getEthBalance(address: string): string =
|
||||
var balance = status_wallet.getBalance(address)
|
||||
result = status_wallet.hex2Eth(balance)
|
||||
# balanceManager.tokenBalances["ETH"] = result
|
||||
|
||||
proc getBalance*(symbol: string, accountAddress: string): string =
|
||||
proc getBalance*(symbol: string, accountAddress: string, tokenAddress: string): string =
|
||||
if balanceManager.tokenBalances.hasKey(symbol):
|
||||
return balanceManager.tokenBalances[symbol]
|
||||
|
||||
if symbol == "ETH":
|
||||
return getEthBalance(accountAddress)
|
||||
var token: AssetConfig = getTokenConfig(symbol)
|
||||
result = $status_tokens.getTokenBalance(token.address, accountAddress)
|
||||
result = $status_tokens.getTokenBalance(tokenAddress, accountAddress)
|
||||
# balanceManager.tokenBalances[symbol] = result
|
||||
|
||||
proc getFiatValue*(crypto_balance: string, crypto_symbol: string, fiat_symbol: string): float =
|
||||
|
@ -51,13 +50,13 @@ proc getFiatValue*(crypto_balance: string, crypto_symbol: string, fiat_symbol: s
|
|||
parseFloat(crypto_balance) * parseFloat(fiat_crypto_price)
|
||||
|
||||
proc updateBalance*(asset: Asset, currency: string) =
|
||||
var token_balance = getBalance(asset.symbol, asset.accountAddress)
|
||||
var token_balance = getBalance(asset.symbol, asset.accountAddress, asset.address)
|
||||
let fiat_balance = getFiatValue(token_balance, asset.symbol, currency)
|
||||
asset.value = token_balance
|
||||
asset.fiatValue = fmt"{fiat_balance:.2f} {currency}"
|
||||
|
||||
proc updateBalance*(account: WalletAccount, currency: string) =
|
||||
let eth_balance = getBalance("ETH", account.address)
|
||||
let eth_balance = getBalance("ETH", account.address, "")
|
||||
let usd_balance = getFiatValue(eth_balance, "ETH", currency)
|
||||
var totalAccountBalance = usd_balance
|
||||
account.realFiatBalance = totalAccountBalance
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,79 @@
|
|||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.3
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtQuick.Dialogs 1.3
|
||||
import "../../../imports"
|
||||
import "../../../shared"
|
||||
|
||||
ModalPopup {
|
||||
id: popup
|
||||
title: qsTr("add custom token")
|
||||
height: 630
|
||||
|
||||
property int marginBetweenInputs: 35
|
||||
|
||||
onOpened: {
|
||||
accountNameInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||
}
|
||||
|
||||
Input {
|
||||
id: addressInput
|
||||
placeholderText: qsTr("Enter contract address...")
|
||||
label: qsTr("Contract address")
|
||||
}
|
||||
|
||||
Input {
|
||||
id: nameInput
|
||||
anchors.top: addressInput.bottom
|
||||
anchors.topMargin: marginBetweenInputs
|
||||
placeholderText: qsTr("The name of your token...")
|
||||
label: qsTr("Name")
|
||||
}
|
||||
|
||||
Input {
|
||||
id: symbolInput
|
||||
anchors.top: nameInput.bottom
|
||||
anchors.topMargin: marginBetweenInputs
|
||||
placeholderText: qsTr("ABC")
|
||||
label: qsTr("Symbol")
|
||||
}
|
||||
|
||||
Input {
|
||||
id: decimalsInput
|
||||
anchors.top: symbolInput.bottom
|
||||
anchors.topMargin: marginBetweenInputs
|
||||
label: qsTr("Decimals")
|
||||
text: "18"
|
||||
}
|
||||
|
||||
footer: Item {
|
||||
anchors.fill: parent
|
||||
StyledButton {
|
||||
id: addBtn
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: Theme.padding
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.padding
|
||||
label: qsTr("Add")
|
||||
|
||||
disabled: addressInput.text === "" || nameInput.text === "" || symbolInput.text === "" || decimalsInput.text === ""
|
||||
|
||||
onClicked : {
|
||||
const error = walletModel.addCustomToken(addressInput.text, nameInput.text, symbolInput.text, decimalsInput.text);
|
||||
|
||||
if (error) {
|
||||
changeError.text = error
|
||||
changeError.open()
|
||||
return
|
||||
}
|
||||
popup.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*##^##
|
||||
Designer {
|
||||
D{i:0;autoSize:true;height:480;width:640}
|
||||
}
|
||||
##^##*/
|
|
@ -21,6 +21,11 @@ Item {
|
|||
anchors.left: parent.left
|
||||
anchors.leftMargin: 0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
onStatusChanged: {
|
||||
if (assetInfoImage.status == Image.Error) {
|
||||
assetInfoImage.source = "../../img/tokens/0-native.png"
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
id: assetSymbol
|
||||
|
|
|
@ -134,11 +134,12 @@ Item {
|
|||
StyledButton {
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Theme.padding
|
||||
label: qsTr("Apply to all accounts")
|
||||
label: qsTr("Add custom token")
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: Theme.padding
|
||||
onClicked: {
|
||||
popup.close()
|
||||
addCustomTokenModal.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,10 @@ Item {
|
|||
changeSelectedAccount: walletHeader.changeSelectedAccount
|
||||
}
|
||||
|
||||
AddCustomTokenModal {
|
||||
id: addCustomTokenModal
|
||||
}
|
||||
|
||||
Item {
|
||||
property int btnMargin: 8
|
||||
property int btnOuterMargin: 32
|
||||
|
|
|
@ -78,6 +78,7 @@ DISTFILES += \
|
|||
app/AppLayouts/Profile/LeftTab/qmldir \
|
||||
app/AppLayouts/Profile/ProfileLayout.qml \
|
||||
app/AppLayouts/Wallet/AccountSettingsModal.qml \
|
||||
app/AppLayouts/Wallet/AddCustomTokenModal.qml \
|
||||
app/AppLayouts/Wallet/AssetsTab.qml \
|
||||
app/AppLayouts/Wallet/CollectiblesTab.qml \
|
||||
app/AppLayouts/Wallet/Components/AccountSettingsModal.qml \
|
||||
|
|
Loading…
Reference in New Issue