Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into shield_activity_f…
Browse files Browse the repository at this point in the history
…inal
  • Loading branch information
panleone committed Nov 7, 2024
2 parents da9d7bf + c035c75 commit 8567bd6
Show file tree
Hide file tree
Showing 16 changed files with 428 additions and 176 deletions.
2 changes: 1 addition & 1 deletion scripts/composables/use_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function useSettings() {
getEventEmitter().on('advanced-mode', (fAdvancedMode) => {
advancedMode.value = fAdvancedMode;
});
getEventEmitter().on('balance-update', async () => {
getEventEmitter().on('price-update', async () => {
displayDecimals.value = nDisplayDecimals;
});
getEventEmitter().on('auto-lock-wallet', (fAutoLockWallet) => {
Expand Down
4 changes: 3 additions & 1 deletion scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ export const useWallet = defineStore('wallet', () => {
getEventEmitter().on('balance-update', async () => {
balance.value = wallet.balance;
immatureBalance.value = wallet.immatureBalance;
currency.value = strCurrency.toUpperCase();
shieldBalance.value = await wallet.getShieldBalance();
pendingShieldBalance.value = await wallet.getPendingShieldBalance();
coldBalance.value = wallet.coldBalance;
});
getEventEmitter().on('price-update', async () => {
currency.value = strCurrency.toUpperCase();
price.value = cOracle.getCachedPrice(strCurrency);
});

Expand Down
43 changes: 22 additions & 21 deletions scripts/dashboard/Activity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getEventEmitter } from '../event_bus';
import iCheck from '../../assets/icons/icon-check.svg';
import iHourglass from '../../assets/icons/icon-hourglass.svg';
import { blockCount } from '../global.js';
const props = defineProps({
title: String,
Expand Down Expand Up @@ -117,47 +118,40 @@ async function update(txToAdd = 0) {
// If there are less than 10 txs loaded, append rather than update the list
if (txCount < 10 && txToAdd == 0) txToAdd = 10;
let found = 0;
// Since ECMAScript 2019 .sort is stable.
// https://caniuse.com/mdn-javascript_builtins_array_sort_stable
const orderedTxs = Array.from(wallet.getTransactions()).sort(
(a, b) => a.blockHeight - b.blockHeight
);
const historicalTxs = wallet.getHistoricalTxs();
// For Rewards: aggregate the total amount
if (props.rewards) {
for (const tx of orderedTxs) {
for (const tx of historicalTxs) {
// If this Tx Height is under our last scanned height, we stop
if (tx.blockHeight <= nRewardUpdateHeight) break;
// Only compute rewards
if (!tx.isCoinStake()) continue;
if (tx.type != HistoricalTxType.STAKE) continue;
// Aggregate the total rewards
rewardAmount.value += (
await wallet.toHistoricalTXs([tx])
)[0].amount;
rewardAmount.value += tx.amount;
}
// Keep track of the scan block height
if (orderedTxs.length) {
nRewardUpdateHeight = orderedTxs[0].blockHeight;
if (historicalTxs.length) {
nRewardUpdateHeight = historicalTxs[0].blockHeight;
}
}
// Prepare the Tx History list
let i = 0;
let found = 0;
while (found < txCount + txToAdd) {
if (orderedTxs.length == 0) {
if (i === historicalTxs.length) {
isHistorySynced.value = true;
break;
}
const tx = orderedTxs.pop();
if (props.rewards && !tx.isCoinStake()) continue;
const tx = historicalTxs[i];
i += 1;
if (props.rewards && tx.type != HistoricalTxType.STAKE) continue;
newTxs.push(tx);
found++;
}
// Convert to MPW's Activity format and render it
const arrTXs = await wallet.toHistoricalTXs(newTxs);
await parseTXs(arrTXs);
txCount = found;
await parseTXs(newTxs);
updating.value = false;
}
Expand Down Expand Up @@ -215,6 +209,13 @@ async function parseTXs(arrTXs) {
let amountToShow = Math.abs(cTx.amount + cTx.shieldAmount);
// Coinbase Transactions (rewards) require coinbaseMaturity confs
const fConfirmed =
blockCount - cTx.blockHeight >=
(cTx.type === HistoricalTxType.STAKE
? cChainParams.current.coinbaseMaturity
: 6);
// Take the icon, colour and content based on the type of the transaction
let { icon, colour, content } = txMap.value[cTx.type];
const match = content.match(/{(.)}/);
Expand Down Expand Up @@ -277,7 +278,7 @@ async function parseTXs(arrTXs) {
content: props.rewards ? cTx.id : content,
formattedAmt,
amount: amountToShow,
confirmed: cTx.isConfirmed,
confirmed: fConfirmed,
icon,
colour,
});
Expand Down
1 change: 0 additions & 1 deletion scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,6 @@ defineExpose({
:publicMode="wallet.publicMode"
:price="price"
:currency="currency"
:shieldEnabled="hasShield"
v-model:amount="transferAmount"
:desc="transferDescription"
v-model:address="transferAddress"
Expand Down
15 changes: 9 additions & 6 deletions scripts/dashboard/TransferMenu.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script setup>
import { translation } from '../i18n.js';
import { ref, watch, computed } from 'vue';
import { ref, watch } from 'vue';
import { getAddressColor } from '../contacts-book';
import { promptForContact } from '../contacts-book';
import { sanitizeHTML } from '../misc';
import { useWallet } from '../composables/use_wallet.js';
import BottomPopup from '../BottomPopup.vue';
import qrIcon from '../../assets/icons/icon-qr-code.svg';
import addressbookIcon from '../../assets/icons/icon-address-book.svg';
Expand All @@ -21,16 +20,13 @@ const emit = defineEmits([
const amountCurrency = ref('');
const color = ref('');
const wallet = useWallet();
const props = defineProps({
show: Boolean,
price: Number,
currency: String,
amount: String,
desc: String,
address: String,
shieldEnabled: Boolean,
publicMode: Boolean,
});
Expand All @@ -40,6 +36,13 @@ watch(address, (value) =>
getAddressColor(value).then((c) => (color.value = `${c} !important`))
);
watch(
() => props.price,
() => {
syncAmountCurrency();
}
);
const amount = defineModel('amount', {
set(value) {
return value.toString();
Expand All @@ -56,7 +59,7 @@ function send() {
'send',
sanitizeHTML(address.value),
amount.value,
!wallet.publicMode
!props.publicMode
);
}
Expand Down
24 changes: 12 additions & 12 deletions scripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export async function start() {

async function refreshPriceDisplay() {
await cOracle.getPrice(strCurrency);
getEventEmitter().emit('balance-update');
getEventEmitter().emit('price-update');
}

function subscribeToNetworkEvents() {
Expand Down Expand Up @@ -777,19 +777,19 @@ export async function updateGovernanceTab() {

// Update governance counter when testnet/mainnet has been switched
if (!governanceFlipdown && blockCount > 0) {
Masternode.getNextSuperblock().then((nSuperblock) => {
// The estimated time to the superblock (using the block target and remaining blocks)
const nTimestamp =
Date.now() / 1000 + (nSuperblock - blockCount) * 60;
governanceFlipdown = new FlipDown(nTimestamp).start();
});
getNetwork()
.getNextSuperblock()
.then((nSuperblock) => {
// The estimated time to the superblock (using the block target and remaining blocks)
const nTimestamp =
Date.now() / 1000 + (nSuperblock - blockCount) * 60;
governanceFlipdown = new FlipDown(nTimestamp).start();
});
isTestnetLastState = cChainParams.current.isTestnet;
}

// Fetch all proposals from the network
const arrProposals = await Masternode.getProposals({
fAllowFinished: false,
});
const arrProposals = await getNetwork().getProposals();

/* Sort proposals into two categories
- Standard (Proposal is either new with <100 votes, or has a healthy vote count)
Expand Down Expand Up @@ -979,7 +979,7 @@ async function renderProposals(arrProposals, fContested) {
);

// Fetch the Masternode count for proposal status calculations
const cMasternodes = await Masternode.getMasternodeCount();
const cMasternodes = await getNetwork().getMasternodeCount();

let totalAllocatedAmount = 0;

Expand Down Expand Up @@ -1654,7 +1654,7 @@ export async function createProposal() {
const strAddress =
document.getElementById('proposalAddress').value.trim() ||
wallet.getNewAddress(1)[0];
const nextSuperblock = await Masternode.getNextSuperblock();
const nextSuperblock = await getNetwork().getNextSuperblock();
const proposal = {
name: strTitle,
url: strUrl,
Expand Down
8 changes: 5 additions & 3 deletions scripts/historical_tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ export class HistoricalTx {
* @param {Array<string>} shieldReceivers - The list of decrypted 'shield output addresses'.
* @param {number} time - The block time of the transaction.
* @param {number} blockHeight - The block height of the transaction.
<<<<<<< HEAD
* @param {number} amount - The transparent amount transacted, in coins.
* @param {number} shieldAmount - The shielded amount transacted, in coins.
* @param {boolean} isToSelf - If the transaction is to self.
* @param {boolean} isConfirmed - Whether the transaction has been confirmed.
=======
* @param {number} amount - The amount transacted, in coins.
>>>>>>> upstream/master
*/
constructor(
type,
Expand All @@ -23,8 +27,7 @@ export class HistoricalTx {
blockHeight,
amount,
shieldAmount,
isToSelf,
isConfirmed
isToSelf
) {
this.type = type;
this.id = id;
Expand All @@ -35,7 +38,6 @@ export class HistoricalTx {
this.amount = amount;
this.shieldAmount = shieldAmount;
this.isToSelf = isToSelf;
this.isConfirmed = isConfirmed;
}
}

Expand Down
Loading

0 comments on commit 8567bd6

Please sign in to comment.