Skip to content

Commit

Permalink
[Wallet] Simplify importWallet flow (#269)
Browse files Browse the repository at this point in the history
* Simplify importWallet flow

* Update translations
  • Loading branch information
panleone authored Nov 17, 2023
1 parent b7b11c0 commit 934f7aa
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 23 deletions.
2 changes: 2 additions & 0 deletions locale/de/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ APP_INSTALLED = "Anwendung installiert!" # App Installed!
CONFIRM_POPUP_DELETE_ACCOUNT = "Dies wird alle deine Daten löschen. Eingeschlossen Masternode, Kontakte und private Schlüssel!" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "Bist du wirklich sicher?" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/en/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ APP_INSTALLED = "App Installed!" # App Installed!
CONFIRM_POPUP_DELETE_ACCOUNT = "This will delete all your data, including masternodes contacts and private keys!" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "Are you sure?" # Are you sure?
WALLET_NOT_SYNCED = "Please try again when wallet finishes syncing!" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "Wallet successfully Locked!" # Wallet successfully Locked!
WALLET_UNLOCKED = "Wallet successfully Unlocked!" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/es-mx/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ PROMO_ALREADY_CREATED = "" # You've already created that code!
CONFIRM_POPUP_DELETE_ACCOUNT = "" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/fr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ PROMO_ALREADY_CREATED = "Vous avez déjà créé ce code !" # You've already cre
CONFIRM_POPUP_DELETE_ACCOUNT = "Cette opération supprimera toutes vos données, y compris les contacts des masternodes et les clés privées !" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "Êtes-vous sûr ?" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/it/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ PROMO_ALREADY_CREATED = "Hai già creato quel codice!" # You've already created
CONFIRM_POPUP_DELETE_ACCOUNT = "Questo cancellerà tutti i tuoi data, inclusi i masternode, i contatti e le chiavi private!" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "Sei sicuro?" # Are you sure?
WALLET_NOT_SYNCED = "Per favore, prova di nuovo quando il wallet a finito di sincronizzarsi!" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/nl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ APP_INSTALLED = "App geïnstalleerd!" # App Installed!
CONFIRM_POPUP_DELETE_ACCOUNT = "" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/ph/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ PROMO_ALREADY_CREATED = "" # You've already created that code!
CONFIRM_POPUP_DELETE_ACCOUNT = "" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/pt-br/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ FAILED_TO_IMPORT_HARDWARE = "<b> Falha para importar a carteira de hardware</b>"
CONFIRM_POPUP_DELETE_ACCOUNT = "Isso ira deletar toda a sua informação, incluindo masternodes, contatos e chaves privadas!" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "Você tem certerza?" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/pt-pt/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ FAILED_TO_IMPORT_HARDWARE = "<b>Falha ao importar a carteira de hardware</b>." #
CONFIRM_POPUP_DELETE_ACCOUNT = "Isso excluirá todos os seus dados, incluindo contatos de masternodes e chaves privadas!" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "Tens a certeza?" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
2 changes: 2 additions & 0 deletions locale/template/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ WALLET_HARDWARE_CONNECTION_LOST = "<b>Lost connection to {hardwareWallet} </b><b
WALLET_HARDWARE_BUSY = "<b>{hardwareWallet} is waiting</b><br>Please unlock your {hardwareWallet} or finish it's current prompt"
WALLET_HARDWARE_ERROR = "<b> {hardwareWallet} </b><br> {error}"
WALLET_NOT_SYNCED = "Please try again when wallet finishes syncing!"
WALLET_LOCKED = "Wallet successfully Locked!"
WALLET_UNLOCKED = "Wallet successfully Unlocked!"
CONFIRM_POPUP_VOTE = "Confirm Vote"
CONFIRM_POPUP_VOTE_HTML = "Are you sure? It takes 60 minutes to change vote"
CONFIRM_POPUP_TRANSACTION = "Confirm your transaction"
Expand Down
2 changes: 2 additions & 0 deletions locale/uwu/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ FAILED_TO_IMPORT_HARDWARE = "" # <b> Failed to import Hardware Wallet</b>.
CONFIRM_POPUP_DELETE_ACCOUNT = "" # This will delete all your data, including masternodes contacts and private keys!
CONFIRM_POPUP_DELETE_ACCOUNT_TITLE = "" # Are you sure?
WALLET_NOT_SYNCED = "" # Please try again when wallet finishes syncing!
WALLET_LOCKED = "" # Wallet successfully Locked!
WALLET_UNLOCKED = "" # Wallet successfully Unlocked!
24 changes: 9 additions & 15 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async function parseSecret(secret, password = '') {
}
/**
* Import a wallet, this function MUST be called only at start or when switching network
* @param {Object} o - Options
* @param {'legacy'|'hd'|'hardware'} o.type - type of import
* @param {string} o.secret
Expand Down Expand Up @@ -171,7 +172,6 @@ async function importWallet({ type, secret, password = '' }) {
key = await parseSecret(secret, password);
}
if (key) {
const isAlreadyLoaded = wallet.isLoaded();
wallet.setMasterKey(key);
isImported.value = true;
jdenticonValue.value = wallet.getAddress();
Expand All @@ -184,11 +184,8 @@ async function importWallet({ type, secret, password = '' }) {
if (needsToEncrypt.value) showEncryptModal.value = true;
isViewOnly.value = wallet.isViewOnly();
// Don't reload an already loaded wallet!
if (!isAlreadyLoaded) {
await mempool.loadFromDisk();
getNetwork().walletFullSync();
}
await mempool.loadFromDisk();
getNetwork().walletFullSync();
getEventEmitter().emit('wallet-import');
return true;
}
Expand Down Expand Up @@ -240,16 +237,12 @@ async function restoreWallet(strReason) {
domPassword.value = '';
const database = await Database.getInstance();
const { encWif } = await database.getAccount();
// Attempt to unlock the wallet with the provided password
if (
await importWallet({
type: 'hd',
secret: encWif,
password: strPassword,
})
) {
// Wallet is unlocked!
const key = await parseSecret(encWif, strPassword);
if (key) {
wallet.setMasterKey(key);
isViewOnly.value = wallet.isViewOnly();
createAlert('success', ALERTS.WALLET_UNLOCKED, 1500);
return true;
} else {
// Password is invalid
Expand Down Expand Up @@ -280,6 +273,7 @@ async function lockWallet() {
) {
wallet.wipePrivateData();
isViewOnly.value = wallet.isViewOnly();
createAlert('success', ALERTS.WALLET_LOCKED, 1500);
}
}
Expand Down
17 changes: 9 additions & 8 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,19 @@ export class Wallet {
* @param {import('./masterkey.js').MasterKey} mk - The new Master Key to set active
*/
setMasterKey(mk, nAccount = 0) {
if (
const isNewAcc =
mk?.getKeyToExport(nAccount) !==
this.#masterKey?.getKeyToExport(this.#nAccount)
)
this.reset();
this.#masterKey?.getKeyToExport(this.#nAccount);
this.#masterKey = mk;
this.#nAccount = nAccount;
// If this is the global wallet update the network master key
if (this.#isMainWallet) {
getNetwork().setWallet(this);
if (isNewAcc) {
this.reset();
// If this is the global wallet update the network master key
if (this.#isMainWallet) {
getNetwork().setWallet(this);
}
for (let i = 0; i < Wallet.chains; i++) this.loadAddresses(i);
}
for (let i = 0; i < Wallet.chains; i++) this.loadAddresses(i);
}

/**
Expand Down

0 comments on commit 934f7aa

Please sign in to comment.