2023-05-10 11:05:45 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
2023-09-26 13:45:44 +00:00
|
|
|
import Models 1.0
|
|
|
|
import utils 1.0
|
2023-11-28 19:16:18 +00:00
|
|
|
import StatusQ 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2023-09-26 13:45:44 +00:00
|
|
|
import shared.stores 1.0
|
2023-11-28 19:16:18 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
import AppLayouts.Wallet.stores 1.0
|
2023-09-26 13:45:44 +00:00
|
|
|
|
2024-07-09 22:10:13 +00:00
|
|
|
// TODO: This store, as all other stores should be empty QtObject {}.
|
|
|
|
// All mocking should be done in place in Storybook pages and unit tests.
|
|
|
|
// If it's necessary to share mocks between tests/pages, such mock can be
|
|
|
|
// created by deriving from empty stub and putting in mocks dir.
|
|
|
|
// Stores itself should be simple, thin layers over functionality exposed from
|
|
|
|
// the backend. No additional logic should there. Data transformation logic
|
|
|
|
// should be delegated to adaptors, stateles helpers to proper utility singletons.
|
|
|
|
//
|
|
|
|
// PLEASE DO NOT ADD ANY NEW CONTENT HERE
|
|
|
|
|
2023-09-26 13:45:44 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2024-05-28 17:39:41 +00:00
|
|
|
readonly property CurrenciesStore currencyStore: CurrenciesStore {}
|
2024-07-05 12:49:31 +00:00
|
|
|
|
|
|
|
readonly property TokensStore tokensStore: TokensStore {}
|
2024-07-03 03:55:05 +00:00
|
|
|
|
|
|
|
readonly property var accounts: WalletSendAccountsModel {
|
2024-07-05 12:49:31 +00:00
|
|
|
Component.onCompleted: selectedSenderAccountAddress = accounts.get(0).address
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
2023-11-28 19:16:18 +00:00
|
|
|
|
|
|
|
property WalletAssetsStore walletAssetStore
|
|
|
|
|
2024-07-05 12:49:31 +00:00
|
|
|
property QtObject tmpActivityController0: QtObject {
|
|
|
|
property ListModel model: ListModel{}
|
|
|
|
}
|
|
|
|
property QtObject tmpActivityController1: QtObject {
|
2023-09-26 13:45:44 +00:00
|
|
|
property ListModel model: ListModel{}
|
|
|
|
}
|
|
|
|
|
2024-03-13 17:38:16 +00:00
|
|
|
property var flatNetworksModel: NetworksModel.flatNetworks
|
2024-07-03 08:51:15 +00:00
|
|
|
property var fromNetworksRouteModel: NetworksModel.sendFromNetworks
|
|
|
|
property var toNetworksRouteModel: NetworksModel.sendToNetworks
|
2024-07-05 12:49:31 +00:00
|
|
|
property string selectedSenderAccountAddress
|
2023-09-26 13:45:44 +00:00
|
|
|
|
|
|
|
readonly property QtObject walletSectionSendInst: QtObject {
|
|
|
|
signal transactionSent(var chainId, var txHash, var uuid, var error)
|
2024-07-19 03:36:36 +00:00
|
|
|
signal suggestedRoutesReady(var txRoutes, string errCode, string errDescription)
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
readonly property QtObject mainModuleInst: QtObject {
|
|
|
|
signal resolvedENS(var resolvedPubKey, var resolvedAddress, var uuid)
|
|
|
|
}
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
property string selectedAssetKey
|
2023-09-26 13:45:44 +00:00
|
|
|
property bool showUnPreferredChains: false
|
|
|
|
property int sendType: Constants.SendType.Transfer
|
|
|
|
property string selectedRecipient
|
|
|
|
|
|
|
|
readonly property var savedAddressesModel: ListModel {
|
|
|
|
Component.onCompleted: {
|
|
|
|
for (let i = 0; i < 10; i++)
|
|
|
|
append({
|
|
|
|
name: "some saved addr name " + i,
|
|
|
|
ens: [],
|
|
|
|
address: "0x2B748A02e06B159C7C3E98F5064577B96E55A7b4",
|
2024-05-16 16:37:54 +00:00
|
|
|
chainShortNames: "eth:arb1"
|
2023-09-26 13:45:44 +00:00
|
|
|
})
|
2024-07-05 12:49:31 +00:00
|
|
|
append({
|
|
|
|
name: "some saved ENS name ",
|
|
|
|
ens: ["me@status.eth"],
|
|
|
|
address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc4",
|
|
|
|
chainShortNames: "eth:arb1:opt"
|
|
|
|
})
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function splitAndFormatAddressPrefix(textAddrss, updateInStore) {
|
|
|
|
return textAddrss
|
|
|
|
}
|
|
|
|
|
2024-07-05 13:42:42 +00:00
|
|
|
function resolveENS(value: string) {
|
|
|
|
if (!!value && value.endsWith(".eth"))
|
|
|
|
root.mainModuleInst.resolvedENS("", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc4", "") // return some valid address
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAsset(assetsList, symbol) {
|
2023-11-28 19:16:18 +00:00
|
|
|
const idx = SQUtils.ModelUtils.indexOf(assetsList, "symbol", symbol)
|
2023-09-26 13:45:44 +00:00
|
|
|
if (idx < 0) {
|
|
|
|
return {}
|
|
|
|
}
|
2023-11-28 19:16:18 +00:00
|
|
|
return SQUtils.ModelUtils.get(assetsList, idx)
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
readonly property string currentCurrency: "USD"
|
|
|
|
|
|
|
|
function getAllNetworksSupportedString() {
|
|
|
|
return "OPT"
|
|
|
|
}
|
|
|
|
|
2024-07-05 12:49:31 +00:00
|
|
|
function plainText(htmlFragment) {
|
|
|
|
return SQUtils.StringUtils.plainText(htmlFragment)
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepareTransactionsForAddress(address) {
|
|
|
|
console.log("prepareTransactionsForAddress:", address)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTransactions() {
|
|
|
|
return transactions
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var transactions_: ListModel {
|
|
|
|
id: transactions
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
for (let i = 0; i < 10; i++)
|
|
|
|
append({
|
|
|
|
to: "to",
|
|
|
|
loadingTransaction: false,
|
|
|
|
value: {
|
|
|
|
displayDecimals: true,
|
|
|
|
stripTrailingZeroes: true,
|
|
|
|
amount: 3.234
|
|
|
|
},
|
|
|
|
timestamp: new Date()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-05 12:49:31 +00:00
|
|
|
function setSenderAccount(address) {
|
2024-07-03 03:55:05 +00:00
|
|
|
for (let i = 0; i < accounts.count; i++) {
|
|
|
|
const acc = accounts.get(i)
|
2024-07-05 12:49:31 +00:00
|
|
|
if (acc.address === address && acc.canSend) {
|
|
|
|
selectedSenderAccountAddress = acc.address
|
2024-06-07 12:27:56 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNetworkShortNames(chainIds) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
function getShortChainIds(chainIds) {
|
|
|
|
let listOfChains = chainIds.split(":")
|
|
|
|
let listOfChainIds = []
|
|
|
|
for (let k =0;k<listOfChains.length;k++) {
|
2024-06-12 20:43:08 +00:00
|
|
|
listOfChainIds.push(SQUtils.ModelUtils.getByKey(flatNetworksModel, "shortName", listOfChains[k], "chainId"))
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
return listOfChainIds
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSendType(sendType) {
|
|
|
|
root.sendType = sendType
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelectedRecipient(recipientAddress) {
|
|
|
|
root.selectedRecipient = recipientAddress
|
|
|
|
}
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
function setSelectedAssetKey(assetsKey) {
|
|
|
|
root.selectedAssetKey = assetsKey
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getWei2Eth(wei, decimals) {
|
|
|
|
return wei/(10**decimals)
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateRoutePreferredChains(chainIds) {
|
2024-07-03 08:51:15 +00:00
|
|
|
root.toNetworksRouteModel.updateRoutePreferredChains(chainIds)
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleShowUnPreferredChains() {
|
|
|
|
root.showUnPreferredChains = !root.showUnPreferredChains
|
|
|
|
}
|
|
|
|
|
2024-07-05 12:49:31 +00:00
|
|
|
function setAllNetworksAsRoutePreferredChains() {
|
|
|
|
}
|
|
|
|
|
2024-06-12 20:43:08 +00:00
|
|
|
function setRouteEnabledFromChains(chainId) {
|
|
|
|
}
|
|
|
|
|
2024-06-10 10:37:39 +00:00
|
|
|
function setSelectedTokenIsOwnerToken(isOwnerToken) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelectedTokenName(tokenName) {
|
|
|
|
}
|
|
|
|
|
2023-09-26 13:45:44 +00:00
|
|
|
property string amountToSend
|
|
|
|
property bool suggestedRoutesCalled: false
|
|
|
|
function suggestedRoutes(amount) {
|
|
|
|
root.amountToSend = amount
|
|
|
|
root.suggestedRoutesCalled = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetStoredProperties() {
|
|
|
|
root.amountToSend = ""
|
|
|
|
root.sendType = Constants.SendType.Transfer
|
|
|
|
root.selectedRecipient = ""
|
2024-02-05 16:44:49 +00:00
|
|
|
root.selectedAssetKey = ""
|
2023-09-26 13:45:44 +00:00
|
|
|
root.showUnPreferredChains = false
|
2024-07-03 08:51:15 +00:00
|
|
|
root.fromNetworksRouteModel.reset()
|
|
|
|
root.toNetworksRouteModel.reset()
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNetworkName(chainId) {
|
2024-06-12 20:43:08 +00:00
|
|
|
return SQUtils.ModelUtils.getByKey(flatNetworksModel, "chainId", chainId, "chainName")
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|
2023-11-28 19:16:18 +00:00
|
|
|
|
2024-06-12 20:43:08 +00:00
|
|
|
function formatCurrencyAmountFromBigInt(balance, symbol, decimals, options = null) {
|
|
|
|
return currencyStore.formatCurrencyAmountFromBigInt(balance, symbol, decimals, options)
|
2024-01-30 13:15:58 +00:00
|
|
|
}
|
2023-09-26 13:45:44 +00:00
|
|
|
}
|