feat(@wallet): move visible token to status go

This commit is contained in:
Anthony Laibe 2022-04-04 14:11:39 +02:00 committed by Anthony Laibe
parent 45f147fa95
commit 3f71e1fe87
14 changed files with 50 additions and 69 deletions

View File

@ -134,7 +134,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.activityCenterService = activity_center_service.newService(statusFoundation.events, result.activityCenterService = activity_center_service.newService(statusFoundation.events,
statusFoundation.threadpool, result.chatService) statusFoundation.threadpool, result.chatService)
result.tokenService = token_service.newService( result.tokenService = token_service.newService(
statusFoundation.events, statusFoundation.threadpool, result.settingsService, result.networkService statusFoundation.events, statusFoundation.threadpool, result.networkService
) )
result.collectibleService = collectible_service.newService(result.settingsService) result.collectibleService = collectible_service.newService(result.settingsService)
result.walletAccountService = wallet_account_service.newService( result.walletAccountService = wallet_account_service.newService(

View File

@ -43,8 +43,8 @@ proc getTokens*(self: Controller): seq[token_service.TokenDto] =
proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int) = proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int) =
self.tokenService.addCustomToken(chainId, address, name, symbol, decimals) self.tokenService.addCustomToken(chainId, address, name, symbol, decimals)
proc toggleVisible*(self: Controller, chainId: int, symbol: string) = proc toggleVisible*(self: Controller, chainId: int, address: string) =
self.walletAccountService.toggleTokenVisible(chainId, symbol) self.walletAccountService.toggleTokenVisible(chainId, address)
proc removeCustomToken*(self: Controller, chainId: int, address: string) = proc removeCustomToken*(self: Controller, chainId: int, address: string) =
self.tokenService.removeCustomToken(chainId, address) self.tokenService.removeCustomToken(chainId, address)

View File

