feat(@wallet): prevent to duplicate token

fixes #5567
This commit is contained in:
Anthony Laibe 2022-04-19 13:47:41 +02:00 committed by Anthony Laibe
parent 1ac4ea4158
commit 538cd6ae06
5 changed files with 13 additions and 8 deletions

View File

@ -40,8 +40,8 @@ proc getTokens*(self: Controller): seq[token_service.TokenDto] =
for token in tokens:
result.add(token)
proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int) =
self.tokenService.addCustomToken(chainId, address, name, symbol, decimals)
proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int): string =
return self.tokenService.addCustomToken(chainId, address, name, symbol, decimals)
proc toggleVisible*(self: Controller, chainId: int, address: string) =
self.walletAccountService.toggleTokenVisible(chainId, address)

View File

@ -11,7 +11,7 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
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): string {.base.} =
raise newException(ValueError, "No implementation available")
method toggleVisible*(self: AccessInterface, chainId: int, address: string) {.base.} =

View File

@ -74,8 +74,8 @@ method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.allTokensModuleDidLoad()
method addCustomToken*(self: Module, chainId: int, address: string, name: string, symbol: string, decimals: int) =
self.controller.addCustomToken(chainId, address, name, symbol, decimals)
method addCustomToken*(self: Module, chainId: int, address: string, name: string, symbol: string, decimals: int): string =
return self.controller.addCustomToken(chainId, address, name, symbol, decimals)
method toggleVisible*(self: Module, chainId: int, address: string) =
self.controller.toggleVisible(chainId, address)

View File

@ -61,8 +61,8 @@ QtObject:
self.custom.setItems(items.filter(i => i.getIsCustom()))
self.default.setItems(items.filter(i => not i.getIsCustom()))
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 addCustomToken(self: View, chainId: int, address: string, name: string, symbol: string, decimals: string): string {.slot.} =
return self.delegate.addCustomToken(chainId, address, name, symbol, parseInt(decimals))
proc toggleVisible(self: View, chainId: int, address: string) {.slot.} =
self.delegate.toggleVisible(chainId, address)

View File

@ -112,9 +112,14 @@ QtObject:
if token.isVisible:
result.add(token)
proc addCustomToken*(self: Service, chainId: int, address: string, name: string, symbol: string, decimals: int) =
proc addCustomToken*(self: Service, chainId: int, address: string, name: string, symbol: string, decimals: int): string =
# TODO(alaile): use chainId rather than first enabled network
let networkWIP = self.networkService.getEnabledNetworks()[0]
let foundToken = self.findTokenByAddress(networkWIP, parseAddress(address))
if not foundToken.isNil:
return "token already exists"
let backendToken = backend.Token(
name: name, chainId: networkWIP.chainId, address: address, symbol: symbol, decimals: decimals, color: ""
)