2022-10-17 10:17:25 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import shared.stores 1.0
|
|
|
|
import "../../../app/AppLayouts/Profile/stores"
|
2023-04-18 16:05:24 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
2022-10-17 10:17:25 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2022-12-29 16:44:51 +00:00
|
|
|
property CurrenciesStore currencyStore: CurrenciesStore {}
|
2022-10-17 10:17:25 +00:00
|
|
|
property ProfileSectionStore profileSectionStore: ProfileSectionStore {}
|
|
|
|
property var contactStore: profileSectionStore.contactsStore
|
|
|
|
|
|
|
|
property var mainModuleInst: mainModule
|
|
|
|
property var walletSectionTransactionsInst: walletSectionTransactions
|
2023-04-20 08:41:45 +00:00
|
|
|
property var walletSectionSendInst: walletSectionSend
|
2022-10-17 10:17:25 +00:00
|
|
|
|
|
|
|
property string currentCurrency: walletSection.currentCurrency
|
|
|
|
property var allNetworks: networksModule.all
|
2023-04-25 16:54:50 +00:00
|
|
|
property var overview: walletSectionOverview
|
2023-04-20 08:41:45 +00:00
|
|
|
property var accounts: walletSectionSendInst.accounts
|
2023-05-04 12:55:39 +00:00
|
|
|
property var senderAccounts: walletSectionSendInst.senderAccounts
|
|
|
|
property var selectedSenderAccount: walletSectionSendInst.selectedSenderAccount
|
2022-10-17 10:17:25 +00:00
|
|
|
property string signingPhrase: walletSection.signingPhrase
|
2023-04-18 16:05:24 +00:00
|
|
|
property var savedAddressesModel: SortFilterProxyModel {
|
|
|
|
sourceModel: walletSectionSavedAddresses.model
|
|
|
|
filters: [
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "isTest"
|
|
|
|
value: networksModule.areTestNetworksEnabled
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
property var disabledChainIdsFromList: []
|
|
|
|
property var disabledChainIdsToList: []
|
|
|
|
|
|
|
|
function addRemoveDisabledFromChain(chainID, isDisabled) {
|
|
|
|
if(isDisabled) {
|
2022-12-09 09:10:05 +00:00
|
|
|
if(!root.disabledChainIdsFromList.includes(chainID))
|
|
|
|
disabledChainIdsFromList.push(chainID)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-11-23 17:58:22 +00:00
|
|
|
for(var i = 0; i < disabledChainIdsFromList.length;i++) {
|
|
|
|
if(disabledChainIdsFromList[i] === chainID) {
|
|
|
|
disabledChainIdsFromList.splice(i, 1)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addRemoveDisabledToChain(chainID, isDisabled) {
|
|
|
|
if(isDisabled) {
|
2022-12-09 09:10:05 +00:00
|
|
|
if(!root.disabledChainIdsToList.includes(chainID))
|
|
|
|
root.disabledChainIdsToList.push(chainID)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-11-23 17:58:22 +00:00
|
|
|
for(var i = 0; i < root.disabledChainIdsToList.length;i++) {
|
|
|
|
if(root.disabledChainIdsToList[i] === chainID) {
|
|
|
|
root.disabledChainIdsToList.splice(i, 1)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-08 15:56:02 +00:00
|
|
|
function getEtherscanLink(chainID) {
|
|
|
|
return networksModule.all.getBlockExplorerURL(chainID)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyToClipboard(text) {
|
|
|
|
globalUtils.copyToClipboard(text)
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:59:21 +00:00
|
|
|
function authenticateAndTransfer(from, to, tokenSymbol, amount, uuid, selectedRoutes) {
|
2023-04-20 08:41:45 +00:00
|
|
|
walletSectionSendInst.authenticateAndTransfer(from, to, tokenSymbol, amount, uuid, selectedRoutes)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function suggestedFees(chainId) {
|
2023-04-20 08:41:45 +00:00
|
|
|
return JSON.parse(walletSectionSendInst.suggestedFees(chainId))
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEstimatedTime(chainId, maxFeePerGas) {
|
2023-04-20 08:41:45 +00:00
|
|
|
return walletSectionSendInst.getEstimatedTime(chainId, maxFeePerGas)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getChainIdForChat() {
|
|
|
|
return walletSectionTransactions.getChainIdForChat()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChainIdForBrowser() {
|
|
|
|
return walletSectionTransactions.getChainIdForBrowser()
|
|
|
|
}
|
|
|
|
|
2022-11-25 09:13:02 +00:00
|
|
|
function suggestedRoutes(account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIds, sendType, lockedInAmounts) {
|
2023-04-20 08:41:45 +00:00
|
|
|
walletSectionSendInst.suggestedRoutes(account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIds, sendType, JSON.stringify(lockedInAmounts))
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hex2Eth(value) {
|
|
|
|
return globalUtils.hex2Eth(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchAccount(newIndex) {
|
|
|
|
if(Constants.isCppApp)
|
|
|
|
walletSectionAccounts.switchAccount(newIndex)
|
|
|
|
else
|
|
|
|
walletSection.switchAccount(newIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolveENS(value) {
|
|
|
|
mainModuleInst.resolveENS(value, "")
|
|
|
|
}
|
|
|
|
|
2022-11-15 11:22:03 +00:00
|
|
|
function getWei2Eth(wei, decimals) {
|
|
|
|
return globalUtils.wei2Eth(wei, decimals)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 11:22:03 +00:00
|
|
|
function getEth2Wei(eth, decimals) {
|
|
|
|
return globalUtils.eth2Wei(eth, decimals)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function plainText(text) {
|
|
|
|
return globalUtils.plainText(text)
|
|
|
|
}
|
2022-12-01 15:48:44 +00:00
|
|
|
|
2022-11-25 09:13:02 +00:00
|
|
|
function setDefaultPreferredDisabledChains() {
|
|
|
|
let mainnetChainId = getMainnetChainId()
|
|
|
|
preferredChainIds.push(mainnetChainId)
|
|
|
|
addUnpreferredChainsToDisabledChains()
|
|
|
|
}
|
2022-12-01 15:48:44 +00:00
|
|
|
|
2023-01-27 13:16:42 +00:00
|
|
|
function setAllNetworksAsPreferredChains() {
|
|
|
|
var preferredChains = []
|
|
|
|
for(var i = 0; i < allNetworks.count; i++) {
|
|
|
|
let chainId = allNetworks.rowData(i, "chainId") * 1
|
|
|
|
if(!preferredChainIds.includes(chainId)) {
|
|
|
|
preferredChainIds.push(chainId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 09:13:02 +00:00
|
|
|
function resetTxStoreProperties() {
|
|
|
|
disabledChainIdsFromList = []
|
|
|
|
disabledChainIdsToList = []
|
|
|
|
preferredChainIds = []
|
|
|
|
lockedInAmounts = []
|
2022-12-01 15:48:44 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 09:13:02 +00:00
|
|
|
property var preferredChainIds: []
|
|
|
|
|
2022-12-01 15:48:44 +00:00
|
|
|
function getMainnetChainId() {
|
|
|
|
return networksModule.getMainnetChainId()
|
|
|
|
}
|
|
|
|
|
2023-02-07 17:58:41 +00:00
|
|
|
// We should move all this over to nim
|
2022-11-25 09:13:02 +00:00
|
|
|
function addPreferredChains(preferredchains, showUnpreferredNetworks) {
|
2023-02-07 17:58:41 +00:00
|
|
|
let tempPreferredChains = preferredChainIds
|
2022-11-25 09:13:02 +00:00
|
|
|
for(const chain of preferredchains) {
|
2023-02-07 17:58:41 +00:00
|
|
|
if(!tempPreferredChains.includes(chain)) {
|
|
|
|
tempPreferredChains.push(chain)
|
2022-11-25 09:13:02 +00:00
|
|
|
// remove from disabled accounts as it was added as preferred
|
|
|
|
addRemoveDisabledToChain(chain, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// here we are trying to remove chains that are not preferred from the list and
|
|
|
|
// also disable them incase the showUnpreferredNetworks toggle is turned off
|
2023-02-07 17:58:41 +00:00
|
|
|
for(var i = 0; i < tempPreferredChains.length; i++) {
|
|
|
|
if(!preferredchains.includes(tempPreferredChains[i])) {
|
2022-11-25 09:13:02 +00:00
|
|
|
if(!showUnpreferredNetworks)
|
2023-02-07 17:58:41 +00:00
|
|
|
addRemoveDisabledToChain(tempPreferredChains[i], true)
|
|
|
|
tempPreferredChains.splice(i, 1)
|
2022-11-25 09:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-07 17:58:41 +00:00
|
|
|
|
|
|
|
preferredChainIds = tempPreferredChains
|
2022-11-25 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 15:48:44 +00:00
|
|
|
function addUnpreferredChainsToDisabledChains() {
|
|
|
|
for(var i = 0; i < allNetworks.count; i++) {
|
|
|
|
let chainId = allNetworks.rowData(i, "chainId") * 1
|
2022-11-25 09:13:02 +00:00
|
|
|
if(!preferredChainIds.includes(chainId)) {
|
2022-12-01 15:48:44 +00:00
|
|
|
addRemoveDisabledToChain(chainId, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-30 12:59:21 +00:00
|
|
|
|
2022-11-25 09:13:02 +00:00
|
|
|
function splitAndFormatAddressPrefix(text, isBridgeTx, showUnpreferredNetworks) {
|
|
|
|
let address = ""
|
|
|
|
let tempPreferredChains = []
|
|
|
|
let chainFound = false
|
|
|
|
let splitWords = plainText(text).split(':')
|
|
|
|
let editedText = ""
|
|
|
|
|
|
|
|
for(var i=0; i<splitWords.length; i++) {
|
|
|
|
const word = splitWords[i]
|
|
|
|
if(word.startsWith("0x")) {
|
|
|
|
address = word
|
|
|
|
editedText += word
|
|
|
|
} else {
|
|
|
|
let chainColor = allNetworks.getNetworkColor(word)
|
|
|
|
if(!!chainColor) {
|
|
|
|
chainFound = true
|
|
|
|
if(!isBridgeTx)
|
|
|
|
tempPreferredChains.push(allNetworks.getNetworkChainId(word))
|
|
|
|
editedText += `<span style='color: %1'>%2</span>`.arg(chainColor).arg(word)+':'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 13:16:42 +00:00
|
|
|
if(!isBridgeTx) {
|
|
|
|
if(!chainFound)
|
|
|
|
addPreferredChains([getMainnetChainId()], showUnpreferredNetworks)
|
|
|
|
else
|
|
|
|
addPreferredChains(tempPreferredChains, showUnpreferredNetworks)
|
|
|
|
}
|
2022-11-25 09:13:02 +00:00
|
|
|
|
|
|
|
editedText +="</a></p>"
|
|
|
|
return {
|
|
|
|
formattedText: editedText,
|
|
|
|
address: address
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:59:21 +00:00
|
|
|
enum EstimatedTime {
|
|
|
|
Unknown = 0,
|
|
|
|
LessThanOneMin,
|
|
|
|
LessThanThreeMins,
|
|
|
|
LessThanFiveMins,
|
|
|
|
MoreThanFiveMins
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLabelForEstimatedTxTime(estimatedFlag) {
|
|
|
|
switch(estimatedFlag) {
|
|
|
|
case TransactionStore.EstimatedTime.Unknown:
|
|
|
|
return qsTr("~ Unknown")
|
|
|
|
case TransactionStore.EstimatedTime.LessThanOneMin :
|
|
|
|
return qsTr("< 1 minute")
|
|
|
|
case TransactionStore.EstimatedTime.LessThanThreeMins :
|
|
|
|
return qsTr("< 3 minutes")
|
|
|
|
case TransactionStore.EstimatedTime.LessThanFiveMins:
|
|
|
|
return qsTr("< 5 minutes")
|
|
|
|
default:
|
|
|
|
return qsTr("> 5 minutes")
|
|
|
|
}
|
|
|
|
}
|
2022-11-25 09:13:02 +00:00
|
|
|
|
|
|
|
property var lockedInAmounts: []
|
|
|
|
|
|
|
|
function addLockedInAmount(chainID, value, decimals, locked) {
|
2023-01-08 22:23:51 +00:00
|
|
|
let amount = value * Math.pow(10, decimals)
|
2022-11-25 09:13:02 +00:00
|
|
|
let index = lockedInAmounts.findIndex(lockedItem => lockedItem !== undefined && lockedItem.chainID === chainID)
|
|
|
|
if(index === -1) {
|
|
|
|
lockedInAmounts.push({"chainID": chainID, "value": amount.toString(16)})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(locked) {
|
|
|
|
lockedInAmounts[index].value = amount.toString(16)
|
|
|
|
} else {
|
|
|
|
lockedInAmounts.splice(index,1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-29 16:44:51 +00:00
|
|
|
|
|
|
|
function getTokenBalanceOnChain(selectedAccount, chainId: int, tokenSymbol: string) {
|
|
|
|
if (!selectedAccount) {
|
|
|
|
console.warn("selectedAccount invalid")
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2023-04-20 08:41:45 +00:00
|
|
|
walletSectionSendInst.prepareTokenBalanceOnChain(selectedAccount.address, chainId, tokenSymbol)
|
|
|
|
return walletSectionSendInst.getPreparedTokenBalanceOnChain()
|
2022-12-29 16:44:51 +00:00
|
|
|
}
|
2023-04-06 12:59:24 +00:00
|
|
|
|
|
|
|
function findTokenSymbolByAddress(address) {
|
|
|
|
if (Global.appIsReady)
|
|
|
|
return walletSectionAllTokens.findTokenSymbolByAddress(address)
|
|
|
|
return ""
|
|
|
|
}
|
2023-04-07 10:34:01 +00:00
|
|
|
|
|
|
|
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 {}
|
|
|
|
}
|
2023-04-18 16:05:24 +00:00
|
|
|
|
|
|
|
function prepareTransactionsForAddress(address) {
|
|
|
|
walletSectionTransactions.prepareTransactionsForAddress(address)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTransactions() {
|
|
|
|
return walletSectionTransactions.getTransactions()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllNetworksSupportedString() {
|
|
|
|
let result = ""
|
|
|
|
for(var i = 0; i < allNetworks.count; i++) {
|
|
|
|
let shortName = allNetworks.rowData(i, "shortName")
|
|
|
|
result += shortName + ':'
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2023-04-24 18:35:34 +00:00
|
|
|
|
2023-05-04 12:55:39 +00:00
|
|
|
function switchSenderAccount(index) {
|
|
|
|
walletSectionSendInst.switchSenderAccount(index)
|
2023-04-24 18:35:34 +00:00
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|