From 80456eaa10c2d4039577b30056374e8bde8b35b1 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 9 Jun 2021 10:27:21 -0400 Subject: [PATCH] remove libstatus references from the wallet view --- src/app/chat/view.nim | 1 - src/app/wallet/view.nim | 26 +++++++++++++------------- src/status/tokens.nim | 10 ++++++++++ src/status/wallet.nim | 9 +++++++++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 53c143d190..feef8b3e7a 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -34,7 +34,6 @@ type const getLinkPreviewDataTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[GetLinkPreviewDataTaskArg](argEncoded) var success: bool - # We need to call directly on libstatus because going through the status model is not thread safe let response = status_chat.getLinkPreviewData(arg.link, success) responseJson = %* { "result": %response, "success": %success, "uuid": %arg.uuid } diff --git a/src/app/wallet/view.nim b/src/app/wallet/view.nim index 4fbae622f0..502b6053b3 100644 --- a/src/app/wallet/view.nim +++ b/src/app/wallet/view.nim @@ -6,12 +6,13 @@ import # vendor libs NimQml, chronicles, stint import # status-desktop libs - ../../status/[status, wallet, settings], + ../../status/[status, wallet, settings, tokens], ../../status/wallet/collectibles as status_collectibles, - ../../status/libstatus/wallet as status_wallet, - ../../status/libstatus/tokens, ../../status/types, + ../../status/wallet as status_wallet, + ../../status/types, ../../status/utils as status_utils, - ../../status/libstatus/eth/contracts, ../../status/ens as status_ens, + ../../status/tokens as status_tokens, + ../../status/ens as status_ens, views/[asset_list, account_list, account_item, token_list, transaction_list, collectibles_list], ../../status/tasks/[qt, task_runner_impl], ../../status/signals/types as signal_types @@ -78,7 +79,7 @@ const initBalancesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[InitBalancesTaskArg](argEncoded) var tokenBalances = initTable[string, string]() for token in arg.tokenList: - tokenBalances[token] = getTokenBalance(token, arg.address) + tokenBalances[token] = status_tokens.getTokenBalance(token, arg.address) let output = %* { "address": arg.address, "eth": getEthBalance(arg.address), @@ -147,7 +148,7 @@ const loadTransactionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} arg = decode[LoadTransactionsTaskArg](argEncoded) output = %*{ "address": arg.address, - "history": getTransfersByAddress(arg.address, arg.toBlock, arg.limit, arg.loadMore), + "history": status_wallet.getTransfersByAddress(arg.address, arg.toBlock, arg.limit, arg.loadMore), "loadMore": arg.loadMore } arg.finish(output) @@ -379,7 +380,6 @@ QtObject: write = setCurrentAssetList notify = currentAssetListChanged - proc totalFiatBalanceChanged*(self: WalletView) {.signal.} proc getTotalFiatBalance(self: WalletView): string {.slot.} = @@ -526,10 +526,10 @@ QtObject: self.currentAccountChanged() proc removeCustomToken*(self: WalletView, tokenAddress: string) {.slot.} = - let t = getCustomTokens().getErc20ContractByAddress(parseAddress(tokenAddress)) + let t = self.status.tokens.getCustomTokens().getErc20ContractByAddress(parseAddress(tokenAddress)) if t == nil: return self.status.wallet.hideAsset(t.symbol) - removeCustomToken(tokenAddress) + self.status.tokens.removeCustomToken(tokenAddress) self.customTokenList.loadCustomTokens() for account in self.status.wallet.accounts: if account.address == self.currentAccount.address: @@ -699,12 +699,12 @@ QtObject: proc decodeTokenApproval*(self: WalletView, tokenAddress: string, data: string): string {.slot.} = let amount = data[74..len(data)-1] - let token = getToken(tokenAddress) - + let token = self.status.tokens.getToken(tokenAddress) + if(token != nil): - let amountDec = $hex2Token(amount, token.decimals) + let amountDec = $self.status.wallet.hex2Token(amount, token.decimals) return $(%* {"symbol": token.symbol, "amount": amountDec}) - + return """{"error":"Unknown token address"}"""; proc isFetchingHistory*(self: WalletView): bool {.slot.} = diff --git a/src/status/tokens.nim b/src/status/tokens.nim index cdd881a0a3..062aa6dc87 100644 --- a/src/status/tokens.nim +++ b/src/status/tokens.nim @@ -25,6 +25,9 @@ proc getSNTAddress*(): string = proc getCustomTokens*(self: TokensModel, useCached: bool = true): seq[Erc20Contract] = result = status_tokens.getCustomTokens(useCached) +proc removeCustomToken*(self: TokensModel, address: string) = + status_tokens.removeCustomToken(address) + proc getSNTBalance*(account: string): string = result = status_tokens.getSNTBalance(account) @@ -37,6 +40,13 @@ proc tokenName*(contract: Contract): string = proc tokensymbol*(contract: Contract): string = result = status_tokens.tokensymbol(contract) +proc getTokenBalance*(tokenAddress: string, account: string): string = + result = status_tokens.getTokenBalance(tokenAddress, account) + +proc getToken*(self: TokensModel, tokenAddress: string): Erc20Contract = + result = status_tokens.getToken(tokenAddress) + export newErc20Contract export getErc20Contracts export Erc20Contract +export getErc20ContractByAddress diff --git a/src/status/wallet.nim b/src/status/wallet.nim index 1cb8fb873f..4fa9903806 100644 --- a/src/status/wallet.nim +++ b/src/status/wallet.nim @@ -374,3 +374,12 @@ proc watchTransaction*(self: WalletModel, transactionHash: string): string = proc getPendingTransactions*(self: WalletModel): string = result = status_wallet.getPendingTransactions() + +proc getTransfersByAddress*(address: string): seq[types.Transaction] = + result = status_wallet.getTransfersByAddress(address) + +proc watchTransaction*(transactionHash: string): string = + result = status_wallet.watchTransaction(transactionHash) + +proc hex2Token*(self: WalletModel, input: string, decimals: int): string = + result = status_wallet.hex2Token(input, decimals)