Skip to content

Commit

Permalink
feat: Return state and state setter from address state hooks and dest…
Browse files Browse the repository at this point in the history
…ructure in AddressViews
  • Loading branch information
msarcev committed Feb 14, 2024
1 parent 67bfbea commit a8f1377
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ interface AccountAddressViewProps {
}

const AccountAddressView: React.FC<AccountAddressViewProps> = ({ accountAddress }) => {
const { accountAddressDetails, totalBalance, availableBalance, isAccountDetailsLoading } = useAccountAddressState(accountAddress);
const [state] = useAccountAddressState(accountAddress);
const { accountAddressDetails, totalBalance, availableBalance, isAccountDetailsLoading } = state;
const isPageLoading = isAccountDetailsLoading;

return (
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/components/nova/address/AnchorAddressView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ interface AnchorAddressViewProps {
}

const AnchorAddressView: React.FC<AnchorAddressViewProps> = ({ anchorAddress }) => {
const { anchorAddressDetails, totalBalance, availableBalance, isAnchorDetailsLoading } = useAnchorAddressState(anchorAddress);
const [state] = useAnchorAddressState(anchorAddress);
const { anchorAddressDetails, totalBalance, availableBalance, isAnchorDetailsLoading } = state;
const isPageLoading = isAnchorDetailsLoading;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface Ed25519AddressViewProps {
}

const Ed25519AddressView: React.FC<Ed25519AddressViewProps> = ({ ed25519Address }) => {
const { ed25519AddressDetails, totalBalance, availableBalance } = useEd25519AddressState(ed25519Address);
const [state] = useEd25519AddressState(ed25519Address);
const { ed25519AddressDetails, totalBalance, availableBalance } = state;

return (
<div className="address-page">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface ImplicitAccountCreationAddressViewProps {
}

const ImplicitAccountCreationAddressView: React.FC<ImplicitAccountCreationAddressViewProps> = ({ implicitAccountCreationAddress }) => {
const { implicitAccountCreationAddressDetails, totalBalance, availableBalance } =
useImplicitAccountCreationAddressState(implicitAccountCreationAddress);
const [state] = useImplicitAccountCreationAddressState(implicitAccountCreationAddress);
const { implicitAccountCreationAddressDetails, totalBalance, availableBalance } = state;

return (
<div className="address-page">
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/components/nova/address/NftAddressView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ interface NftAddressViewProps {
}

const NftAddressView: React.FC<NftAddressViewProps> = ({ nftAddress }) => {
const { nftAddressDetails, totalBalance, availableBalance, isNftDetailsLoading } = useNftAddressState(nftAddress);
const [state] = useNftAddressState(nftAddress);
const { nftAddressDetails, totalBalance, availableBalance, isNftDetailsLoading } = state;
const isPageLoading = isNftDetailsLoading;

return (
Expand Down
10 changes: 2 additions & 8 deletions client/src/helpers/nova/hooks/useAccountAddressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface IAddressPageLocationProps {
addressDetails: IAddressDetails;
}

export const useAccountAddressState = (address: AccountAddress): IAccountAddressState => {
export const useAccountAddressState = (address: AccountAddress): [IAccountAddressState, React.Dispatch<Partial<IAccountAddressState>>] => {
const location = useLocation();
const { network } = useParams<AddressRouteProps>();
const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo);
Expand Down Expand Up @@ -64,11 +64,5 @@ export const useAccountAddressState = (address: AccountAddress): IAccountAddress
});
}, [accountOutput, totalBalance, availableBalance, isAccountDetailsLoading]);

return {
accountAddressDetails: state.accountAddressDetails,
accountOutput: state.accountOutput,
totalBalance: state.totalBalance,
availableBalance: state.availableBalance,
isAccountDetailsLoading: state.isAccountDetailsLoading,
};
return [state, setState];
};
10 changes: 2 additions & 8 deletions client/src/helpers/nova/hooks/useAnchorAddressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface IAddressPageLocationProps {
addressDetails: IAddressDetails;
}

export const useAnchorAddressState = (address: AnchorAddress): IAnchorAddressState => {
export const useAnchorAddressState = (address: AnchorAddress): [IAnchorAddressState, React.Dispatch<Partial<IAnchorAddressState>>] => {
const location = useLocation();
const { network } = useParams<AddressRouteProps>();
const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo);
Expand Down Expand Up @@ -64,11 +64,5 @@ export const useAnchorAddressState = (address: AnchorAddress): IAnchorAddressSta
});
}, [anchorOutput, totalBalance, availableBalance, isAnchorDetailsLoading]);

return {
anchorAddressDetails: state.anchorAddressDetails,
anchorOutput: state.anchorOutput,
totalBalance: state.totalBalance,
availableBalance: state.availableBalance,
isAnchorDetailsLoading: state.isAnchorDetailsLoading,
};
return [state, setState];
};
9 changes: 2 additions & 7 deletions client/src/helpers/nova/hooks/useEd25519AddressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IAddressPageLocationProps {
addressDetails: IAddressDetails;
}

export const useEd25519AddressState = (address: Ed25519Address) => {
export const useEd25519AddressState = (address: Ed25519Address): [IEd25519AddressState, React.Dispatch<Partial<IEd25519AddressState>>] => {
const location = useLocation();
const { name: network, bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo);
const [state, setState] = useReducer<Reducer<IEd25519AddressState, Partial<IEd25519AddressState>>>(
Expand All @@ -42,7 +42,6 @@ export const useEd25519AddressState = (address: Ed25519Address) => {
: { addressDetails: AddressHelper.buildAddress(bech32Hrp, address) };

setState({
...initialState,
ed25519AddressDetails: addressDetails,
});
}, []);
Expand All @@ -54,9 +53,5 @@ export const useEd25519AddressState = (address: Ed25519Address) => {
});
}, [totalBalance, availableBalance]);

