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