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,
statusFoundation.threadpool, result.chatService)
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.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) =
self.tokenService.addCustomToken(chainId, address, name, symbol, decimals)
proc toggleVisible*(self: Controller, chainId: int, symbol: string) =
self.walletAccountService.toggleTokenVisible(chainId, symbol)
proc toggleVisible*(self: Controller, chainId: int, address: string) =
self.walletAccountService.toggleTokenVisible(chainId, address)
proc removeCustomToken*(self: Controller, chainId: int, address: string) =
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.} =
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")
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) =
self.controller.addCustomToken(chainId, address, name, symbol, decimals)
method toggleVisible*(self: Module, chainId: int, symbol: string) =
self.controller.toggleVisible(chainId, symbol)
method toggleVisible*(self: Module, chainId: int, address: string) =
self.controller.toggleVisible(chainId, address)
method removeCustomToken*(self: Module, chainId: int, address: string) =
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.} =
self.delegate.addCustomToken(chainId, address, name, symbol, parseInt(decimals))
proc toggleVisible(self: View, chainId: int, symbol: string) {.slot.} =
self.delegate.toggleVisible(chainId, symbol)
proc toggleVisible(self: View, chainId: int, address: string) {.slot.} =
self.delegate.toggleVisible(chainId, address)
proc removeCustomToken(self: View, chainId: int, address: string) {.slot.} =
self.delegate.removeCustomToken(chainId, address)

View File

@ -115,7 +115,6 @@ type
telemetryServerUrl*: string
fleet*: string
currentUserStatus*: CurrentUserStatus
walletVisibleTokens*: Table[int, seq[string]]
nodeConfig*: JsonNode
wakuBloomFilterMode*: bool
autoMessageEnabled*: bool
@ -155,23 +154,11 @@ proc toPinnedMailserver*(jsonObj: JsonNode): PinnedMailserver =
discard jsonObj.getProp("status.test", result.statusTest)
discard jsonObj.getProp("status.prod", result.statusProd)
proc toCurrentUserStatus*(jsonObj: JsonNode): CurrentUserStatus =
discard jsonObj.getProp("statusType", result.statusType)
discard jsonObj.getProp("clock", result.clock)
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 =
discard jsonObj.getProp(KEY_ADDRESS, result.address)
discard jsonObj.getProp(KEY_CURRENCY, result.currency)
@ -221,10 +208,6 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
if(jsonObj.getProp(KEY_CURRENT_USER_STATUS, 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_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 =
return self.pinMailserver("", fleet)
proc getWalletVisibleTokens*(self: Service): Table[int, seq[string]] =
self.settings.walletVisibleTokens
proc isEIP1559Enabled*(self: Service, blockNumber: int): bool =
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 =
var obj = newJObject()
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 isEIP1559Enabled*(self: Service): bool =
result = self.eip1559Enabled
proc saveNodeConfiguration*(self: Service, value: JsonNode): bool =
if(self.saveSetting(KEY_NODE_CONFIG, value)):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

2
vendor/status-go vendored

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