feat: testnet tokens
This commit is contained in:
parent
811024b0ee
commit
24212a63e9
|
@ -20,14 +20,17 @@ QtObject:
|
||||||
self.tokens = @[]
|
self.tokens = @[]
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
|
|
||||||
|
proc tokensLoaded(self: TokenList, cnt: int) {.signal.}
|
||||||
|
|
||||||
proc loadDefaultTokens*(self:TokenList) =
|
proc loadDefaultTokens*(self:TokenList) =
|
||||||
if self.tokens.len == 0:
|
if self.tokens.len == 0:
|
||||||
self.tokens = getDefaultTokens().getElems()
|
self.tokens = getDefaultTokens().getElems()
|
||||||
|
self.tokensLoaded(self.tokens.len)
|
||||||
|
|
||||||
proc loadCustomTokens*(self: TokenList) =
|
proc loadCustomTokens*(self: TokenList) =
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.tokens = getCustomTokens().getElems()
|
self.tokens = getCustomTokens().getElems()
|
||||||
echo $self.tokens
|
self.tokensLoaded(self.tokens.len)
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
|
|
||||||
proc newTokenList*(): TokenList =
|
proc newTokenList*(): TokenList =
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -46,10 +46,22 @@ proc getSetting*[T](name: Setting, useCached: bool = true): T =
|
||||||
result = getSetting(name, default(type(T)), useCached)
|
result = getSetting(name, default(type(T)), useCached)
|
||||||
|
|
||||||
proc getCurrentNetwork*(): Network =
|
proc getCurrentNetwork*(): Network =
|
||||||
result = Network.Mainnet
|
case getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME):
|
||||||
if getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME) == "testnet_rpc":
|
of "mainnet_rpc":
|
||||||
|
result = Network.Mainnet
|
||||||
|
of "testnet_rpc":
|
||||||
result = Network.Testnet
|
result = Network.Testnet
|
||||||
|
of "rinkeby_rpc":
|
||||||
|
result = Network.Rinkeby
|
||||||
|
of "goerli_rpc":
|
||||||
|
result = Network.Goerli
|
||||||
|
of "xdai_rpc":
|
||||||
|
result = Network.XDai
|
||||||
|
of "poa_rpc":
|
||||||
|
result = Network.Poa
|
||||||
|
else:
|
||||||
|
result = Network.Other
|
||||||
|
|
||||||
proc getCurrentNetworkDetails*(): NetworkDetails =
|
proc getCurrentNetworkDetails*(): NetworkDetails =
|
||||||
let currNetwork = getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
|
let currNetwork = getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
|
||||||
let networks = getSetting[seq[NetworkDetails]](Setting.Networks_Networks)
|
let networks = getSetting[seq[NetworkDetails]](Setting.Networks_Networks)
|
||||||
|
|
|
@ -45,8 +45,13 @@ proc getTokenByAddress*(tokenList: JsonNode, address: string): JsonNode =
|
||||||
proc visibleTokensSNTDefault(): JsonNode =
|
proc visibleTokensSNTDefault(): JsonNode =
|
||||||
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
||||||
let SNT = if getCurrentNetwork() == Network.Testnet: "STT" else: "SNT"
|
let SNT = if getCurrentNetwork() == Network.Testnet: "STT" else: "SNT"
|
||||||
let response = getSetting[string](Setting.VisibleTokens, "{\"" & currentNetwork & "\": [\"" & SNT & "\"]}")
|
let response = getSetting[string](Setting.VisibleTokens, "{}").parseJSON
|
||||||
result = response.parseJson
|
|
||||||
|
if response.hasKey(currentNetwork): return response
|
||||||
|
|
||||||
|
# Set STT/SNT visible by default
|
||||||
|
response[currentNetwork] = %* [SNT]
|
||||||
|
return response
|
||||||
|
|
||||||
proc toggleAsset*(symbol: string) =
|
proc toggleAsset*(symbol: string) =
|
||||||
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
let currentNetwork = getSetting[string](Setting.Networks_CurrentNetwork)
|
||||||
|
|
|
@ -143,7 +143,12 @@ proc readValue*(reader: var JsonReader, value: var Stuint[256])
|
||||||
type
|
type
|
||||||
Network* {.pure.} = enum
|
Network* {.pure.} = enum
|
||||||
Mainnet,
|
Mainnet,
|
||||||
Testnet
|
Testnet,
|
||||||
|
Rinkeby,
|
||||||
|
Goerli,
|
||||||
|
XDai,
|
||||||
|
Poa,
|
||||||
|
Other
|
||||||
|
|
||||||
Setting* {.pure.} = enum
|
Setting* {.pure.} = enum
|
||||||
Appearance = "appearance",
|
Appearance = "appearance",
|
||||||
|
|
|
@ -123,11 +123,19 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
|
id: customTokensRepeater
|
||||||
model: walletModel.customTokenList
|
model: walletModel.customTokenList
|
||||||
delegate: tokenComponent
|
delegate: tokenComponent
|
||||||
anchors.top: customLbl.bottom
|
anchors.top: customLbl.bottom
|
||||||
anchors.topMargin: Style.current.smallPadding
|
anchors.topMargin: Style.current.smallPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: walletModel.customTokenList
|
||||||
|
onTokensLoaded: {
|
||||||
|
customLbl.visible = cnt > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
|
Loading…
Reference in New Issue