status-desktop/ui/app/AppLayouts/Wallet/stores/RootStore.qml

288 lines
9.9 KiB
QML

pragma Singleton
import QtQuick 2.13
import utils 1.0
import SortFilterProxyModel 0.2
import StatusQ.Core.Theme 0.1
QtObject {
id: root
readonly property string defaultSelectedKeyUid: userProfile.keyUid
readonly property bool defaultSelectedKeyUidMigratedToKeycard: userProfile.isKeycardUser
property bool loggedInUserAuthenticated: false
property string backButtonName: ""
property var currentAccount: Constants.isCppApp ? walletSectionAccounts.currentAccount: walletSectionCurrent
property var accounts: walletSectionAccounts.model
property var generatedAccounts: walletSectionAccounts.generated
property var appSettings: localAppSettings
property var accountSensitiveSettings: localAccountSensitiveSettings
property bool hideSignPhraseModal: accountSensitiveSettings.hideSignPhraseModal
property var totalCurrencyBalance: walletSection.totalCurrencyBalance
property bool tokensLoading: walletSection.tokensLoading
property string signingPhrase: walletSection.signingPhrase
property string mnemonicBackedUp: walletSection.isMnemonicBackedUp
property var flatCollectibles: walletSectionCollectibles.model
property var currentCollectible: walletSectionCurrentCollectible
property var savedAddresses: SortFilterProxyModel {
sourceModel: walletSectionSavedAddresses.model
filters: [
ValueFilter {
roleName: "isTest"
value: networksModule.areTestNetworksEnabled
}
]
}
property QtObject _d: QtObject {
id: d
property var chainColors: ({})
function initChainColors(model) {
for (let i = 0; i < model.count; i++) {
chainColors[model.rowData(i, "shortName")] = model.rowData(i, "chainColor")
}
}
}
function colorForChainShortName(chainShortName) {
return d.chainColors[chainShortName]
}
// Used for new wallet account generation
property var generatedAccountsViewModel: walletSectionAccounts.generatedAccounts
property var derivedAddressesList: walletSectionAccounts.derivedAddresses
property var layer1Networks: networksModule.layer1
property var layer2Networks: networksModule.layer2
property var testNetworks: networksModule.test
property var enabledNetworks: networksModule.enabled
property var allNetworks: networksModule.all
onAllNetworksChanged: {
d.initChainColors(allNetworks)
}
property var layer1NetworksProxy: networksModule.layer1Proxy
property var layer2NetworksProxy: networksModule.layer2Proxy
property var cryptoRampServicesModel: walletSectionBuySellCrypto.model
// This should be exposed to the UI via "walletModule", WalletModule should use
// Accounts Service which keeps the info about that (isFirstTimeAccountLogin).
// Then in the View of WalletModule we may have either QtProperty or
// Q_INVOKABLE function (proc marked as slot) depends on logic/need.
// The only need for onboardingModel here is actually to check if an account
// has been just created or an old one.
//property bool firstTimeLogin: onboardingModel.isFirstTimeLogin
// example wallet model
property ListModel exampleWalletModel: ListModel {
ListElement {
name: "Status account"
address: "0xcfc9f08bbcbcb80760e8cb9a3c1232d19662fc6f"
balance: "12.00 USD"
color: "#7CDA00"
}
ListElement {
name: "Test account 1"
address: "0x2Ef1...E0Ba"
balance: "12.00 USD"
color: "#FA6565"
}
ListElement {
name: "Status account"
address: "0x2Ef1...E0Ba"
balance: "12.00 USD"
color: "#7CDA00"
}
}
property ListModel exampleAssetModel: ListModel {
ListElement {
name: "Ethereum"
symbol: "ETH"
balance: "3423 ETH"
address: "token-icons/eth"
currencyBalance: "123 USD"
}
}
property bool derivedAddressesLoading: walletSectionAccounts.derivedAddressesLoading
property string derivedAddressesError: walletSectionAccounts.derivedAddressesError
function setHideSignPhraseModal(value) {
localAccountSensitiveSettings.hideSignPhraseModal = value;
}
function getLatestBlockNumber() {
// TODO: Move to transaction root module and not wallet
// Not Refactored Yet
// return walletModel.getLatestBlockNumber()
}
function setInitialRange() {
// Not Refactored Yet
// walletModel.setInitialRange()
}
function switchAccount(newIndex) {
if(Constants.isCppApp)
walletSectionAccounts.switchAccount(newIndex)
else
walletSection.switchAccount(newIndex)
}
function switchAccountByAddress(address) {
walletSection.switchAccountByAddress(address)
}
function generateNewAccount(password, accountName, color, emoji, path, derivedFrom) {
return walletSectionAccounts.generateNewAccount(password, accountName, color, emoji, path, derivedFrom)
}
function addNewWalletAccountGeneratedFromKeycard(accountType, accountName, color, emoji) {
return walletSectionAccounts.addNewWalletAccountGeneratedFromKeycard(accountType, accountName, color, emoji)
}
function addAccountsFromPrivateKey(privateKey, password, accountName, color, emoji) {
return walletSectionAccounts.addAccountsFromPrivateKey(privateKey, password, accountName, color, emoji)
}
function addAccountsFromSeed(seedPhrase, password, accountName, color, emoji, path) {
return walletSectionAccounts.addAccountsFromSeed(seedPhrase, password, accountName, color, emoji, path)
}
function addWatchOnlyAccount(address, accountName,color, emoji) {
return walletSectionAccounts.addWatchOnlyAccount(address, accountName, color, emoji)
}
function deleteAccount(address) {
return walletSectionAccounts.deleteAccount(address)
}
function updateCurrentAccount(address, accountName, color, emoji) {
return walletSectionCurrent.update(address, accountName, color, emoji)
}
function updateCurrency(newCurrency) {
walletSection.updateCurrency(newCurrency)
}
function getQrCode(address) {
return globalUtils.qrCode(address)
}
function hex2Dec(value) {
return globalUtils.hex2Dec(value)
}
function getCollectionMaxValue(traitType, value, maxValue, collectionIndex) {
// Not Refactored Yet
// if(maxValue !== "")
// return parseInt(value) + qsTr(" of ") + maxValue;
// else
// return parseInt(value) + qsTr(" of ") +
// walletModelV2Inst.collectiblesView.collections.getCollectionTraitMaxValue(collectionIndex, traitType).toString();
}
function selectCollectible(address, tokenId) {
walletSectionCurrentCollectible.update(address, tokenId)
}
function getNameForSavedWalletAddress(address) {
return walletSectionSavedAddresses.getNameByAddress(address)
}
function createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens) {
return walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens)
}
function deleteSavedAddress(address, ens) {
return walletSectionSavedAddresses.deleteSavedAddress(address, ens)
}
function toggleNetwork(chainId) {
networksModule.toggleNetwork(chainId)
}
function copyToClipboard(text) {
globalUtils.copyToClipboard(text)
}
function getDerivedAddress(password, derivedFrom, path, hashPassword) {
walletSectionAccounts.getDerivedAddress(password, derivedFrom, path, hashPassword)
}
function getDerivedAddressList(password, derivedFrom, path, pageSize, pageNumber, hashPassword) {
walletSectionAccounts.getDerivedAddressList(password, derivedFrom, path, pageSize, pageNumber, hashPassword)
}
function getDerivedAddressData(index) {
return walletSectionAccounts.getDerivedAddressAtIndex(index)
}
function getDerivedAddressPathData(index) {
return walletSectionAccounts.getDerivedAddressPathAtIndex(index)
}
function getDerivedAddressHasActivityData(index) {
return walletSectionAccounts.getDerivedAddressHasActivityAtIndex(index)
}
function getDerivedAddressAlreadyCreatedData(index) {
return walletSectionAccounts.getDerivedAddressAlreadyCreatedAtIndex(index)
}
function getDerivedAddressListForMnemonic(mnemonic, path, pageSize , pageNumber) {
walletSectionAccounts.getDerivedAddressListForMnemonic(mnemonic, path, pageSize , pageNumber)
}
function getDerivedAddressForPrivateKey(privateKey) {
walletSectionAccounts.getDerivedAddressForPrivateKey(privateKey)
}
function resetDerivedAddressModel() {
walletSectionAccounts.resetDerivedAddressModel()
}
function validSeedPhrase(mnemonic) {
return walletSectionAccounts.validSeedPhrase(mnemonic)
}
function getNextSelectableDerivedAddressIndex() {
return walletSectionAccounts.getNextSelectableDerivedAddressIndex()
}
function authenticateUser() {
walletSectionAccounts.authenticateUser()
}
function loggedInUserUsesBiometricLogin() {
return userProfile.usingBiometricLogin
}
function loggedInUserIsKeycardUser() {
return userProfile.isKeycardUser
}
function createSharedKeycardModule() {
walletSectionAccounts.createSharedKeycardModule()
}
function destroySharedKeycarModule() {
walletSectionAccounts.destroySharedKeycarModule()
}
function authenticateUserAndDeriveAddressOnKeycardForPath(keyUid, derivationPath, searchForFirstAvailableAddress) {
walletSectionAccounts.authenticateUserAndDeriveAddressOnKeycardForPath(keyUid, derivationPath, searchForFirstAvailableAddress)
}
}