fix(@desktop/wallet): Browser: can't do transactions in simpledapp

fixes #10192
This commit is contained in:
Khushboo Mehta 2023-04-07 12:34:01 +02:00 committed by Khushboo-dev-cpp
parent 23f493f251
commit 98a2328517
9 changed files with 52 additions and 99 deletions

View File

@ -1,6 +1,8 @@
import NimQml, Tables, strutils, strformat import NimQml, Tables, strutils, strformat
import ./item import ./item
import ../../../shared_models/currency_amount
import ../../../shared_models/token_model
type type
ModelRole {.pure.} = enum ModelRole {.pure.} = enum
@ -149,3 +151,9 @@ QtObject:
if(account.getAddress() == address): if(account.getAddress() == address):
return newQVariant(account.getAssets()) return newQVariant(account.getAssets())
return nil return nil
proc getTokenBalanceOnChain1*(self: Model, address: string, chainId: int, tokenSymbol: string): CurrencyAmount =
for account in self.items:
if(account.getAddress() == address):
return account.getAssets().getTokenBalanceOnChain(chainId, tokenSymbol)
return newCurrencyAmount()

View File

@ -30,6 +30,8 @@ QtObject:
watchOnlyVariant: QVariant watchOnlyVariant: QVariant
generatedAccountsVariant: QVariant generatedAccountsVariant: QVariant
tmpAddress: string tmpAddress: string
tmpChainID: int # shouldn't be used anywhere except in prepareCurrencyAmount/getPreparedCurrencyAmount procs
tmpSymbol: string # shouldn't be used anywhere except in prepareCurrencyAmount/getPreparedCurrencyAmount procs
proc delete*(self: View) = proc delete*(self: View) =
self.model.delete self.model.delete
@ -171,4 +173,22 @@ QtObject:
self.tmpAddress = address self.tmpAddress = address
proc getAccountAssetsByAddress*(self: View): QVariant {.slot.} = proc getAccountAssetsByAddress*(self: View): QVariant {.slot.} =
return self.model.getAccountAssetsByAddress(self.tmpAddress) self.tmpAddress = ""
return self.model.getAccountAssetsByAddress(self.tmpAddress)
# Returning a QVariant from a slot with parameters other than "self" won't compile
#proc getTokenBalanceOnChain*(self: View, chainId: int, tokenSymbol: string): QVariant {.slot.} =
# return newQVariant(self.assets.getTokenBalanceOnChain(chainId, tokenSymbol))
# As a workaround, we do it in two steps: First call prepareTokenBalanceOnChain, then getPreparedTokenBalanceOnChain
proc prepareTokenBalanceOnChain*(self: View, address: string, chainId: int, tokenSymbol: string) {.slot.} =
self.tmpAddress = address
self.tmpChainId = chainId
self.tmpSymbol = tokenSymbol
proc getPreparedTokenBalanceOnChain*(self: View): QVariant {.slot.} =
let currencyAmount = self.model.getTokenBalanceOnChain1(self.tmpAddress, self.tmpChainId, self.tmpSymbol)
self.tmpAddress = ""
self.tmpChainId = 0
self.tmpSymbol = "ERROR"
return newQVariant(currencyAmount)

View File