return {
ed25519AddressDetails: state.ed25519AddressDetails,
totalBalance: state.totalBalance,
availableBalance: state.availableBalance,
};
return [state, setState];
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ interface IAddressPageLocationProps {
addressDetails: IAddressDetails;
}

export const useImplicitAccountCreationAddressState = (address: ImplicitAccountCreationAddress) => {
export const useImplicitAccountCreationAddressState = (
address: ImplicitAccountCreationAddress,
): [IImplicitAccountCreationAddressState, React.Dispatch<Partial<IImplicitAccountCreationAddressState>>] => {
const location = useLocation();
const { network } = useParams<AddressRouteProps>();
const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo);
Expand Down Expand Up @@ -56,9 +58,5 @@ export const useImplicitAccountCreationAddressState = (address: ImplicitAccountC
});
}, [totalBalance, availableBalance]);

return {
implicitAccountCreationAddressDetails: state.implicitAccountCreationAddressDetails,
totalBalance: state.totalBalance,
availableBalance: state.availableBalance,
};
return [state, setState];
};
10 changes: 2 additions & 8 deletions client/src/helpers/nova/hooks/useNftAddressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface IAddressPageLocationProps {
addressDetails: IAddressDetails;
}

export const useNftAddressState = (address: NftAddress): INftAddressState => {
export const useNftAddressState = (address: NftAddress): [INftAddressState, React.Dispatch<Partial<INftAddressState>>] => {
const location = useLocation();
const { network } = useParams<AddressRouteProps>();
const { bech32Hrp } = useNetworkInfoNova((s) => s.networkInfo);
Expand Down Expand Up @@ -64,11 +64,5 @@ export const useNftAddressState = (address: NftAddress): INftAddressState => {
});
}, [nftOutput, totalBalance, availableBalance, isNftDetailsLoading]);

return {
nftAddressDetails: state.nftAddressDetails,
nftOutput: state.nftOutput,
totalBalance: state.totalBalance,
availableBalance: state.availableBalance,
isNftDetailsLoading: state.isNftDetailsLoading,
};
return [state, setState];
};

0 comments on commit a8f1377

Please sign in to comment.