@ -14,7 +14,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method addCustomToken*(self: AccessInterface, chainId: int, address: string, name: string, symbol: string, decimals: int) {.base.} = method addCustomToken*(self: AccessInterface, chainId: int, address: string, name: string, symbol: string, decimals: int) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method toggleVisible*(self: AccessInterface, chainId: int, symbol: string) {.base.} = method toggleVisible*(self: AccessInterface, chainId: int, address: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method removeCustomToken*(self: AccessInterface, chainId: int, address: string) {.base.} = method removeCustomToken*(self: AccessInterface, chainId: int, address: string) {.base.} =

View File

@ -77,8 +77,8 @@ method viewDidLoad*(self: Module) =
method addCustomToken*(self: Module, chainId: int, address: string, name: string, symbol: string, decimals: int) = method addCustomToken*(self: Module, chainId: int, address: string, name: string, symbol: string, decimals: int) =
self.controller.addCustomToken(chainId, address, name, symbol, decimals) self.controller.addCustomToken(chainId, address, name, symbol, decimals)
method toggleVisible*(self: Module, chainId: int, symbol: string) = method toggleVisible*(self: Module, chainId: int, address: string) =
self.controller.toggleVisible(chainId, symbol) self.controller.toggleVisible(chainId, address)
method removeCustomToken*(self: Module, chainId: int, address: string) = method removeCustomToken*(self: Module, chainId: int, address: string) =
self.controller.removeCustomToken(chainId, address) self.controller.removeCustomToken(chainId, address)

View File

@ -64,8 +64,8 @@ QtObject:
proc addCustomToken(self: View, chainId: int, address: string, name: string, symbol: string, decimals: string) {.slot.} = proc addCustomToken(self: View, chainId: int, address: string, name: string, symbol: string, decimals: string) {.slot.} =
self.delegate.addCustomToken(chainId, address, name, symbol, parseInt(decimals)) self.delegate.addCustomToken(chainId, address, name, symbol, parseInt(decimals))
proc toggleVisible(self: View, chainId: int, symbol: string) {.slot.} = proc toggleVisible(self: View, chainId: int, address: string) {.slot.} =
self.delegate.toggleVisible(chainId, symbol) self.delegate.toggleVisible(chainId, address)
proc removeCustomToken(self: View, chainId: int, address: string) {.slot.} = proc removeCustomToken(self: View, chainId: int, address: string) {.slot.} =
self.delegate.removeCustomToken(chainId, address) self.delegate.removeCustomToken(chainId, address)

View File

@ -115,7 +115,6 @@ type
telemetryServerUrl*: string telemetryServerUrl*: string
fleet*: string fleet*: string
currentUserStatus*: CurrentUserStatus currentUserStatus*: CurrentUserStatus
walletVisibleTokens*: Table[int, seq[string]]
nodeConfig*: JsonNode nodeConfig*: JsonNode
wakuBloomFilterMode*: bool wakuBloomFilterMode*: bool
autoMessageEnabled*: bool autoMessageEnabled*: bool
@ -155,23 +154,11 @@ proc toPinnedMailserver*(jsonObj: JsonNode): PinnedMailserver =
discard jsonObj.getProp("status.test", result.statusTest) discard jsonObj.getProp("status.test", result.statusTest)
discard jsonObj.getProp("status.prod", result.statusProd) discard jsonObj.getProp("status.prod", result.statusProd)
proc toCurrentUserStatus*(jsonObj: JsonNode): CurrentUserStatus = proc toCurrentUserStatus*(jsonObj: JsonNode): CurrentUserStatus =
discard jsonObj.getProp("statusType", result.statusType) discard jsonObj.getProp("statusType", result.statusType)
discard jsonObj.getProp("clock", result.clock) discard jsonObj.getProp("clock", result.clock)
discard jsonObj.getProp("text", result.text) discard jsonObj.getProp("text", result.text)
proc toWalletVisibleTokens*(jsonObj: JsonNode): Table[int, seq[string]] =
for chainIdStr, tokenArr in jsonObj:
if(tokenArr.kind != JArray):
continue
let chainId = parseInt(chainIdStr)
result[chainId] = @[]
for token in tokenArr:
result[chainId].add(token.getStr)
proc toSettingsDto*(jsonObj: JsonNode): SettingsDto = proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
discard jsonObj.getProp(KEY_ADDRESS, result.address) discard jsonObj.getProp(KEY_ADDRESS, result.address)
discard jsonObj.getProp(KEY_CURRENCY, result.currency) discard jsonObj.getProp(KEY_CURRENCY, result.currency)
@ -221,10 +208,6 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
if(jsonObj.getProp(KEY_CURRENT_USER_STATUS, currentUserStatusObj)): if(jsonObj.getProp(KEY_CURRENT_USER_STATUS, currentUserStatusObj)):
result.currentUserStatus = toCurrentUserStatus(currentUserStatusObj) result.currentUserStatus = toCurrentUserStatus(currentUserStatusObj)
var walletVisibleTokensObj: JsonNode
if(jsonObj.getProp(KEY_WALLET_VISIBLE_TOKENS, walletVisibleTokensObj)):
result.walletVisibleTokens = toWalletVisibleTokens(walletVisibleTokensObj)
discard jsonObj.getProp(KEY_NODE_CONFIG, result.nodeConfig) discard jsonObj.getProp(KEY_NODE_CONFIG, result.nodeConfig)
discard jsonObj.getProp(KEY_WAKU_BLOOM_FILTER_MODE, result.wakuBloomFilterMode) discard jsonObj.getProp(KEY_WAKU_BLOOM_FILTER_MODE, result.wakuBloomFilterMode)

View File

@ -394,19 +394,22 @@ proc pinMailserver*(self: Service, address: string, fleet: Fleet): bool =
proc unpinMailserver*(self: Service, fleet: Fleet): bool = proc unpinMailserver*(self: Service, fleet: Fleet): bool =
return self.pinMailserver("", fleet) return self.pinMailserver("", fleet)
proc getWalletVisibleTokens*(self: Service): Table[int, seq[string]] = proc isEIP1559Enabled*(self: Service, blockNumber: int): bool =
self.settings.walletVisibleTokens let networkId = self.getCurrentNetworkDetails().config.NetworkId
let activationBlock = case networkId:
of 3: 10499401 # Ropsten
of 4: 8897988 # Rinkeby
of 5: 5062605 # Goerli
of 1: 12965000 # Mainnet
else: -1
if activationBlock > -1 and blockNumber >= activationBlock:
result = true
else:
result = false
self.eip1559Enabled = result
proc saveWalletVisibleTokens*(self: Service, visibleTokens: Table[int, seq[string]]): bool = proc isEIP1559Enabled*(self: Service): bool =
var obj = newJObject() result = self.eip1559Enabled
for chainId, tokens in visibleTokens.pairs:
obj[$chainId] = %* tokens
if(self.saveSetting(KEY_WALLET_VISIBLE_TOKENS, obj)):
self.settings.walletVisibleTokens = visibleTokens
return true
return false
proc saveNodeConfiguration*(self: Service, value: JsonNode): bool = proc saveNodeConfiguration*(self: Service, value: JsonNode): bool =
if(self.saveSetting(KEY_NODE_CONFIG, value)): if(self.saveSetting(KEY_NODE_CONFIG, value)):

View File

@ -5,7 +5,6 @@ import web3/ethtypes
from web3/conversions import `$` from web3/conversions import `$`
import ../../../backend/backend as backend import ../../../backend/backend as backend
import ../settings/service as settings_service
import ../network/service as network_service import ../network/service as network_service
import ../../../app/core/eventemitter import ../../../app/core/eventemitter
@ -19,7 +18,6 @@ logScope:
include async_tasks include async_tasks
const DEFAULT_VISIBLE_TOKENS = {1: @["SNT"], 3: @["STT"], 4: @["STT"]}.toTable()
# Signals which may be emitted by this service: # Signals which may be emitted by this service:
const SIGNAL_TOKEN_DETAILS_LOADED* = "tokenDetailsLoaded" const SIGNAL_TOKEN_DETAILS_LOADED* = "tokenDetailsLoaded"
const SIGNAL_TOKEN_LIST_RELOADED* = "tokenListReloaded" const SIGNAL_TOKEN_LIST_RELOADED* = "tokenListReloaded"
@ -44,7 +42,6 @@ QtObject:
type Service* = ref object of QObject type Service* = ref object of QObject
events: EventEmitter events: EventEmitter
threadpool: ThreadPool threadpool: ThreadPool
settingsService: settings_service.Service
networkService: network_service.Service networkService: network_service.Service
tokens: Table[NetworkDto, seq[TokenDto]] tokens: Table[NetworkDto, seq[TokenDto]]
@ -54,39 +51,34 @@ QtObject:
proc newService*( proc newService*(
events: EventEmitter, events: EventEmitter,
threadpool: ThreadPool, threadpool: ThreadPool,
settingsService: settings_service.Service,
networkService: network_service.Service, networkService: network_service.Service,
): Service = ): Service =
new(result, delete) new(result, delete)
result.QObject.setup result.QObject.setup
result.events = events result.events = events
result.threadpool = threadpool result.threadpool = threadpool
result.settingsService = settingsService
result.networkService = networkService result.networkService = networkService
result.tokens = initTable[NetworkDto, seq[TokenDto]]() result.tokens = initTable[NetworkDto, seq[TokenDto]]()
proc init*(self: Service) = proc init*(self: Service) =
try: try:
self.tokens = initTable[NetworkDto, seq[TokenDto]]() self.tokens = initTable[NetworkDto, seq[TokenDto]]()
var activeTokenSymbols = self.settingsService.getWalletVisibleTokens()
let networks = self.networkService.getEnabledNetworks() let networks = self.networkService.getEnabledNetworks()
let chainIds = networks.map(n => n.chainId)
let visibleTokens = backend.getVisibleTokens(chainIds).result
let responseCustomTokens = backend.getCustomTokens() let responseCustomTokens = backend.getCustomTokens()
for network in networks: for network in networks:
if not activeTokenSymbols.hasKey(network.chainId) and DEFAULT_VISIBLE_TOKENS.hasKey(network.chainId): let activeTokenSymbols = visibleTokens[$network.chainId].getElems().map(n => n["symbol"].getStr)
activeTokenSymbols[network.chainId] = DEFAULT_VISIBLE_TOKENS[network.chainId]
else:
activeTokenSymbols[network.chainId] = @[]
let responseTokens = backend.getTokens(network.chainId) let responseTokens = backend.getTokens(network.chainId)
let default_tokens = map( let default_tokens = map(
responseTokens.result.getElems(), responseTokens.result.getElems(),
proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols[network.chainId], hasIcon=true, isCustom=false) proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols, hasIcon=true, isCustom=false)
) )
self.tokens[network] = concat( self.tokens[network] = concat(
default_tokens, default_tokens,
map(responseCustomTokens.result.getElems(), proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols[network.chainId])) map(responseCustomTokens.result.getElems(), proc(x: JsonNode): TokenDto = x.toTokenDto(activeTokenSymbols))
).filter( ).filter(
proc(x: TokenDto): bool = x.chainId == network.chainId proc(x: TokenDto): bool = x.chainId == network.chainId
) )
@ -140,21 +132,17 @@ QtObject:
self.tokens[network].add(token) self.tokens[network].add(token)
self.events.emit("token/customTokenAdded", CustomTokenAdded(token: token)) self.events.emit("token/customTokenAdded", CustomTokenAdded(token: token))
proc toggleVisible*(self: Service, chainId: int, symbol: string) = proc toggleVisible*(self: Service, chainId: int, address: string) =
discard backend.toggleVisibleToken(chainId, address)
let network = self.networkService.getNetwork(chainId) let network = self.networkService.getNetwork(chainId)
var tokenChanged = self.tokens[network][0] var tokenChanged = self.tokens[network][0]
for token in self.tokens[network]: for token in self.tokens[network]:
if token.symbol == symbol: if token.addressAsString() == address:
token.isVisible = not token.isVisible token.isVisible = not token.isVisible
tokenChanged = token tokenChanged = token
break break
var visibleSymbols = initTable[int, seq[string]]()
for network, tokens in self.tokens.pairs:
let symbols = tokens.filter(t => t.isVisible).map(t => t.symbol)
visibleSymbols[network.chainId] = symbols
discard self.settingsService.saveWalletVisibleTokens(visibleSymbols)
self.events.emit("token/visibilityToggled", VisibilityToggled(token: tokenChanged)) self.events.emit("token/visibilityToggled", VisibilityToggled(token: tokenChanged))
proc removeCustomToken*(self: Service, chainId: int, address: string) = proc removeCustomToken*(self: Service, chainId: int, address: string) =