@ -64,7 +64,7 @@ StatusSectionLayout {
property Component sendTransactionModalComponent: SendModal { property Component sendTransactionModalComponent: SendModal {
anchors.centerIn: parent anchors.centerIn: parent
selectedAccount: WalletStore.dappBrowserAccount selectedAccount: WalletStore.dappBrowserAccount
preSelectedAsset: _internal.getEthAsset() preSelectedAsset: store.getAsset(WalletStore.dappBrowserAccount.assets, "ETH")
} }
property Component signMessageModalComponent: SignMessageModal {} property Component signMessageModalComponent: SignMessageModal {}
@ -142,22 +142,6 @@ StatusSectionLayout {
findBar.reset(); findBar.reset();
browserHeader.addressBar.text = Web3ProviderStore.obtainAddress(currentWebView.url) browserHeader.addressBar.text = Web3ProviderStore.obtainAddress(currentWebView.url)
} }
function getEthAsset() {
let assetsList = WalletStore.dappBrowserAccount.assets
for(var i=0; i< assetsList.count;i++) {
if("ETH" === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
} }
centerPanel: Rectangle { centerPanel: Rectangle {

View File

@ -120,21 +120,7 @@ Item {
sendType: Constants.SendType.ENSRelease sendType: Constants.SendType.ENSRelease
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress() preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0) preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)
preSelectedAsset: { preSelectedAsset: store.getAsset(releaseEnsModal.store.currentAccount.assets, "ETH")
let assetsList = releaseEnsModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
if("ETH" === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
sendTransaction: function() { sendTransaction: function() {
if(bestRoutes.length === 1) { if(bestRoutes.length === 1) {
let path = bestRoutes[0] let path = bestRoutes[0]

View File

@ -66,21 +66,7 @@ Item {
sendType: Constants.SendType.ENSSetPubKey sendType: Constants.SendType.ENSSetPubKey
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress() preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0) preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)
preSelectedAsset: { preSelectedAsset: store.getAsset(connectEnsModal.store.currentAccount.assets, "ETH")
let assetsList = connectEnsModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
if("ETH" === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
sendTransaction: function() { sendTransaction: function() {
if(bestRoutes.length === 1) { if(bestRoutes.length === 1) {
let path = bestRoutes[0] let path = bestRoutes[0]

View File

@ -50,23 +50,7 @@ Item {
sendType: Constants.SendType.ENSRegister sendType: Constants.SendType.ENSRegister
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress() preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(10) preDefinedAmountToSend: LocaleUtils.numberToLocaleString(10)
preSelectedAsset: { preSelectedAsset: store.getAsset(buyEnsModal.store.currentAccount.assets, JSON.parse(root.stickersStore.getStatusToken()).symbol)
let assetsList = buyEnsModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
let symbol = JSON.parse(root.stickersStore.getStatusToken()).symbol
if (symbol !== assetsList.rowData(i, "symbol"))
continue
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: JSON.parse(assetsList.rowData(i, "totalBalance")),
totalCurrencyBalance: JSON.parse(assetsList.rowData(i, "totalCurrencyBalance")),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
sendTransaction: function() { sendTransaction: function() {
if(bestRoutes.length === 1) { if(bestRoutes.length === 1) {
let path = bestRoutes[0] let path = bestRoutes[0]

View File

@ -157,22 +157,7 @@ Item {
sendType: Constants.SendType.StickersBuy sendType: Constants.SendType.StickersBuy
preSelectedRecipient: root.store.stickersStore.getStickersMarketAddress() preSelectedRecipient: root.store.stickersStore.getStickersMarketAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price)) preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price))
preSelectedAsset: { preSelectedAsset: store.getAsset(buyStickersModal.store.currentAccount.assets, JSON.parse(root.store.stickersStore.getStatusToken()).symbol)
let assetsList = buyStickersModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
let symbol = JSON.parse(root.store.stickersStore.getStatusToken()).symbol
if(symbol === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
sendTransaction: function() { sendTransaction: function() {
if(bestRoutes.length === 1) { if(bestRoutes.length === 1) {
let path = bestRoutes[0] let path = bestRoutes[0]

View File

@ -70,22 +70,7 @@ ModalPopup {
sendType: Constants.SendType.StickersBuy sendType: Constants.SendType.StickersBuy
preSelectedRecipient: stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress() preSelectedRecipient: stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price)) preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price))
preSelectedAsset: { preSelectedAsset: store.getAsset(buyStickersPackModal.store.currentAccount.assets, JSON.parse(stickerPackDetailsPopup.store.stickersStore.getStatusToken()).symbol)
let assetsList = buyStickersPackModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
let symbol = JSON.parse(stickerPackDetailsPopup.store.stickersStore.getStatusToken()).symbol
if(symbol === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
sendTransaction: function() { sendTransaction: function() {
if(bestRoutes.length === 1) { if(bestRoutes.length === 1) {
let path = bestRoutes[0] let path = bestRoutes[0]

View File

@ -256,8 +256,8 @@ QtObject {
return undefined return undefined
} }
selectedAccount.prepareTokenBalanceOnChain(chainId, tokenSymbol) walletSectionAccounts.prepareTokenBalanceOnChain(selectedAccount.address, chainId, tokenSymbol)
return selectedAccount.getPreparedTokenBalanceOnChain() return walletSectionAccounts.getPreparedTokenBalanceOnChain()
} }
function findTokenSymbolByAddress(address) { function findTokenSymbolByAddress(address) {
@ -265,4 +265,19 @@ QtObject {
return walletSectionAllTokens.findTokenSymbolByAddress(address) return walletSectionAllTokens.findTokenSymbolByAddress(address)
return "" return ""
} }
function getAsset(assetsList, symbol) {
for(var i=0; i< assetsList.count;i++) {
if(symbol === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: JSON.parse(assetsList.rowData(i, "totalBalance")),
totalCurrencyBalance: JSON.parse(assetsList.rowData(i, "totalCurrencyBalance")),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
}
} }