fix(wallet): fix loading of initial balances
This commit is contained in:
parent
eb726a315c
commit
b720a611c4
|
@ -101,14 +101,27 @@ QtObject:
|
||||||
if loadTransactions:
|
if loadTransactions:
|
||||||
self.historyView.loadTransactionsForAccount(accountAddress)
|
self.historyView.loadTransactionsForAccount(accountAddress)
|
||||||
|
|
||||||
|
proc initBalance(self: BalanceView, acc: WalletAccount, loadTransactions: bool = true) =
|
||||||
|
let
|
||||||
|
accountAddress = acc.address
|
||||||
|
tokenList = acc.assetList.filter(proc(x:Asset): bool = x.address != "").map(proc(x: Asset): string = x.address)
|
||||||
|
self.initBalances("getAccountBalanceSuccess", accountAddress, tokenList)
|
||||||
|
if loadTransactions:
|
||||||
|
self.historyView.loadTransactionsForAccount(accountAddress)
|
||||||
|
|
||||||
proc initBalance*(self: BalanceView, accountAddress: string, loadTransactions: bool = true) =
|
proc initBalance*(self: BalanceView, accountAddress: string, loadTransactions: bool = true) =
|
||||||
echo "initBalance"
|
var found = false
|
||||||
#var found = false
|
var acc: WalletAccount
|
||||||
#let acc = self.status.wallet.accounts.find(acc => acc.address.toLowerAscii == accountAddress.toLowerAscii, found)
|
for a in self.status.wallet.accounts:
|
||||||
#if not found:
|
if a.address.toLowerAscii == accountAddress.toLowerAscii:
|
||||||
# error "Failed to init balance: could not find account", account=accountAddress
|
found = true
|
||||||
# return
|
acc = a
|
||||||
#self.initBalance(acc, loadTransactions)
|
break
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
error "Failed to init balance: could not find account", account=accountAddress
|
||||||
|
return
|
||||||
|
self.initBalance(acc, loadTransactions)
|
||||||
|
|
||||||
proc getAccountBalanceSuccess*(self: BalanceView, jsonResponse: string) {.slot.} =
|
proc getAccountBalanceSuccess*(self: BalanceView, jsonResponse: string) {.slot.} =
|
||||||
let jsonObj = jsonResponse.parseJson()
|
let jsonObj = jsonResponse.parseJson()
|
||||||
|
|
|
@ -33,8 +33,11 @@ proc loadTransactions*[T](self: T, slot: string, address: string, toBlock: Uint2
|
||||||
let arg = LoadTransactionsTaskArg(
|
let arg = LoadTransactionsTaskArg(
|
||||||
tptr: cast[ByteAddress](loadTransactionsTask),
|
tptr: cast[ByteAddress](loadTransactionsTask),
|
||||||
vptr: cast[ByteAddress](self.vptr),
|
vptr: cast[ByteAddress](self.vptr),
|
||||||
slot: slot, address: address,
|
slot: slot,
|
||||||
toBlock: toBlock, limit: limit, loadMore: loadMore
|
address: address,
|
||||||
|
toBlock: toBlock,
|
||||||
|
limit: limit,
|
||||||
|
loadMore: loadMore
|
||||||
)
|
)
|
||||||
self.status.tasks.threadpool.start(arg)
|
self.status.tasks.threadpool.start(arg)
|
||||||
|
|
||||||
|
@ -58,10 +61,12 @@ QtObject:
|
||||||
|
|
||||||
proc historyWasFetched*(self: HistoryView) {.signal.}
|
proc historyWasFetched*(self: HistoryView) {.signal.}
|
||||||
|
|
||||||
|
proc loadingTrxHistoryChanged*(self: HistoryView, isLoading: bool, address: string) {.signal.}
|
||||||
|
|
||||||
proc setHistoryFetchState*(self: HistoryView, accounts: seq[string], isFetching: bool) =
|
proc setHistoryFetchState*(self: HistoryView, accounts: seq[string], isFetching: bool) =
|
||||||
for acc in accounts:
|
for acc in accounts:
|
||||||
self.fetchingHistoryState[acc] = isFetching
|
self.fetchingHistoryState[acc] = isFetching
|
||||||
if not isFetching: self.historyWasFetched()
|
self.loadingTrxHistoryChanged(isFetching, acc)
|
||||||
|
|
||||||
proc isFetchingHistory*(self: HistoryView, address: string): bool {.slot.} =
|
proc isFetchingHistory*(self: HistoryView, address: string): bool {.slot.} =
|
||||||
if self.fetchingHistoryState.hasKey(address):
|
if self.fetchingHistoryState.hasKey(address):
|
||||||
|
@ -71,8 +76,6 @@ QtObject:
|
||||||
proc isHistoryFetched*(self: HistoryView, address: string): bool {.slot.} =
|
proc isHistoryFetched*(self: HistoryView, address: string): bool {.slot.} =
|
||||||
return self.transactionsView.currentTransactions.rowCount() > 0
|
return self.transactionsView.currentTransactions.rowCount() > 0
|
||||||
|
|
||||||
proc loadingTrxHistoryChanged*(self: HistoryView, isLoading: bool, address: string) {.signal.}
|
|
||||||
|
|
||||||
proc loadTransactionsForAccount*(self: HistoryView, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) {.slot.} =
|
proc loadTransactionsForAccount*(self: HistoryView, address: string, toBlock: string = "0x0", limit: int = 20, loadMore: bool = false) {.slot.} =
|
||||||
self.loadingTrxHistoryChanged(true, address)
|
self.loadingTrxHistoryChanged(true, address)
|
||||||
let toBlockParsed = stint.fromHex(Uint256, toBlock)
|
let toBlockParsed = stint.fromHex(Uint256, toBlock)
|
||||||
|
|
|
@ -340,7 +340,7 @@ proc addCustomToken*(self: WalletModel, symbol: string, enable: bool, address: s
|
||||||
addCustomToken(address, name, symbol, decimals, color)
|
addCustomToken(address, name, symbol, decimals, color)
|
||||||
|
|
||||||
proc getTransfersByAddress*(self: WalletModel, address: string, toBlock: Uint256, limit: int, loadMore: bool): seq[Transaction] =
|
proc getTransfersByAddress*(self: WalletModel, address: string, toBlock: Uint256, limit: int, loadMore: bool): seq[Transaction] =
|
||||||
result = status_wallet.getTransfersByAddress(address, toBlock, limit, loadMore)
|
result = status_wallet.getTransfersByAddress(address, toBlock, limit, loadMore)
|
||||||
|
|
||||||
proc validateMnemonic*(self: WalletModel, mnemonic: string): string =
|
proc validateMnemonic*(self: WalletModel, mnemonic: string): string =
|
||||||
result = status_wallet.validateMnemonic(mnemonic).parseJSON()["error"].getStr
|
result = status_wallet.validateMnemonic(mnemonic).parseJSON()["error"].getStr
|
||||||
|
|
|
@ -11,19 +11,19 @@ import "../../../shared/status"
|
||||||
Item {
|
Item {
|
||||||
property int pageSize: 20 // number of transactions per page
|
property int pageSize: 20 // number of transactions per page
|
||||||
property var tokens: {
|
property var tokens: {
|
||||||
const count = walletModel.tokensView.defaultTokenList.rowCount()
|
let count = walletModel.tokensView.defaultTokenList.rowCount()
|
||||||
const toks = []
|
const toks = []
|
||||||
for (var i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
toks.push({
|
toks.push({
|
||||||
"address": walletModel.tokensView.defaultTokenList.rowData(i, 'address'),
|
"address": walletModel.tokensView.defaultTokenList.rowData(i, 'address'),
|
||||||
"symbol": walletModel.tokensView.defaultTokenList.rowData(i, 'symbol')
|
"symbol": walletModel.tokensView.defaultTokenList.rowData(i, 'symbol')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
count = walletModel.customTokenList.rowCount()
|
count = walletModel.tokensView.customTokenList.rowCount()
|
||||||
for (var i = 0; i < count; i++) {
|
for (let j = 0; j < count; j++) {
|
||||||
toks.push({
|
toks.push({
|
||||||
"address": walletModel.customTokenList.rowData(i, 'address'),
|
"address": walletModel.customTokenList.rowData(j, 'address'),
|
||||||
"symbol": walletModel.customTokenList.rowData(i, 'symbol')
|
"symbol": walletModel.customTokenList.rowData(j, 'symbol')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return toks
|
return toks
|
||||||
|
|
Loading…
Reference in New Issue