Skip to content

Commit

Permalink
fix(@desktop/wallet): Browser: can't do transactions in simpledapp
Browse files Browse the repository at this point in the history
fixes #10192
  • Loading branch information
Khushboo-dev-cpp committed Apr 7, 2023
1 parent 23f493f commit 98a2328
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 99 deletions.
8 changes: 8 additions & 0 deletions src/app/modules/main/wallet_section/accounts/model.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import NimQml, Tables, strutils, strformat

import ./item
import ../../../shared_models/currency_amount
import ../../../shared_models/token_model

type
ModelRole {.pure.} = enum
Expand Down Expand Up @@ -149,3 +151,9 @@ QtObject:
if(account.getAddress() == address):
return newQVariant(account.getAssets())
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()
22 changes: 21 additions & 1 deletion src/app/modules/main/wallet_section/accounts/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ QtObject:
watchOnlyVariant: QVariant
generatedAccountsVariant: QVariant
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) =
self.model.delete
Expand Down Expand Up @@ -171,4 +173,22 @@ QtObject:
self.tmpAddress = address

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)
18 changes: 1 addition & 17 deletions ui/app/AppLayouts/Browser/BrowserLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ StatusSectionLayout {
property Component sendTransactionModalComponent: SendModal {
anchors.centerIn: parent
selectedAccount: WalletStore.dappBrowserAccount
preSelectedAsset: _internal.getEthAsset()
preSelectedAsset: store.getAsset(WalletStore.dappBrowserAccount.assets, "ETH")
}

property Component signMessageModalComponent: SignMessageModal {}
Expand Down Expand Up @@ -142,22 +142,6 @@ StatusSectionLayout {
findBar.reset();
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 {
Expand Down
16 changes: 1 addition & 15 deletions ui/app/AppLayouts/Profile/views/EnsDetailsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,7 @@ Item {
sendType: Constants.SendType.ENSRelease
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)
preSelectedAsset: {
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 {}
}
preSelectedAsset: store.getAsset(releaseEnsModal.store.currentAccount.assets, "ETH")
sendTransaction: function() {
if(bestRoutes.length === 1) {
let path = bestRoutes[0]
Expand Down
16 changes: 1 addition & 15 deletions ui/app/AppLayouts/Profile/views/EnsSearchView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,7 @@ Item {
sendType: Constants.SendType.ENSSetPubKey
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)
preSelectedAsset: {
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 {}
}
preSelectedAsset: store.getAsset(connectEnsModal.store.currentAccount.assets, "ETH")
sendTransaction: function() {
if(bestRoutes.length === 1) {
let path = bestRoutes[0]
Expand Down
18 changes: 1 addition & 17 deletions ui/app/AppLayouts/Profile/views/EnsTermsAndConditionsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,7 @@ Item {
sendType: Constants.SendType.ENSRegister
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(10)
preSelectedAsset: {
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 {}
}
preSelectedAsset: store.getAsset(buyEnsModal.store.currentAccount.assets, JSON.parse(root.stickersStore.getStatusToken()).symbol)
sendTransaction: function() {
if(bestRoutes.length === 1) {
let path = bestRoutes[0]
Expand Down
17 changes: 1 addition & 16 deletions ui/imports/shared/status/StatusStickerMarket.qml
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,7 @@ Item {
sendType: Constants.SendType.StickersBuy
preSelectedRecipient: root.store.stickersStore.getStickersMarketAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price))
preSelectedAsset: {
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 {}
}
preSelectedAsset: store.getAsset(buyStickersModal.store.currentAccount.assets, JSON.parse(root.store.stickersStore.getStatusToken()).symbol)
sendTransaction: function() {
if(bestRoutes.length === 1) {
let path = bestRoutes[0]
Expand Down
17 changes: 1 addition & 16 deletions ui/imports/shared/status/StatusStickerPackClickPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,7 @@ ModalPopup {
sendType: Constants.SendType.StickersBuy
preSelectedRecipient: stickerPackDetailsPopup.store.stickersStore.getStickersMarketAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(parseFloat(price))
preSelectedAsset: {
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 {}
}
preSelectedAsset: store.getAsset(buyStickersPackModal.store.currentAccount.assets, JSON.parse(stickerPackDetailsPopup.store.stickersStore.getStatusToken()).symbol)
sendTransaction: function() {
if(bestRoutes.length === 1) {
let path = bestRoutes[0]
Expand Down
19 changes: 17 additions & 2 deletions ui/imports/shared/stores/TransactionStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,28 @@ QtObject {
return undefined
}

selectedAccount.prepareTokenBalanceOnChain(chainId, tokenSymbol)
return selectedAccount.getPreparedTokenBalanceOnChain()
walletSectionAccounts.prepareTokenBalanceOnChain(selectedAccount.address, chainId, tokenSymbol)
return walletSectionAccounts.getPreparedTokenBalanceOnChain()
}

function findTokenSymbolByAddress(address) {
if (Global.appIsReady)
return walletSectionAllTokens.findTokenSymbolByAddress(address)
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 {}
}
}

0 comments on commit 98a2328

Please sign in to comment.