Skip to content

Commit

Permalink
fix: adjust stake data refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickk137 committed Sep 17, 2023
1 parent 857c5ab commit bc718f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
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,24 @@ 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(() => {
console.log('onAdjustSuccess');
onSuccess();
toggleAdjustStakeDialog();
}, [onSuccess]);

return (
<div className="flex lg:justify-end">
<Button
Expand All @@ -48,7 +56,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,8 @@ export const COLUMNS_CONFIG = [
{
id: 'actions',
title: ' ',
cellRenderer: (item: StakeItem) => AdjustStakeRenderer({ stake: item }),
cellRenderer: (item: StakeItem) =>
AdjustStakeRenderer({ stake: item, 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 };
};

0 comments on commit bc718f5

Please sign in to comment.