diff --git a/src/app/modules/main/wallet_section/all_tokens/controller.nim b/src/app/modules/main/wallet_section/all_tokens/controller.nim index d419de0509..02c30e7fbd 100644 --- a/src/app/modules/main/wallet_section/all_tokens/controller.nim +++ b/src/app/modules/main/wallet_section/all_tokens/controller.nim @@ -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) diff --git a/src/app/modules/main/wallet_section/all_tokens/io_interface.nim b/src/app/modules/main/wallet_section/all_tokens/io_interface.nim index 3989192e0a..db48d026e6 100644 --- a/src/app/modules/main/wallet_section/all_tokens/io_interface.nim +++ b/src/app/modules/main/wallet_section/all_tokens/io_interface.nim @@ -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.} = diff --git a/src/app/modules/main/wallet_section/all_tokens/module.nim b/src/app/modules/main/wallet_section/all_tokens/module.nim index a32a9128f5..7cb976a745 100644 --- a/src/app/modules/main/wallet_section/all_tokens/module.nim +++ b/src/app/modules/main/wallet_section/all_tokens/module.nim @@ -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) diff --git a/src/app/modules/main/wallet_section/all_tokens/view.nim b/src/app/modules/main/wallet_section/all_tokens/view.nim index c9135b39c2..18b8ad2da1 100644 --- a/src/app/modules/main/wallet_section/all_tokens/view.nim +++ b/src/app/modules/main/wallet_section/all_tokens/view.nim @@ -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) diff --git a/src/app_service/service/token/service.nim b/src/app_service/service/token/service.nim index 2b90e183b3..b08bd6ace5 100644 --- a/src/app_service/service/token/service.nim +++ b/src/app_service/service/token/service.nim @@ -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: "" )