Skip to content

Commit

Permalink
Release hotfix to main (#1420)
Browse files Browse the repository at this point in the history
* update polkadot chain icon (#1415)

* Inflation chart fix (#1417)

* Inflation chart fix

* Current inflation calculation and cleanup

* Minor bug fixes

* Division by zero fix

* Enable governance section for Astar (#1418)

* docs: update zh translation from #1385 (#1413)

* docs: update zh translation

* fix format issue

* remove useless import

---------

Co-authored-by: coin98team002 <[email protected]>

* Enable governance section on Astar

---------

Co-authored-by: Taegeon Alan Go <[email protected]>
Co-authored-by: coin98team002 <[email protected]>

* Transferable balance fix (#1423)

* Transferable balance fix

* Existential deposit

* Referendum state fix (#1424)

---------

Co-authored-by: Taegeon Alan Go <[email protected]>
Co-authored-by: coin98team002 <[email protected]>
Co-authored-by: Saša Pul <[email protected]>
  • Loading branch information
4 people authored Dec 2, 2024
1 parent 1cfc88a commit 14b3b96
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 173 deletions.
Binary file modified src/assets/img/chain/polkadot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 37 additions & 1 deletion src/components/assets/NativeAssetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</div>
<div v-if="!isSkeleton" class="column--balance">
<div class="column--amount text--amount">
{{ $n(truncate(lockInDappStaking + vestingTtl + reservedTtl, 3)) }}
{{ $n(truncate(lockedAmount, 3)) }}
</div>
<div class="column--symbol text--symbol">
{{ nativeTokenSymbol }}
Expand Down Expand Up @@ -252,6 +252,28 @@
</router-link>
</div>
</div>

<!-- Governance -->
<div class="row--expand">
<div class="row--expand__info">
<div class="column--label text--label">{{ $t('governance.governance') }}</div>
<div class="column--balance">
<template v-if="!isSkeleton">
<div class="column--amount text--amount">
{{ $n(truncate(lockInDemocracy, 3)) }}
</div>
<div class="column--symbol text--symbol">
{{ nativeTokenSymbol }}
</div>
</template>
<template v-else>
<div class="skeleton--right">
<q-skeleton animation="fade" class="skeleton--md" />
</div>
</template>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -310,6 +332,7 @@ export default defineComponent({
const vestingTtl = ref<number>(0);
const reservedTtl = ref<number>(0);
const lockInDappStaking = ref<number>(0);
const lockInDemocracy = ref<number>(0);
const isRocstar = ref<boolean>(false);
const isShibuya = ref<boolean>(false);
const isFaucet = ref<boolean>(false);
Expand Down Expand Up @@ -369,6 +392,10 @@ export default defineComponent({
}
};
const lockedAmount = computed<number>(() =>
Math.max(vestingTtl.value, lockInDappStaking.value, lockInDemocracy.value, reservedTtl.value)
);
watch([nativeTokenSymbol, balance, props], setBalanceData, { immediate: false });
watchEffect(() => {
Expand All @@ -377,11 +404,14 @@ export default defineComponent({
// Memo: `vesting ` -> there has been inputted 1 space here
const vesting = accountDataRef.locks.find((it) => u8aToString(it.id) === 'vesting ');
const dappStake = accountDataRef.locks.find((it) => u8aToString(it.id) === 'dapstake');
const democracy = accountDataRef.locks.find((it) => u8aToString(it.id) === 'democrac');
const reserved = accountDataRef.reserved;
if (vesting) {
const amount = String(vesting.amount);
vestingTtl.value = Number(ethers.utils.formatEther(amount));
}
if (dappStake) {
const amount = String(dappStake.amount);
lockInDappStaking.value = Number(ethers.utils.formatEther(amount));
Expand All @@ -393,6 +423,10 @@ export default defineComponent({
const amount = reserved.toString();
reservedTtl.value = Number(ethers.utils.formatEther(amount));
}
if (democracy) {
lockInDemocracy.value = Number(ethers.utils.formatEther(democracy.amount.toString()));
}
});
// Ref: https://stackoverflow.com/questions/48143381/css-expand-contract-animation-to-show-hide-content
Expand All @@ -414,6 +448,7 @@ export default defineComponent({
isShibuya,
vestingTtl,
lockInDappStaking,
lockInDemocracy,
isFaucet,
transferableBalance,
isModalTransfer,
Expand All @@ -437,6 +472,7 @@ export default defineComponent({
handleModalFaucet,
handleModalEvmWithdraw,
expandAsset,
lockedAmount,
};
},
});
Expand Down
28 changes: 14 additions & 14 deletions src/components/dashboard/InflationRateChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
<div class="row chart--value">
<div>
<span class="text--value text-color--neon">{{ estimatedInflation?.toFixed(1) }}%</span>
<span class="text--value text-color--neon">{{ estimatedInflation?.toFixed(2) }}%</span>
</div>
</div>
<div class="chart">
Expand All @@ -22,7 +22,7 @@
</template>

<script lang="ts">
import { defineComponent, computed, ref, watch, onMounted } from 'vue';
import { defineComponent, computed, ref, watch } from 'vue';
import { Chart } from 'highcharts-vue';
import { useStore } from 'src/store';
import { titleFormatter, seriesFormatter } from 'src/modules/token-api';
Expand Down Expand Up @@ -150,18 +150,18 @@ export default defineComponent({
chartOptions.value.xAxis.labels.style.color = getTextColor();
});
watch([maximumInflationData], () => {
if (maximumInflationData.value && maximumInflationData.value.length > 0) {
hasData.value = true;
chartOptions.value.series[0].data = maximumInflationData.value;
} else {
hasData.value = false;
}
});
onMounted(() => {
estimateRealizedInflation();
});
watch(
[maximumInflationData],
() => {
if (maximumInflationData.value && maximumInflationData.value.length > 0) {
hasData.value = true;
chartOptions.value.series[0].data = maximumInflationData.value;
} else {
hasData.value = false;
}
},
{ immediate: true }
);
return {
estimatedInflation,
Expand Down
4 changes: 0 additions & 4 deletions src/components/governance/GovernanceLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import { defineComponent } from 'vue';
export default defineComponent({
props: {
index: {
type: Number,
required: true,
},
title: {
type: String,
required: true,
Expand Down
19 changes: 11 additions & 8 deletions src/components/governance/GovernanceLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
<div class="header"><astar-icon-governance />{{ $t('governance.newProposals') }}</div>
<hr class="separator" />
<div class="governance-container">
<div v-for="proposal in proposals" :key="proposal.index">
<div v-if="!hasProposals">
<governance-link
:title="$t('governance.noProposals')"
:url="`${governanceUrl}/democracy/proposals`"
/>
</div>
<div v-for="proposal in proposals" v-else :key="proposal.index">
<governance-link :index="proposal.index" :title="proposal.title" :url="proposal.url" />
</div>
</div>
<div v-if="ongoingReferenda" class="governance-container">
<div class="header"><astar-icon-governance />{{ $t('governance.ongoingReferenda') }}</div>
<hr class="separator" />
<governance-link
:index="ongoingReferenda.index"
:title="ongoingReferenda.title"
:url="ongoingReferenda.url"
/>
<governance-link :title="ongoingReferenda.title" :url="ongoingReferenda.url" />
</div>
</div>
</template>
Expand All @@ -27,9 +29,10 @@ import GovernanceLink from './GovernanceLink.vue';
export default defineComponent({
components: { GovernanceLink },
setup() {
const { isGovernanceEnabled, proposals, ongoingReferenda } = useGovernance();
const { isGovernanceEnabled, proposals, ongoingReferenda, hasProposals, governanceUrl } =
useGovernance();
return { isGovernanceEnabled, proposals, ongoingReferenda };
return { isGovernanceEnabled, proposals, ongoingReferenda, hasProposals, governanceUrl };
},
});
</script>
Expand Down
46 changes: 24 additions & 22 deletions src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useStore } from 'src/store';
import { computed, onUnmounted, ref, Ref, watch } from 'vue';
import { isValidEvmAddress } from '@astar-network/astar-sdk-core';
import { useDapps } from 'src/staking-v3';
import { Option, Vec, u32 } from '@polkadot/types';
import { Option, Vec, u128, u32 } from '@polkadot/types';

// Temporarily moved here until uplift polkadot js for astar.js
export const getVested = ({
Expand Down Expand Up @@ -223,11 +223,20 @@ export class AccountData {
}

public getUsableTransactionBalance(): BN {
return this.free.sub(this.frozen);
// refs.
// https://wiki.polkadot.network/docs/learn-account-balances
// https://github.com/paritytech/polkadot-sdk/blob/e8da320734ae44803f89dd2b35b3cfea0e1ecca1/substrate/frame/balances/src/impl_fungible.rs#L44
const existentialDeposit = <u128>$api?.consts.balances.existentialDeposit;
if (!existentialDeposit) {
return new BN(0);
}

const untouchable = BN.max(this.frozen.sub(this.reserved), existentialDeposit);
return this.free.sub(untouchable);
}

public getUsableFeeBalance(): BN {
return this.free.sub(this.frozen);
return this.getUsableTransactionBalance();
}

public free: BN;
Expand All @@ -241,26 +250,19 @@ export class AccountData {
public locks: (PalletBalancesBalanceLock | BalanceLockTo212)[];
}

// FIXME: the class might be inherited by AccountData
export class AccountDataH160 {
export class AccountDataH160 extends AccountData {
constructor(
public free: BN,
public reserved: BN,
public frozen: BN,
public flags: BN,
public vested: BN,
public vesting: ExtendedVestingInfo[],
public vestedClaimable: BN,
public remainingVests: BN,
public locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]
) {}

public getUsableTransactionBalance(): BN {
return this.free.sub(this.frozen);
}

public getUsableFeeBalance(): BN {
return this.free.sub(this.flags);
free: BN,
reserved: BN,
frozen: BN,
flags: BN,
vested: BN,
vesting: ExtendedVestingInfo[],
vestedClaimable: BN,
remainingVests: BN,
locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]
) {
super(free, reserved, frozen, flags, vested, vesting, vestedClaimable, remainingVests, locks);
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/hooks/useGovernance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { computed, ref, onMounted } from 'vue';
import { useNetworkInfo } from './useNetworkInfo';
import axios from 'axios';
import { endpointKey } from 'src/config/chainEndpoints';

export type GovernanceData = {
title: string;
Expand All @@ -11,6 +12,7 @@ export type GovernanceData = {

const proposals = ref<GovernanceData[]>([]);
const ongoingReferenda = ref<GovernanceData>();
const hasProposals = computed<boolean>(() => proposals.value.length > 0);

const fetchProposals = async (network: string): Promise<GovernanceData[]> => {
try {
Expand Down Expand Up @@ -43,15 +45,11 @@ const fetchOngoingReferenda = async (network: string): Promise<GovernanceData |

if (response.data) {
const referendas = response.data.items.map(
(referenda: {
title: string;
referendumIndex: number;
referendumState: { state: string };
}) => {
(referenda: { title: string; referendumIndex: number; state: string }) => {
return <GovernanceData>{
title: referenda.title,
index: referenda.referendumIndex,
state: referenda.referendumState.state,
state: referenda.state ?? 'Unknown',
url: `https://${network}.subsquare.io/democracy/referenda/${referenda.referendumIndex}`,
};
}
Expand All @@ -67,14 +65,17 @@ const fetchOngoingReferenda = async (network: string): Promise<GovernanceData |
};

export function useGovernance() {
const { networkNameSubstrate } = useNetworkInfo();
const { currentNetworkIdx, networkNameSubstrate } = useNetworkInfo();

const networkLowercase = computed<string>(() => {
return networkNameSubstrate.value.toLowerCase();
});

const isGovernanceEnabled = computed<boolean>(() => {
return networkLowercase.value === 'shibuya';
return (
currentNetworkIdx.value === endpointKey.ASTAR ||
currentNetworkIdx.value === endpointKey.SHIBUYA
);
});

const governanceUrl = computed<string>(() => {
Expand All @@ -98,5 +99,6 @@ export function useGovernance() {
proposals,
ongoingReferenda,
governanceUrl,
hasProposals,
};
}
Loading

0 comments on commit 14b3b96

Please sign in to comment.