feat: show SNT by default in the token list, and STT in ropsten
fixes #805
This commit is contained in:
parent
addd1d9c3e
commit
0b6643ac2d
|
@ -5,7 +5,7 @@ import ../../status/libstatus/wallet as status_wallet
|
|||
import ../../status/libstatus/tokens
|
||||
import ../../status/libstatus/types
|
||||
import ../../status/libstatus/utils
|
||||
import views/[asset_list, account_list, account_item, transaction_list, collectibles_list]
|
||||
import views/[asset_list, account_list, account_item, token_list, transaction_list, collectibles_list]
|
||||
|
||||
QtObject:
|
||||
type
|
||||
|
@ -15,6 +15,7 @@ QtObject:
|
|||
currentCollectiblesLists*: CollectiblesList
|
||||
currentAccount: AccountItemView
|
||||
currentTransactions: TransactionList
|
||||
defaultTokenList: TokenList
|
||||
status: Status
|
||||
totalFiatBalance: string
|
||||
etherscanLink: string
|
||||
|
@ -30,6 +31,7 @@ QtObject:
|
|||
self.currentAssetList.delete
|
||||
self.currentAccount.delete
|
||||
self.currentTransactions.delete
|
||||
self.defaultTokenList.delete
|
||||
self.QAbstractListModel.delete
|
||||
|
||||
proc setup(self: WalletView) =
|
||||
|
@ -43,6 +45,7 @@ QtObject:
|
|||
result.currentAssetList = newAssetList()
|
||||
result.currentTransactions = newTransactionList()
|
||||
result.currentCollectiblesLists = newCollectiblesList()
|
||||
result.defaultTokenList = newTokenList()
|
||||
result.totalFiatBalance = ""
|
||||
result.etherscanLink = ""
|
||||
result.safeLowGasPrice = "0"
|
||||
|
@ -261,8 +264,8 @@ QtObject:
|
|||
proc hasAsset*(self: WalletView, account: string, symbol: string): bool {.slot.} =
|
||||
self.status.wallet.hasAsset(account, symbol)
|
||||
|
||||
proc toggleAsset*(self: WalletView, symbol: string, checked: bool, address: string, name: string, decimals: int, color: string) {.slot.} =
|
||||
self.status.wallet.toggleAsset(symbol, checked, address, name, decimals, color)
|
||||
proc toggleAsset*(self: WalletView, symbol: string) {.slot.} =
|
||||
self.status.wallet.toggleAsset(symbol)
|
||||
for account in self.status.wallet.accounts:
|
||||
if account.address == self.currentAccount.address:
|
||||
self.currentAccount.setAccountItem(account)
|
||||
|
@ -279,7 +282,7 @@ QtObject:
|
|||
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), "")
|
||||
self.status.wallet.addCustomToken(symbol, true, address, name, parseInt(decimals), "")
|
||||
|
||||
proc loadCollectiblesForAccount*(self: WalletView, address: string, currentCollectiblesList: seq[CollectibleList]) =
|
||||
if (currentCollectiblesList.len > 0):
|
||||
|
@ -452,3 +455,10 @@ QtObject:
|
|||
|
||||
proc getDefaultAddress*(self: WalletView): string {.slot.} =
|
||||
result = $status_wallet.getWalletAccounts()[0].address
|
||||
|
||||
proc getDefaultTokenList(self: WalletView): QVariant {.slot.} =
|
||||
self.defaultTokenList.setupTokens()
|
||||
result = newQVariant(self.defaultTokenList)
|
||||
|
||||
QtProperty[QVariant] defaultTokenList:
|
||||
read = getDefaultTokenList
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
import NimQml, tables, json
|
||||
import ../../../status/libstatus/default_tokens
|
||||
|
||||
type
|
||||
TokenRoles {.pure.} = enum
|
||||
Name = UserRole + 1,
|
||||
Symbol = UserRole + 2,
|
||||
HasIcon = UserRole + 3
|
||||
|
||||
QtObject:
|
||||
type TokenList* = ref object of QAbstractListModel
|
||||
tokens*: seq[JsonNode]
|
||||
|
||||
proc setup(self: TokenList) =
|
||||
self.QAbstractListModel.setup
|
||||
|
||||
proc delete(self: TokenList) =
|
||||
self.tokens = @[]
|
||||
self.QAbstractListModel.delete
|
||||
|
||||
proc setupTokens*(self:TokenList) =
|
||||
if self.tokens.len == 0:
|
||||
self.tokens = getDefaultTokens().getElems()
|
||||
|
||||
proc newTokenList*(): TokenList =
|
||||
new(result, delete)
|
||||
result.tokens = @[]
|
||||
result.setup
|
||||
|
||||
method rowCount(self: TokenList, index: QModelIndex = nil): int =
|
||||
return self.tokens.len
|
||||
|
||||
method data(self: TokenList, index: QModelIndex, role: int): QVariant =
|
||||
if not index.isValid:
|
||||
return
|
||||
if index.row < 0 or index.row >= self.tokens.len:
|
||||
return
|
||||
let token = self.tokens[index.row]
|
||||
let tokenRole = role.TokenRoles
|
||||
case tokenRole:
|
||||
of TokenRoles.Name: result = newQVariant(token["name"].getStr)
|
||||
of TokenRoles.Symbol: result = newQVariant(token["symbol"].getStr)
|
||||
of TokenRoles.HasIcon: result = newQVariant(token["hasIcon"].getBool)
|
||||
|
||||
method roleNames(self: TokenList): Table[int, string] =
|
||||
{TokenRoles.Name.int:"name",
|
||||
TokenRoles.Symbol.int:"symbol",
|
||||
TokenRoles.HasIcon.int:"hasIcon"}.toTable
|
||||
|
||||
proc forceUpdate*(self: TokenList) =
|
||||
self.beginResetModel()
|
||||
self.endResetModel()
|
File diff suppressed because it is too large
Load Diff
|
@ -3,6 +3,10 @@ import core, wallet
|
|||
import contracts
|
||||
import eth/common/eth_types, eth/common/utils, stew/byteutils
|
||||
import json_serialization
|
||||
import settings
|
||||
from types import Setting, Network
|
||||
import default_tokens
|
||||
import strutils
|
||||
|
||||
logScope:
|
||||
topics = "wallet"
|
||||
|
@ -14,6 +18,45 @@ proc getCustomTokens*(): JsonNode =
|
|||
return %* []
|
||||
return response["result"]
|
||||
|
||||
proc visibleTokensSNTDefault(): JsonNode =
|
||||
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
||||
let SNT = if getCurrentNetwork() == Network.Testnet: "STT" else: "SNT"
|
||||
let response = getSetting[string](Setting.VisibleTokens, "{\"" & currentNetwork & "\": [\"" & SNT & "\"]}")
|
||||
echo response
|
||||
result = response.parseJson
|
||||
|
||||
proc toggleAsset*(symbol: string) =
|
||||
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
||||
let visibleTokens = visibleTokensSNTDefault()
|
||||
var visibleTokenList = visibleTokens[currentNetwork].to(seq[string])
|
||||
var symbolIdx = visibleTokenList.find(symbol)
|
||||
if symbolIdx > -1:
|
||||
visibleTokenList.del(symbolIdx)
|
||||
else:
|
||||
visibleTokenList.add symbol
|
||||
visibleTokens[currentNetwork] = newJArray()
|
||||
visibleTokens[currentNetwork] = %* visibleTokenList
|
||||
discard saveSetting(Setting.VisibleTokens, $visibleTokens)
|
||||
|
||||
proc getVisibleTokens*(): JsonNode =
|
||||
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
||||
let visibleTokens = visibleTokensSNTDefault()
|
||||
let visibleTokenList = visibleTokens[currentNetwork].to(seq[string])
|
||||
let customTokens = getCustomTokens()
|
||||
|
||||
result = newJArray()
|
||||
for defToken in getDefaultTokens().getElems():
|
||||
for v in visibleTokenList:
|
||||
if defToken["symbol"].getStr == v:
|
||||
result.elems.add(defToken)
|
||||
break
|
||||
|
||||
for custToken in customTokens.getElems():
|
||||
for v in visibleTokenList:
|
||||
if custToken["symbol"].getStr == v:
|
||||
result.elems.add(custToken)
|
||||
break
|
||||
|
||||
proc addCustomToken*(address: string, name: string, symbol: string, decimals: int, color: string) =
|
||||
let payload = %* [{"address": address, "name": name, "symbol": symbol, "decimals": decimals, "color": color}]
|
||||
discard callPrivateRPC("wallet_addCustomToken", payload)
|
||||
|
|
|
@ -159,6 +159,7 @@ type
|
|||
PreferredUsername = "preferred-name"
|
||||
Usernames = "usernames"
|
||||
SigningPhrase = "signing-phrase"
|
||||
VisibleTokens = "wallet/visible-tokens"
|
||||
|
||||
UpstreamConfig* = ref object
|
||||
enabled* {.serializedFieldName("Enabled").}: bool
|
||||
|
|
|
@ -114,7 +114,7 @@ proc newAccount*(self: WalletModel, name: string, address: string, iconColor: st
|
|||
account
|
||||
|
||||
proc initAccounts*(self: WalletModel) =
|
||||
self.tokens = status_tokens.getCustomTokens()
|
||||
self.tokens = status_tokens.getVisibleTokens()
|
||||
let accounts = status_wallet.getWalletAccounts()
|
||||
for account in accounts:
|
||||
var acc = WalletAccount(account)
|
||||
|
@ -203,13 +203,17 @@ proc changeAccountSettings*(self: WalletModel, address: string, accountName: str
|
|||
proc deleteAccount*(self: WalletModel, address: string): string =
|
||||
result = status_accounts.deleteAccount(address)
|
||||
|
||||
proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) =
|
||||
self.tokens = addOrRemoveToken(enable, address, name, symbol, decimals, color)
|
||||
proc toggleAsset*(self: WalletModel, symbol: string) =
|
||||
status_tokens.toggleAsset(symbol)
|
||||
self.tokens = status_tokens.getVisibleTokens()
|
||||
for account in self.accounts:
|
||||
account.assetList = self.generateAccountConfiguredAssets(account.address)
|
||||
updateBalance(account, self.getDefaultCurrency())
|
||||
self.events.emit("assetChanged", Args())
|
||||
|
||||
proc addCustomToken*(self: WalletModel, symbol: string, enable: bool, address: string, name: string, decimals: int, color: string) =
|
||||
addCustomToken(address, name, symbol, decimals, color)
|
||||
|
||||
proc getTransfersByAddress*(self: WalletModel, address: string): seq[Transaction] =
|
||||
result = status_wallet.getTransfersByAddress(address)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ ModalPopup {
|
|||
property int marginBetweenInputs: 35
|
||||
|
||||
onOpened: {
|
||||
accountNameInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||
addressInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||
}
|
||||
|
||||
Input {
|
||||
|
|
|
@ -5,10 +5,6 @@ import "../../../imports"
|
|||
import "../../../shared"
|
||||
|
||||
Item {
|
||||
Tokens {
|
||||
id: tokenList
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loadingImg
|
||||
active: false
|
||||
|
@ -45,8 +41,9 @@ Item {
|
|||
radius: 8
|
||||
|
||||
Component.onCompleted: {
|
||||
for (let i = 0; i < tokenList.count; i++) {
|
||||
let token = tokenList.get(i)
|
||||
// TODO: test if this work. I could not obtain any transaction history
|
||||
for (let i = 0; i < walletModel.defaultTokenList.items.count; i++) {
|
||||
let token = walletModel.defaultTokenList.items.get(i)
|
||||
if (token.address == contract) {
|
||||
transactionListItem.symbol = token.symbol
|
||||
break;
|
||||
|
@ -183,7 +180,6 @@ Item {
|
|||
model: walletModel.transactions
|
||||
delegate: transactionListItemCmp
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*##^##
|
||||
|
|
|
@ -25,7 +25,7 @@ Item {
|
|||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
model: Tokens {}
|
||||
model: walletModel.defaultTokenList
|
||||
ScrollBar.vertical: ScrollBar { active: true }
|
||||
|
||||
delegate: Component {
|
||||
|
@ -75,7 +75,7 @@ Item {
|
|||
checked: walletModel.hasAsset("0x123", symbol)
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Style.current.smallPadding
|
||||
onClicked: walletModel.toggleAsset(symbol, assetCheck.checked, address, name, decimals, "eeeeee")
|
||||
onClicked: walletModel.toggleAsset(symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 730 B |
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in New Issue