Skip to content

Commit

Permalink
Merge branch 'master' into cypress-playback-submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino authored Dec 2, 2024
2 parents e1e66fb + cd0e080 commit 46799c1
Show file tree
Hide file tree
Showing 62 changed files with 3,672 additions and 1,614 deletions.
9 changes: 9 additions & 0 deletions assets/icons/icon-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions assets/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,6 @@ a {
}

.row {
margin-left: 1px;
margin-right: 1px;
}

Expand Down Expand Up @@ -4294,4 +4293,4 @@ textarea::placeholder {
.mobileVote .pivx-button-outline {
margin-right:7px;
}
}
}
302 changes: 2 additions & 300 deletions index.template.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions locale/en/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ MN_BAD_IP = "The IP address is invalid!" # The IP address is invalid!
MN_BAD_PRIVKEY = "The private key is invalid" # The private key is invalid
MN_NOT_ENOUGH_COLLAT = "You need <b>{amount} more {ticker}</b> to create a Masternode!" # You need <b>{amount} more {ticker}</b> to create a Masternode!
MN_ENOUGH_BUT_NO_COLLAT = "You have enough balance for a Masternode, but no valid collateral UTXO of {amount} {ticker}" # You have enough balance for a Masternode, but no valid collateral UTXO of {amount} {ticker}
MN_UNLOCK_WALLET = "Please import your <b> COLLATERAL WALLET</b> first."
MN_COLLAT_NOT_SUITABLE = "This is not a suitable UTXO for a Masternode" # This is not a suitable UTXO for a Masternode
MN_CANT_CONNECT = "Unable to connect to RPC node!" # Unable to connect to RPC node!
CONTACTS_ENCRYPT_FIRST = "You need to hit \"{button}\" before you can use Contacts!" # You need to hit "{button}" before you can use Contacts!
Expand Down
1 change: 1 addition & 0 deletions locale/template/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ MN_BAD_IP = "The IP address is invalid!"
MN_BAD_PRIVKEY = "The private key is invalid"
MN_NOT_ENOUGH_COLLAT = "You need <b>{amount} more {ticker}</b> to create a Masternode!"
MN_ENOUGH_BUT_NO_COLLAT = "You have enough balance for a Masternode, but no valid collateral UTXO of {amount} {ticker}"
MN_UNLOCK_WALLET = "Please import your <b> COLLATERAL WALLET</b> first."
MN_COLLAT_NOT_SUITABLE = "This is not a suitable UTXO for a Masternode"
MN_CANT_CONNECT = "Unable to connect to RPC node!"
CONTACTS_ENCRYPT_FIRST = "You need to hit \"{button}\" before you can use Contacts!"
Expand Down
20 changes: 17 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"pivx-shield-rust-multicore": "^1.2.0-7",
"qr-scanner": "^1.4.2",
"qrcode-generator": "^1.4.4",
"uuid": "^10.0.0",
"vue": "^3.3.4",
"vue-router": "^4.2.4"
},
Expand Down
29 changes: 29 additions & 0 deletions scripts/__mocks__/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const ALERTS = new Proxy(
{},
{
get(_target, prop) {
// Return the proxy itself if trying to access ALERTS
if (prop === 'ALERTS') return translation;
// Return key in tests so they aren't affected by translation changes
return prop;
},
}
);

export const translation = ALERTS;

export const tr = (message, vars) => {
return (
message +
' ' +
vars
.map((v) => {
let varStr = '';
for (const key in v) {
varStr += key + ' ' + v[key];
}
return varStr;
})
.join(' ')
);
};
50 changes: 50 additions & 0 deletions scripts/composables/use_masternode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ref, watch, toRaw } from 'vue';
import { defineStore } from 'pinia';
import { Database } from '../database.js';
import { getEventEmitter } from '../event_bus.js';

export const useMasternode = defineStore('masternode', () => {
/**
* @type{import('vue').Ref<import('../masternode.js').default?>}
*/
const masternode = ref(null);
const localProposals = ref([]);
watch(
localProposals,
async () => {
const database = await Database.getInstance();
const account = await database.getAccount();
if (account) {
account.localProposals = toRaw(localProposals.value);
await database.updateAccount(account);
}
},
{
// We need deep reactivity to detect proposal changes e.g. proposalHeight update when it gets confirmed
deep: true,
}
);
const fetchProposalsFromDatabase = async () => {
const database = await Database.getInstance();
const account = await database.getAccount();
localProposals.value = account?.localProposals ?? [];
};

const fetchMasternodeFromDatabase = async () => {
const database = await Database.getInstance();
masternode.value = await database.getMasternode();
};

watch(masternode, async () => {
const database = await Database.getInstance();
await database.addMasternode(toRaw(masternode.value));
});

fetchProposalsFromDatabase().then(() => {});
fetchMasternodeFromDatabase().then(() => {});
getEventEmitter().on('toggle-network', () => {
fetchProposalsFromDatabase().then(() => {});
fetchMasternodeFromDatabase().then(() => {});
});
return { masternode, localProposals };
});
5 changes: 3 additions & 2 deletions scripts/composables/use_settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defineStore } from 'pinia';
import { getEventEmitter } from '../event_bus.js';
import { ref, watch } from 'vue';
import { watchIgnorable } from '@vueuse/core';
Expand All @@ -11,7 +12,7 @@ import {
} from '../settings.js';
import { cChainParams } from '../chain_params.js';