View File

@ -317,8 +317,8 @@ proc updateCurrency*(self: Service, newCurrency: string) =
self.refreshBalances() self.refreshBalances()
self.events.emit(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED, CurrencyUpdated()) self.events.emit(SIGNAL_WALLET_ACCOUNT_CURRENCY_UPDATED, CurrencyUpdated())
proc toggleTokenVisible*(self: Service, chainId: int, symbol: string) = proc toggleTokenVisible*(self: Service, chainId: int, address: string) =
self.tokenService.toggleVisible(chainId, symbol) self.tokenService.toggleVisible(chainId, address)
self.refreshBalances() self.refreshBalances()
self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED, TokenVisibilityToggled()) self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKEN_VISIBILITY_UPDATED, TokenVisibilityToggled())

View File

@ -96,6 +96,13 @@ rpc(discoverToken, "wallet"):
rpc(getPendingTransactions, "wallet"): rpc(getPendingTransactions, "wallet"):
discard discard
rpc(getVisibleTokens, "wallet"):
chainIds: seq[int]
rpc(toggleVisibleToken, "wallet"):
chainId: int
address: string
rpc(fetchPrices, "wallet"): rpc(fetchPrices, "wallet"):
symbols: seq[string] symbols: seq[string]
currency: string currency: string

