Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset the staking tab to 'My Rewards' after changing accounts #779

Merged
merged 1 commit into from
May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/components/dapp-staking/my-staking/MyStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
<div class="staking-container">
<div class="wrapper--tabs responsive">
<nav class="tabs">
<div class="tab" :class="currentTab === 0 ? 'active' : ''" @click="currentTab = 0">
<div
class="tab"
:class="currentTab === MyStakingTab.MyRewards ? 'active' : ''"
@click="currentTab = MyStakingTab.MyRewards"
>
<span class="text--tab">
{{ $t('dappStaking.myRewards') }}
</span>
</div>
<div
v-if="unlockingChunks && unlockingChunks.length > 0"
class="tab"
:class="currentTab === 1 ? 'active' : ''"
@click="currentTab = 1"
:class="currentTab === MyStakingTab.UnbondingList ? 'active' : ''"
@click="currentTab = MyStakingTab.UnbondingList"
>
<span class="text--tab">
{{ $t('dappStaking.unbonding') }}
Expand All @@ -22,8 +26,8 @@
<div
v-if="myStakeInfos && myStakeInfos.length > 0"
class="tab"
:class="currentTab === 2 ? 'active' : ''"
@click="currentTab = 2"
:class="currentTab === MyStakingTab.MyDapps ? 'active' : ''"
@click="currentTab = MyStakingTab.MyDapps"
>
<span class="text--tab">
{{ $t('dappStaking.myDapps') }}
Expand Down Expand Up @@ -56,16 +60,22 @@
</div>
</template>
<script lang="ts">
import { defineComponent, ref, computed } from 'vue';
import { defineComponent, ref, computed, watch } from 'vue';
import { ethers } from 'ethers';
import { useStore } from 'src/store';
import { useBalance, useNetworkInfo, useStakerInfo } from 'src/hooks';
import { useAccount, useBalance, useNetworkInfo, useStakerInfo } from 'src/hooks';
import { useUnbonding } from 'src/hooks/dapps-staking/useUnbonding';
import MyRewards from './MyRewards.vue';
import UnbondingList from './UnbondingList.vue';
import MyDapps from './MyDapps.vue';
import TokenBalance from 'src/components/common/TokenBalance.vue';

enum MyStakingTab {
MyRewards = 0,
UnbondingList = 1,
MyDapps = 2,
}

export default defineComponent({
components: {
MyRewards,
Expand All @@ -75,10 +85,11 @@ export default defineComponent({
},
setup() {
const store = useStore();
const currentTab = ref(0);
const currentTab = ref<MyStakingTab>(MyStakingTab.MyDapps);
const { nativeTokenSymbol } = useNetworkInfo();
const { unlockingChunks } = useUnbonding();
const { myStakeInfos } = useStakerInfo();
const { currentAccount } = useAccount();

const selectedAddress = computed(() => store.getters['general/selectedAddress']);
const { accountData, isLoadingBalance } = useBalance(selectedAddress);
Expand All @@ -90,13 +101,22 @@ export default defineComponent({
return Number(balance);
});

watch(
[currentAccount],
() => {
currentTab.value = MyStakingTab.MyRewards;
},
{ immediate: false }
);

return {
currentTab,
isLoadingBalance,
transferableBalance,
nativeTokenSymbol,
unlockingChunks,
myStakeInfos,
MyStakingTab,
};
},
});
Expand Down
Loading