export function useSettings() {
export const useSettings = defineStore('settings', () => {
const advancedMode = ref(fAdvancedMode);
const displayDecimals = ref(0);
const autoLockWallet = ref(false);
Expand Down Expand Up @@ -59,4 +60,4 @@ export function useSettings() {
debug,
isTestnet,
};
}
});
14 changes: 14 additions & 0 deletions scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { cOracle } from '../prices.js';
import { ledgerSignTransaction } from '../ledger.js';
import { defineStore } from 'pinia';
import { lockableFunction } from '../lock.js';
import { blockCount as rawBlockCount } from '../global.js';
import { doms } from '../global.js';
import {
RECEIVE_TYPES,
Expand All @@ -30,6 +31,8 @@ export const useWallet = defineStore('wallet', () => {
const getKeyToExport = () => wallet.getKeyToExport();
const isEncrypted = ref(true);
const hasShield = ref(wallet.hasShield());
const getNewAddress = (nReceiving) => wallet.getNewAddress(nReceiving);
const blockCount = ref(0);

const setMasterKey = async ({ mk, extsk }) => {
await wallet.setMasterKey({ mk, extsk });
Expand Down Expand Up @@ -132,9 +135,12 @@ export const useWallet = defineStore('wallet', () => {
});

const isCreatingTransaction = () => createAndSendTransaction.isLocked();
const getMasternodeUTXOs = () => wallet.getMasternodeUTXOs();
const getPath = (script) => wallet.getPath(script);

getEventEmitter().on('toggle-network', async () => {
isEncrypted.value = await hasEncryptedWallet();
blockCount.value = rawBlockCount;
});

getEventEmitter().on('wallet-import', async () => {
Expand All @@ -153,6 +159,10 @@ export const useWallet = defineStore('wallet', () => {
price.value = cOracle.getCachedPrice(strCurrency);
});

getEventEmitter().on('new-block', () => {
blockCount.value = rawBlockCount;
});

return {
publicMode,
isImported,
Expand All @@ -167,6 +177,7 @@ export const useWallet = defineStore('wallet', () => {
isHardwareWallet,
checkDecryptPassword,
encrypt,
getNewAddress,
getNewChangeAddress,
wipePrivateData: () => {
wallet.wipePrivateData();
Expand All @@ -184,5 +195,8 @@ export const useWallet = defineStore('wallet', () => {
sync,
createAndSendTransaction,
coldBalance,
getMasternodeUTXOs,
getPath,
blockCount,
};
});
20 changes: 4 additions & 16 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ const needsToEncrypt = computed(() => {
}
});
const showTransferMenu = ref(false);
const { advancedMode, displayDecimals, autoLockWallet } = useSettings();
const { advancedMode, displayDecimals, autoLockWallet } = storeToRefs(
useSettings()
);
const showExportModal = ref(false);
const showEncryptModal = ref(false);
const keyToBackup = ref('');
Expand Down Expand Up @@ -186,20 +188,6 @@ async function restoreWallet(strReason) {
});
}
async function importWif(wif, extsk) {
const secret = await ParsedSecret.parse(wif);
if (secret.masterKey) {
await wallet.setMasterKey({ mk: secret.masterKey, extsk });
if (wallet.hasShield && !extsk) {
createAlert(
'warning',
'Could not decrypt sk even if password is correct, please contact a developer'
);
}
createAlert('success', ALERTS.WALLET_UNLOCKED, 1500);
}
}
/**
* Lock the wallet by deleting masterkey private data, after user confirmation
*/
Expand Down Expand Up @@ -993,7 +981,7 @@ defineExpose({
<RestoreWallet
:show="showRestoreWallet"
:reason="restoreWalletReason"
:wallet="wallet"
@close="showRestoreWallet = false"
@import="importWif"
/>
</template>
20 changes: 19 additions & 1 deletion scripts/dashboard/RestoreWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import Password from '../Password.vue';
import { ALERTS, translation } from '../i18n.js';
import { Database } from '../database.js';
import { decrypt } from '../aes-gcm';
import { ParsedSecret } from '../parsed_secret';
import { useAlerts } from '../composables/use_alerts.js';
const { createAlert } = useAlerts();
const props = defineProps({
show: Boolean,
reason: String,
wallet: Object,
});
const { show, reason } = toRefs(props);
const { show, reason, wallet } = toRefs(props);
const emit = defineEmits(['close', 'import']);
const password = ref('');
const passwordInput = ref(null);
Expand All @@ -24,12 +27,27 @@ watch(show, (show) => {
if (!show) password.value = '';
});
async function importWif(wif, extsk) {
const secret = await ParsedSecret.parse(wif);
if (secret.masterKey) {
await wallet.value.setMasterKey({ mk: secret.masterKey, extsk });
if (wallet.value.hasShield && !extsk) {
createAlert(
'warning',
'Could not decrypt sk even if password is correct, please contact a developer'
);
}
createAlert('success', ALERTS.WALLET_UNLOCKED, 1500);
}
}
async function submit() {
const db = await Database.getInstance();
const account = await db.getAccount();
const wif = await decrypt(account.encWif, password.value);
const extsk = await decrypt(account.encExtsk, password.value);
if (wif) {
await importWif(wif, extsk);
emit('import', wif, extsk);
} else {
createAlert('warning', ALERTS.INVALID_PASSWORD);
Expand Down
4 changes: 2 additions & 2 deletions scripts/dashboard/WalletButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import pAddressBook from '../../assets/icons/icon-address-book.svg';
import pGift from '../../assets/icons/icon-gift.svg';
import { useNetwork } from '../composables/use_network.js';
import { useWallet } from '../composables/use_wallet.js';
import { getBlockbookUrl } from '../utils.js';
const wallet = useWallet();
const network = useNetwork();
function getWalletUrl() {
const urlPart = wallet.isHD ? '/xpub/' : '/address/';
return network.explorerUrl + urlPart + wallet.getKeyToExport();
return getBlockbookUrl(network.explorerUrl, wallet.getKeyToExport());
}
</script>

Expand Down
Loading

0 comments on commit 46799c1

Please sign in to comment.