feat: testnet tokens

This commit is contained in:
Richard Ramos 2020-09-08 12:40:09 -04:00 committed by Iuri Matias
parent 811024b0ee
commit 24212a63e9
6 changed files with 1280 additions and 1154 deletions

View File

@ -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 =

View File

@ -3,7 +3,19 @@ import settings
import types import types
proc getDefaultTokens*(): JsonNode = proc getDefaultTokens*(): JsonNode =
result = %* [ if getCurrentNetwork() == Network.Testnet:
return %* [
{
"symbol": "STT",
"name": "Status Test Token",
"address": "0xc55cf4b03948d7ebc8b9e8bad92643703811d162",
"decimals": 18,
"hasIcon": true
}
]
if getCurrentNetwork() == Network.Mainnet:
return %* [
{ {
"symbol": "DAI", "symbol": "DAI",
"name": "Dai Stablecoin", "name": "Dai Stablecoin",
@ -1144,11 +1156,92 @@ proc getDefaultTokens*(): JsonNode =
] ]
if getCurrentNetwork() == Network.Testnet: if getCurrentNetwork() == Network.Testnet:
result.add(%* { return %* [
{
"symbol": "STT", "symbol": "STT",
"name": "Status Test Token", "name": "Status Test Token",
"address": "0xc55cf4b03948d7ebc8b9e8bad92643703811d162", "address": "0xc55cf4b03948d7ebc8b9e8bad92643703811d162",
"decimals": 18, "decimals": 18,
"hasIcon": true "hasIcon": true
}) },
{
"symbol": "HND",
"name": "Handy Test Token",
"address": "0xdee43a267e8726efd60c2e7d5b81552dcd4fa35c",
"decimals": 0,
"hasIcon": false
},
{
"symbol": "LXS",
"name": "Lucky Test Token",
"address": "0x703d7dc0bc8e314d65436adf985dda51e09ad43b",
"decimals": 2,
"hasIcon": false
},
{
"symbol": "ADI",
"name": "Adi Test Token",
"address": "0xe639e24346d646e927f323558e6e0031bfc93581",
"decimals": 7,
"hasIcon": false
},
{
"symbol": "WGN",
"name": "Wagner Test Token",
"address": "0x2e7cd05f437eb256f363417fd8f920e2efa77540",
"decimals": 10,
"hasIcon": false
},
{
"symbol": "MDS",
"name": "Modest Test Token",
"address": "0x57cc9b83730e6d22b224e9dc3e370967b44a2de0",
"decimals": 18,
"hasIcon": false
}
]
if getCurrentNetwork() == Network.Rinkeby:
return %* [
{
"symbol": "MOKSHA",
"name": "Moksha Coin",
"address": "0x6ba7dc8dd10880ab83041e60c4ede52bb607864b",
"decimals": 18,
"hasIcon": false
},
{
"symbol": "KDO",
"nft": true,
"name": "KudosToken",
"address": "0x93bb0afbd0627bbd3a6c72bc318341d3a22e254a",
"hasIcon": false
},
{
"symbol": "WIBB",
"name": "WIBB",
"address": "0x7d4ccf6af2f0fdad48ee7958bcc28bdef7b732c7",
"decimals": 18,
"hasIcon": false
},
{
"symbol": "STT",
"name": "Status Test Token",
"address": "0x43d5adc3b49130a575ae6e4b00dfa4bc55c71621",
"decimals": 18,
"hasIcon": false
}
]
if getCurrentNetwork() == Network.XDai:
return %* [
{
"symbol": "BUFF",
"name": "buffiDai",
"address": "0x3e50bf6703fc132a94e4baff068db2055655f11b",
"decimals": 18,
"hasIcon": false
}
]
return %* []

View File

@ -46,9 +46,21 @@ 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 =
case getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME):
of "mainnet_rpc":
result = Network.Mainnet result = Network.Mainnet
if getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME) == "testnet_rpc": 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)

View File

@ -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)

View File

@ -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",

View File

@ -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 {