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(staking): fix last stake account when moving between devnet #2020

Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions apps/staking/src/components/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ const useIntegrityStakingSum = (
publishers
.map((publisher) => publisher.positions?.[field] ?? 0n)
.reduce((acc, cur) => acc + cur, 0n),
// eslint-disable-next-line react-hooks/exhaustive-deps
publishers.map((publisher) => publisher.positions?.[field]),
[publishers, field],
);

// eslint-disable-next-line unicorn/no-array-reduce
Expand Down
22 changes: 17 additions & 5 deletions apps/staking/src/hooks/use-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
revalidateOnReconnect: false,
},
);
const lastStakeAccount = useLocalStorageValue<string>("last-stake-account");
const lastStakeAccountMainnet = useLocalStorageValue<string>(
`last-stake-account.mainnet`,
);
const lastStakeAccountDevnet = useLocalStorageValue<string>(
`last-stake-account.devnet`,
);

return useMemo(() => {
if (wallet.connecting) {
Expand All @@ -213,11 +218,17 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
} else {
const [firstAccount, ...otherAccounts] = stakeAccounts.data;
if (firstAccount) {
const selectedAccount = lastStakeAccount.value
const localStorageValue = isMainnet
? lastStakeAccountMainnet
: lastStakeAccountDevnet;
const selectedAccount = localStorageValue.value
? stakeAccounts.data.find(
(account) => account.toBase58() === lastStakeAccount.value,
(account) => account.toBase58() === localStorageValue.value,
)
: undefined;
if (!selectedAccount) {
localStorageValue.set(firstAccount.toBase58());
}
return State[StateType.Loaded](
isMainnet,
pythStakingClient,
Expand All @@ -226,7 +237,7 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
selectedAccount ?? firstAccount,
[firstAccount, ...otherAccounts],
(account: PublicKey) => {
lastStakeAccount.set(account.toBase58());
localStorageValue.set(account.toBase58());
},
mutate,
);
Expand Down Expand Up @@ -256,7 +267,8 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
pythnetClient,
stakeAccounts,
hermesClient,
lastStakeAccount,
lastStakeAccountMainnet,
lastStakeAccountDevnet,
mutate,
]);
};
Expand Down
Loading