View File

@ -16,7 +16,7 @@ Item {
property var defaultTokenList property var defaultTokenList
property var customTokenList property var customTokenList
signal toggleVisibleClicked(int chainId, string symbol) signal toggleVisibleClicked(int chainId, string address)
signal removeCustomTokenTriggered(int chainId, string address) signal removeCustomTokenTriggered(int chainId, string address)
signal showTokenDetailsTriggered(int chainId, string address, string name, string symbol, string decimals) signal showTokenDetailsTriggered(int chainId, string address, string name, string symbol, string decimals)
@ -32,7 +32,7 @@ Item {
components: [StatusCheckBox { components: [StatusCheckBox {
id: assetCheck id: assetCheck
checked: model.isVisible checked: model.isVisible
onClicked: toggleVisibleClicked(chainId, symbol) onClicked: toggleVisibleClicked(chainId, address)
}] }]
visible: symbol && (searchBox.text == "" || name.toLowerCase().includes(searchBox.text.toLowerCase()) || symbol.toLowerCase().includes(searchBox.text.toLowerCase())) visible: symbol && (searchBox.text == "" || name.toLowerCase().includes(searchBox.text.toLowerCase()) || symbol.toLowerCase().includes(searchBox.text.toLowerCase()))
MouseArea { MouseArea {
@ -44,13 +44,13 @@ Item {
return contextMenu.popup(mouseX, mouseY) return contextMenu.popup(mouseX, mouseY)
} }
assetCheck.checked = !assetCheck.checked assetCheck.checked = !assetCheck.checked
toggleVisibleClicked(chainId, symbol) toggleVisibleClicked(chainId, address)
} }
StatusPopupMenu { StatusPopupMenu {
id: contextMenu id: contextMenu
Action { Action {
icon.source: Style.svg("make-admin") icon.name: "admin"
//% "Token details" //% "Token details"
text: qsTrId("token-details") text: qsTrId("token-details")
onTriggered: { onTriggered: {
@ -58,7 +58,7 @@ Item {
} }
} }
Action { Action {
icon.source: Style.svg("remove-from-group") icon.name: "remove"
icon.color: Style.current.red icon.color: Style.current.red
enabled: isCustom enabled: isCustom
//% "Remove token" //% "Remove token"

View File

@ -39,7 +39,7 @@ StatusModal {
customTokenList: walletStore.customTokenList customTokenList: walletStore.customTokenList
onToggleVisibleClicked: { onToggleVisibleClicked: {
walletStore.toggleVisible(chainId, symbol) walletStore.toggleVisible(chainId, address)
} }
onRemoveCustomTokenTriggered: { onRemoveCustomTokenTriggered: {
walletStore.removeCustomToken(chainId, address) walletStore.removeCustomToken(chainId, address)

View File

@ -26,8 +26,8 @@ QtObject {
return walletSectionAllTokens.addCustomToken(chainId, address, name, symbol, decimals) return walletSectionAllTokens.addCustomToken(chainId, address, name, symbol, decimals)
} }
function toggleVisible(chainId, symbol) { function toggleVisible(chainId, address) {
walletSectionAllTokens.toggleVisible(chainId, symbol) walletSectionAllTokens.toggleVisible(chainId, address)
} }
function removeCustomToken(chainId, address) { function removeCustomToken(chainId, address) {

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 9fef24917a9c643341de200c3a4045148e9e9ab1 Subproject commit 907ba8ee5c59922721cfcb6a1485e2bf7b8bb9e7