use new wallet api to receive wallet signals
This commit is contained in:
parent
65a0cfbcd3
commit
19d4279237
|
@ -17,6 +17,7 @@ QtObject:
|
|||
currentAccount*: AccountInfoView
|
||||
status*: Status
|
||||
isCurrentFlow*: bool
|
||||
isFirstTimeLogin*: bool
|
||||
|
||||
proc setup(self: OnboardingView) =
|
||||
self.QAbstractListModel.setup
|
||||
|
@ -125,3 +126,17 @@ QtObject:
|
|||
read = isCurrentFlow
|
||||
write = setCurrentFlow
|
||||
notify = currentFlowChanged
|
||||
|
||||
proc firstTimeLoginChanged*(self: OnboardingView, v: bool) {.signal.}
|
||||
|
||||
proc setFirstTimeLogin*(self: OnboardingView, v: bool) {.slot.} =
|
||||
if self.isFirstTimeLogin == v: return
|
||||
self.isFirstTimeLogin = v
|
||||
self.firstTimeLoginChanged(v)
|
||||
|
||||
proc `isFirstTimeLogin=`*(self: OnboardingView, v: bool) = self.setFirstTimeLogin(v)
|
||||
|
||||
QtProperty[bool] isFirstTimeLogin:
|
||||
read = isFirstTimeLogin
|
||||
write = setFirstTimeLogin
|
||||
notify = firstTimeLoginChanged
|
|
@ -10,6 +10,9 @@ import ../../status/[status, wallet]
|
|||
import ../../status/wallet/account as WalletTypes
|
||||
import ../../eventemitter
|
||||
|
||||
logScope:
|
||||
topics = "wallet-core"
|
||||
|
||||
type WalletController* = ref object
|
||||
status: Status
|
||||
view*: WalletView
|
||||
|
@ -58,10 +61,18 @@ proc init*(self: WalletController) =
|
|||
self.view.updateView()
|
||||
|
||||
# TODO: show notification
|
||||
|
||||
of "new-transfers":
|
||||
for acc in data.accounts:
|
||||
self.view.loadTransactionsForAccount(acc)
|
||||
self.view.initBalances(false)
|
||||
of "recent-history-fetching":
|
||||
self.view.setHistoryFetchState(data.accounts, true)
|
||||
of "recent-history-ready":
|
||||
self.view.setHistoryFetchState(data.accounts, false)
|
||||
self.view.initBalances(false)
|
||||
else:
|
||||
error "Unhandled wallet signal", eventType=data.eventType
|
||||
|
||||
# TODO: handle these data.eventType: history, reorg
|
||||
# see status-react/src/status_im/ethereum/subscriptions.cljs
|
||||
|
@ -72,6 +83,3 @@ proc init*(self: WalletController) =
|
|||
|
||||
proc checkPendingTransactions*(self: WalletController) =
|
||||
self.status.wallet.checkPendingTransactions() # TODO: consider doing this in a threadpool task
|
||||
|
||||
proc start*(self: WalletController) =
|
||||
status_wallet.startWallet(false)
|
||||
|
|
|
@ -136,17 +136,16 @@ const loadTransactionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
|||
arg = decode[LoadTransactionsTaskArg](argEncoded)
|
||||
output = %*{
|
||||
"address": arg.address,
|
||||
"history": getTransfersByAddress(arg.address, arg.blockNumber)
|
||||
"history": getTransfersByAddress(arg.address)
|
||||
}
|
||||
arg.finish(output)
|
||||
|
||||
proc loadTransactions[T](self: T, slot: string, address: string, blockNumber: string) =
|
||||
proc loadTransactions[T](self: T, slot: string, address: string) =
|
||||
let arg = LoadTransactionsTaskArg(
|
||||
tptr: cast[ByteAddress](loadTransactionsTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: slot,
|
||||
address: address,
|
||||
blockNumber: blockNumber
|
||||
address: address
|
||||
)
|
||||
self.status.tasks.threadpool.start(arg)
|
||||
|
||||
|
@ -514,11 +513,11 @@ QtObject:
|
|||
self.accounts.forceUpdate()
|
||||
self.setCurrentAssetList(self.currentAccount.account.assetList)
|
||||
|
||||
proc initBalances*(self: WalletView) =
|
||||
proc checkRecentHistory*(self:WalletView) {.slot.} =
|
||||
var addresses:seq[string] = @[]
|
||||
for acc in self.status.wallet.accounts:
|
||||
let accountAddress = acc.address
|
||||
let tokenList = acc.assetList.filter(proc(x:Asset): bool = x.address != "").map(proc(x: Asset): string = x.address)
|
||||
self.initBalances("getAccountBalanceSuccess", accountAddress, tokenList)
|
||||
addresses.add(acc.address)
|
||||
discard status_wallet.checkRecentHistory(addresses)
|
||||
|
||||
proc getAccountBalanceSuccess*(self: WalletView, jsonResponse: string) {.slot.} =
|
||||
let jsonObj = jsonResponse.parseJson()
|
||||
|
@ -526,6 +525,7 @@ QtObject:
|
|||
self.setTotalFiatBalance(self.status.wallet.getTotalFiatBalance())
|
||||
self.accounts.forceUpdate()
|
||||
self.currentAccountChanged()
|
||||
self.updateView()
|
||||
|
||||
|
||||
proc loadCollectiblesForAccount*(self: WalletView, address: string, currentCollectiblesList: seq[CollectibleList]) =
|
||||
|
@ -637,9 +637,6 @@ QtObject:
|
|||
QtProperty[QVariant] customTokenList:
|
||||
read = getCustomTokenList
|
||||
|
||||
|
||||
|
||||
|
||||
proc isKnownTokenContract*(self: WalletView, address: string): bool {.slot.} =
|
||||
return self.status.wallet.getKnownTokenContract(parseAddress(address)) != nil
|
||||
|
||||
|
@ -665,20 +662,26 @@ QtObject:
|
|||
return self.fetchingHistoryState[address]
|
||||
return true
|
||||
|
||||
|
||||
proc isHistoryFetched*(self: WalletView, address: string): bool {.slot.} =
|
||||
return self.currentTransactions.rowCount() > 0
|
||||
|
||||
proc loadingTrxHistoryChanged*(self: WalletView, isLoading: bool) {.signal.}
|
||||
|
||||
proc loadTransactionsForAccount*(self: WalletView, address: string) {.slot.} =
|
||||
var bn = "latest"
|
||||
if self.currentTransactions.rowCount() > 0:
|
||||
bn = self.currentTransactions.getLastTxBlockNumber()
|
||||
# spawn'ed function cannot have a 'var' parameter
|
||||
let blockNumber = bn
|
||||
self.loadingTrxHistoryChanged(true)
|
||||
self.loadTransactions("setTrxHistoryResult", address, bn)
|
||||
self.loadTransactions("setTrxHistoryResult", address)
|
||||
|
||||
proc getLatestTransactionHistory*(self: WalletView, accounts: seq[string]) =
|
||||
for acc in accounts:
|
||||
self.loadTransactionsForAccount(acc)
|
||||
|
||||
proc initBalances*(self: WalletView, loadTransactions: bool = true) =
|
||||
for acc in self.status.wallet.accounts:
|
||||
let accountAddress = acc.address
|
||||
let 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.loadTransactionsForAccount(accountAddress)
|
||||
|
||||
proc setTrxHistoryResult(self: WalletView, historyJSON: string) {.slot.} =
|
||||
let historyData = parseJson(historyJSON)
|
||||
|
@ -686,7 +689,7 @@ QtObject:
|
|||
let address = historyData["address"].getStr
|
||||
let index = self.accounts.getAccountindexByAddress(address)
|
||||
if index == -1: return
|
||||
self.accounts.getAccount(index).transactions.add(transactions)
|
||||
self.accounts.getAccount(index).transactions = transactions
|
||||
if address == self.currentAccount.address:
|
||||
self.setCurrentTransactions(
|
||||
self.accounts.getAccount(index).transactions)
|
||||
|
@ -727,3 +730,6 @@ QtObject:
|
|||
QtProperty[QVariant] dappBrowserAccount:
|
||||
read = getDappBrowserAccount
|
||||
notify = dappBrowserAccountChanged
|
||||
|
||||
proc setInitialRange*(self: WalletView) {.slot.} =
|
||||
discard status_wallet.setInitialBlocksRange()
|
||||
|
|
|
@ -148,7 +148,6 @@ proc mainProc() =
|
|||
browserController.init()
|
||||
|
||||
wallet.checkPendingTransactions()
|
||||
wallet.start()
|
||||
|
||||
engine.setRootContextProperty("loginModel", login.variant)
|
||||
engine.setRootContextProperty("onboardingModel", onboarding.variant)
|
||||
|
|
|
@ -47,8 +47,8 @@ proc getContactByID*(id: string): string =
|
|||
proc getBlockByNumber*(blockNumber: string): string =
|
||||
result = callPrivateRPC("eth_getBlockByNumber", %* [blockNumber, false])
|
||||
|
||||
proc getTransfersByAddress*(address: string, toBlock: string, limit: string): string =
|
||||
result = callPrivateRPC("wallet_getTransfersByAddress", %* [address, toBlock, limit])
|
||||
proc getTransfersByAddress*(address: string, limit: string, fetchMore: bool = false): string =
|
||||
result = callPrivateRPC("wallet_getTransfersByAddress", %* [address, newJNull(), limit, fetchMore])
|
||||
|
||||
proc signMessage*(rpcParams: string): string =
|
||||
return $status_go.signMessage(rpcParams)
|
||||
|
|
|
@ -33,12 +33,9 @@ proc getWalletAccounts*(): seq[WalletAccount] =
|
|||
proc getTransactionReceipt*(transactionHash: string): string =
|
||||
result = callPrivateRPC("eth_getTransactionReceipt", %* [transactionHash])
|
||||
|
||||
proc getTransfersByAddress*(address: string, blockNumber: string = "latest"): seq[types.Transaction] =
|
||||
proc getTransfersByAddress*(address: string): seq[types.Transaction] =
|
||||
try:
|
||||
let response = getBlockByNumber(blockNumber)
|
||||
let latestBlock = parseJson(response)["result"]
|
||||
|
||||
let transactionsResponse = getTransfersByAddress(address, latestBlock["number"].getStr, "0x14")
|
||||
let transactionsResponse = getTransfersByAddress(address, "0x14")
|
||||
let transactions = parseJson(transactionsResponse)["result"]
|
||||
var accountTransactions: seq[types.Transaction] = @[]
|
||||
|
||||
|
@ -59,11 +56,7 @@ proc getTransfersByAddress*(address: string, blockNumber: string = "latest"): se
|
|||
fromAddress: transaction["from"].getStr,
|
||||
to: transaction["to"].getStr
|
||||
))
|
||||
# if we feching more trxs, we should skip the first trx as its already saved in the
|
||||
# existing list
|
||||
if blockNumber == "latest":
|
||||
return accountTransactions
|
||||
return accountTransactions[1 .. ^1]
|
||||
return accountTransactions
|
||||
except:
|
||||
let msg = getCurrentExceptionMsg()
|
||||
error "Failed getting wallet account transactions", msg
|
||||
|
@ -122,3 +115,15 @@ proc getPendingOutboundTransactionsByAddress*(address: string): string =
|
|||
proc deletePendingTransaction*(transactionHash: string) =
|
||||
let payload = %* [transactionHash]
|
||||
discard callPrivateRPC("wallet_deletePendingTransaction", payload)
|
||||
|
||||
proc setInitialBlocksRange*(): string =
|
||||
let payload = %* []
|
||||
result = callPrivateRPC("wallet_setInitialBlocksRange", payload)
|
||||
|
||||
proc watchTransaction*(transactionHash: string): string =
|
||||
let payload = %* [transactionHash]
|
||||
result = callPrivateRPC("wallet_watchTransaction", payload)
|
||||
|
||||
proc checkRecentHistory*(addresses: seq[string]): string =
|
||||
let payload = %* [addresses]
|
||||
result = callPrivateRPC("wallet_checkRecentHistory", payload)
|
||||
|
|
|
@ -3,10 +3,11 @@ import types
|
|||
|
||||
proc fromEvent*(jsonSignal: JsonNode): Signal =
|
||||
var signal:WalletSignal = WalletSignal()
|
||||
if jsonSignal["event"].kind != JNull and jsonSignal["event"]{"blockNumber"}.kind != JNull:
|
||||
signal.content = $jsonSignal
|
||||
if jsonSignal["event"].kind != JNull:
|
||||
signal.eventType = jsonSignal["event"]["type"].getStr
|
||||
signal.blockNumber = jsonSignal["event"]["blockNumber"].getInt
|
||||
signal.erc20 = jsonSignal["event"]["erc20"].getBool
|
||||
signal.blockNumber = jsonSignal["event"]{"blockNumber"}.getInt
|
||||
signal.erc20 = jsonSignal["event"]{"erc20"}.getBool
|
||||
signal.accounts = @[]
|
||||
for account in jsonSignal["event"]["accounts"]:
|
||||
signal.accounts.add(account.getStr)
|
||||
|
|
|
@ -18,6 +18,22 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if(onboardingModel.firstTimeLogin){
|
||||
onboardingModel.firstTimeLogin = false
|
||||
walletModel.setInitialRange()
|
||||
}
|
||||
walletModel.checkRecentHistory()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: recentHistoryTimer
|
||||
interval: Constants.walletFetchRecentHistoryInterval
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: walletModel.checkRecentHistory()
|
||||
}
|
||||
|
||||
SeedPhraseBackupWarning { }
|
||||
|
||||
SplitView {
|
||||
|
|
|
@ -19,6 +19,8 @@ QtObject {
|
|||
readonly property int fetchRangeLast3Days: 259200
|
||||
readonly property int fetchRangeLast7Days: 604800
|
||||
|
||||
readonly property int walletFetchRecentHistoryInterval: 1200000 // 20 mins
|
||||
|
||||
readonly property int limitLongChatText: 500
|
||||
readonly property int limitLongChatTextCompactMode: 1000
|
||||
|
||||
|
|
|
@ -153,6 +153,7 @@ ModalPopup {
|
|||
importError.text += error
|
||||
return importError.open()
|
||||
}
|
||||
onboardingModel.firstTimeLogin = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8a370c1c41bfe953ee34f841593952c6391d771b
|
||||
Subproject commit fd49876a475d6366c1d915933048f1f916f78b70
|
Loading…
Reference in New Issue