fix(@wallet): apply order to token list

This commit is contained in:
Anthony Laibe 2022-04-28 10:16:16 +02:00 committed by Anthony Laibe
parent 0f912a66b8
commit 50fef581a5
1 changed files with 11 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import tables import tables
import algorithm
import ./io_interface import ./io_interface
import ../../../../core/eventemitter import ../../../../core/eventemitter
@ -36,10 +37,20 @@ proc init*(self: Controller) =
self.delegate.refreshTokens() self.delegate.refreshTokens()
proc getTokens*(self: Controller): seq[token_service.TokenDto] = proc getTokens*(self: Controller): seq[token_service.TokenDto] =
proc compare(x, y: token_service.TokenDto): int =
if x.name < y.name:
return -1
elif x.name > y.name:
return 1
return 0
for tokens in self.tokenService.getTokens().values: for tokens in self.tokenService.getTokens().values:
for token in tokens: for token in tokens:
result.add(token) result.add(token)
result.sort(compare)
proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int): string = proc addCustomToken*(self: Controller, chainId: int, address: string, name: string, symbol: string, decimals: int): string =
return self.tokenService.addCustomToken(chainId, address, name, symbol, decimals) return self.tokenService.addCustomToken(chainId, address, name, symbol, decimals)