Skip to content

Commit d16f2c8

Browse files
authored
fix: fetch dApps staking data after changing accounts (#955)
* fix: fetch staked dapps data for EVM wallets * fix: clean up * fix: position for page column
1 parent f86486b commit d16f2c8

4 files changed

Lines changed: 20 additions & 28 deletions

File tree

src/components/dapp-staking/my-staking/components/NewsArea.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default defineComponent({
267267
color: $navy-1;
268268
269269
@media (min-width: $md) {
270-
bottom: 35px;
270+
bottom: 48px;
271271
}
272272
}
273273
.colum--current-page {

src/hooks/dapps-staking/useDispatchGetDapps.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useAccount, useNetworkInfo } from 'src/hooks';
22
import { wait } from '@astar-network/astar-sdk-core';
33
import { useStore } from 'src/store';
4-
import { computed, watchEffect } from 'vue';
4+
import { computed, watch } from 'vue';
55

66
export function useDispatchGetDapps() {
77
const store = useStore();
88
const { currentNetworkName } = useNetworkInfo();
99
const { currentAccount } = useAccount();
10-
const isH160 = computed<boolean>(() => store.getters['general/isH160Formatted']);
1110
const dapps = computed(() => store.getters['dapps/getAllDapps']);
1211

1312
// Memo: invoke this function whenever the users haven't connect to wallets
@@ -32,7 +31,7 @@ export function useDispatchGetDapps() {
3231

3332
const getDapps = async (): Promise<void> => {
3433
const isConnectedWallet = currentNetworkName.value && currentAccount.value;
35-
if (isConnectedWallet && dapps.value.length === 0) {
34+
if (isConnectedWallet) {
3635
const address = !currentAccount.value ? '' : currentAccount.value;
3736
store.dispatch('dapps/getDapps', {
3837
network: currentNetworkName.value.toLowerCase(),
@@ -43,7 +42,5 @@ export function useDispatchGetDapps() {
4342
}
4443
};
4544

46-
watchEffect(async () => {
47-
await getDapps();
48-
});
45+
watch([currentAccount, currentNetworkName], getDapps);
4946
}

src/hooks/dapps-staking/useStake.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { useI18n } from 'vue-i18n';
1515
export function useStake() {
1616
const router = useRouter();
1717
const route = useRoute();
18-
const { currentAccount } = useAccount();
18+
const { currentAccount, senderSs58Account } = useAccount();
1919
const { stakingList } = useStakingList();
2020
const isStakePage = computed<boolean>(() => route.fullPath.includes('stake'));
21-
const addressTransferFrom = ref<string>(currentAccount.value);
21+
const addressTransferFrom = ref<string>(senderSs58Account.value);
2222
const { t } = useI18n();
2323
const store = useStore();
2424

@@ -34,8 +34,8 @@ export function useStake() {
3434
const item = stakingListRef.find((it) => it.address === addressTransferFrom.value);
3535
if (!item) return defaultData;
3636

37-
const name = item.name === currentAccount.value ? 'Transferable Balance' : item.name;
38-
const isNominationTransfer = item.address !== currentAccount.value;
37+
const name = item.name === senderSs58Account.value ? 'Transferable Balance' : item.name;
38+
const isNominationTransfer = item.address !== senderSs58Account.value;
3939
const formattedText = `${name} (${balanceFormatter(item.balance, ASTAR_DECIMALS)})`;
4040
return { text: formattedText, item, isNominationTransfer };
4141
} catch (error) {
@@ -97,9 +97,9 @@ export function useStake() {
9797
};
9898

9999
watch(
100-
[currentAccount],
100+
[senderSs58Account],
101101
() => {
102-
addressTransferFrom.value = currentAccount.value;
102+
addressTransferFrom.value = senderSs58Account.value;
103103
},
104104
{ immediate: true }
105105
);

src/hooks/dapps-staking/useStakingList.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import { $web3 } from 'boot/api';
2-
import { DappCombinedInfo } from 'src/v2/models/DappsStaking';
31
import { ethers } from 'ethers';
42
import { useAccount, useBalance, useNetworkInfo } from 'src/hooks';
53
import { StakingData } from 'src/modules/dapp-staking/index';
64
import { getTokenImage } from 'src/modules/token';
75
import { useStore } from 'src/store';
8-
import { computed, ref, watchEffect } from 'vue';
6+
import { DappCombinedInfo } from 'src/v2/models/DappsStaking';
7+
import { computed, ref, watch } from 'vue';
98

109
export function useStakingList() {
11-
const { currentAccount } = useAccount();
12-
const { accountData } = useBalance(currentAccount);
10+
const { senderSs58Account } = useAccount();
11+
const { accountData } = useBalance(senderSs58Account);
1312
const { nativeTokenSymbol } = useNetworkInfo();
1413
const store = useStore();
1514
const isLoading = computed(() => store.getters['general/isLoading']);
1615
const dapps = computed<DappCombinedInfo[]>(() => store.getters['dapps/getAllDapps']);
17-
const isH160 = computed(() => store.getters['general/isH160Formatted']);
1816
const nativeTokenImg = computed<string>(() =>
1917
getTokenImage({ isNativeToken: true, symbol: nativeTokenSymbol.value })
2018
);
@@ -31,8 +29,8 @@ export function useStakingList() {
3129
const setStakingList = async (): Promise<void> => {
3230
const dappsRef = dapps.value;
3331
const accountDataRef = accountData.value;
34-
const currentAccountRef = currentAccount.value;
35-
if (!accountDataRef || !currentAccountRef) return;
32+
const senderSs58AccountRef = senderSs58Account.value;
33+
if (!accountDataRef || !senderSs58AccountRef) return;
3634
try {
3735
const data = dappsRef.map((it) => {
3836
const accountStakingAmount = it.stakerInfo.accountStakingAmount;
@@ -48,12 +46,9 @@ export function useStakingList() {
4846
}
4947
});
5048

51-
const balance = isH160.value
52-
? await $web3.value!.eth.getBalance(currentAccount.value)
53-
: accountDataRef.getUsableFeeBalance().toString();
54-
49+
const balance = accountDataRef.getUsableFeeBalance().toString();
5550
data.unshift({
56-
address: currentAccountRef,
51+
address: senderSs58AccountRef,
5752
name: 'Transferable Balance',
5853
balance,
5954
iconUrl: nativeTokenImg.value,
@@ -65,8 +60,8 @@ export function useStakingList() {
6560
}
6661
};
6762

68-
watchEffect(async () => {
69-
if (isLoading.value || !dapps.value) {
63+
watch([isLoading, senderSs58Account, accountData], async () => {
64+
if (isLoading.value || !dapps.value || !senderSs58Account.value) {
7065
return;
7166
}
7267
await setStakingList();

0 commit comments

Comments
 (0)