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

SOV-2942: fix adjust stake data refresh #582

Merged
merged 3 commits into from
Sep 25, 2023
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
5 changes: 5 additions & 0 deletions .changeset/six-tips-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend": patch
---

SOV-2942: fix adjust stake data refresh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useReducer } from 'react';
import React, { FC, useCallback, useReducer } from 'react';

import { t } from 'i18next';

Expand All @@ -18,16 +18,23 @@ import { StakeItem } from '../StakesFrame/StakesFrame.types';

type AdjustStakeRendererProps = {
stake: StakeItem;
onSuccess: () => void;
};

export const AdjustStakeRenderer: FC<AdjustStakeRendererProps> = ({
stake,
onSuccess,
}) => {
const [openCreateStakeDialog, toggleAdjustStakeDialog] = useReducer(
v => !v,
false,
);

const onAdjustSuccess = useCallback(() => {
onSuccess();
toggleAdjustStakeDialog();
}, [onSuccess]);

return (
<div className="flex lg:justify-end">
<Button
Expand All @@ -48,7 +55,7 @@ export const AdjustStakeRenderer: FC<AdjustStakeRendererProps> = ({
onClose={toggleAdjustStakeDialog}
/>
<DialogBody>
<AdjustStakeForm stake={stake} onSuccess={toggleAdjustStakeDialog} />
<AdjustStakeForm stake={stake} onSuccess={onAdjustSuccess} />
</DialogBody>
</Dialog>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { VotingPowerCellRenderer } from './components/VotingPowerCellRenderer';

const rskExplorerUrl = getRskExplorerUrl();

export const COLUMNS_CONFIG = [
export const COLUMNS_CONFIG = (onSuccess: () => void) => [
{
id: 'stakeAmount',
title: t(translations.stakePage.table.stakeAmount),
Expand Down Expand Up @@ -55,7 +55,9 @@ export const COLUMNS_CONFIG = [
{
id: 'actions',
title: ' ',
cellRenderer: (item: StakeItem) => AdjustStakeRenderer({ stake: item }),
cellRenderer: (item: StakeItem) => (
<AdjustStakeRenderer stake={item} onSuccess={onSuccess} />
),
labelClassName: 'hidden lg:table-cell',
valueClassName: 'w-full lg:w-auto',
className: 'flex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const pageSize = DEFAULT_PAGE_SIZE;

export const StakesFrame: FC = () => {
const { account } = useAccount();
const { stakes, loading } = useGetStakes();
const { stakes, loading, refetch } = useGetStakes();
const { balance } = useGetStakingBalanceOf(account);

const hasStakedValue = useMemo(() => Number(balance) > 0, [balance]);
Expand Down Expand Up @@ -48,6 +48,8 @@ export const StakesFrame: FC = () => {
[loading, paginatedStakes?.length, stakes?.length],
);

const columns = useMemo(() => COLUMNS_CONFIG(refetch), [refetch]);

return (
<div className="flex flex-col mb-10">
<div className="flex justify-between items-center mb-3 md:mb-6">
Expand All @@ -61,7 +63,7 @@ export const StakesFrame: FC = () => {

<div className="bg-gray-80 py-4 px-4 rounded">
<Table
columns={COLUMNS_CONFIG}
columns={columns}
rows={paginatedStakes}
rowTitle={generateRowTitle}
isLoading={loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ export const useGetStakes = () => {
prevBlockRef.current = block;
}, [block, account, updateStakes]);

return { stakes, loading };
return { stakes, loading, refetch: updateStakes };
};