status-lib/status/tokens.nim

51 lines
1.7 KiB
Nim
Raw Normal View History

2021-09-22 17:49:45 +00:00
import statusgo_backend/settings as status_settings
import statusgo_backend/tokens as statusgo_backend_tokens
2021-09-22 17:49:45 +00:00
import eth/tokens as status_tokens
import eth/contracts
2021-09-22 17:49:45 +00:00
import ./types/network_type
2021-09-08 18:05:39 +00:00
import ../eventemitter
type
TokensModel* = ref object
events*: EventEmitter
proc newTokensModel*(events: EventEmitter): TokensModel =
result = TokensModel()
result.events = events
proc getSNTAddress*(): string =
2021-09-22 17:49:45 +00:00
let network = status_settings.getCurrentNetwork().toNetwork()
result = status_tokens.getSNTAddress(network)
2021-09-08 18:05:39 +00:00
proc getCustomTokens*(self: TokensModel, useCached: bool = true): seq[Erc20Contract] =
result = statusgo_backend_tokens.getCustomTokens(useCached)
2021-09-08 18:05:39 +00:00
proc removeCustomToken*(self: TokensModel, address: string) =
statusgo_backend_tokens.removeCustomToken(address)
2021-09-08 18:05:39 +00:00
proc getSNTBalance*(account: string): string =
2021-09-22 17:49:45 +00:00
let network = status_settings.getCurrentNetwork().toNetwork()
result = status_tokens.getSNTBalance(network, account)
2021-09-08 18:05:39 +00:00
proc tokenDecimals*(contract: Contract): int =
result = status_tokens.tokenDecimals(contract)
proc tokenName*(contract: Contract): string =
result = status_tokens.tokenName(contract)
proc tokensymbol*(contract: Contract): string =
result = status_tokens.tokensymbol(contract)
proc getTokenBalance*(tokenAddress: string, account: string): string =
2021-09-22 17:49:45 +00:00
let network = status_settings.getCurrentNetwork().toNetwork()
result = status_tokens.getTokenBalance(network, tokenAddress, account)
2021-09-08 18:05:39 +00:00
proc getToken*(self: TokensModel, tokenAddress: string): Erc20Contract =
2021-09-22 17:49:45 +00:00
let network = status_settings.getCurrentNetwork().toNetwork()
result = status_tokens.getToken(network, tokenAddress)
2021-09-08 18:05:39 +00:00
export newErc20Contract
2021-09-22 17:49:45 +00:00
export allErc20ContractsByChainId
2021-09-08 18:05:39 +00:00
export Erc20Contract
2021-09-22 17:49:45 +00:00
export findByAddress