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

feat: replace chronicle balance response sigLockedBalance with availableBalance #995

Merged
merged 1 commit into from
Jan 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IAddressBalanceResponse extends IResponse {
/**
* The balance of trivialy unlockable outputs with address unlock condition.
*/
sigLockedBalance?: number;
availableBalance?: number;

/**
* The ledger index at which this balance data was valid.
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/routes/stardust/AddressPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AddressPage: React.FC<RouteComponentProps<AddressRouteProps>> = ({
const {
bech32AddressDetails,
balance,
sigLockedBalance,
availableBalance,
storageRentBalance,
isBasicOutputsLoading,
isAliasOutputsLoading,
Expand Down Expand Up @@ -87,7 +87,7 @@ const AddressPage: React.FC<RouteComponentProps<AddressRouteProps>> = ({
{balance !== null && (
<AddressBalance
balance={balance}
spendableBalance={sigLockedBalance}
spendableBalance={availableBalance}
storageRentBalance={storageRentBalance}
/>
)}
Expand Down
10 changes: 5 additions & 5 deletions client/src/app/routes/stardust/AddressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { IDIDResolverResponse } from "~/models/api/IDIDResolverResponse";
export interface IAddressState {
bech32AddressDetails: IBech32AddressDetails | null;
balance: number | null;
sigLockedBalance: number | null;
availableBalance: number | null;
storageRentBalance: number | null;
addressOutputs: OutputResponse[] | null;
addressBasicOutputs: OutputResponse[] | null;
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface IAddressState {
const initialState = {
bech32AddressDetails: null,
balance: null,
sigLockedBalance: null,
availableBalance: null,
storageRentBalance: null,
addressOutputs: null,
addressBasicOutputs: null,
Expand Down Expand Up @@ -127,7 +127,7 @@ export const useAddressPageState = (): [IAddressState, React.Dispatch<Partial<IA
network,
addressType === AddressType.Alias ? state.bech32AddressDetails : null,
);
const [balance, sigLockedBalance] = useAddressBalance(network, state.bech32AddressDetails?.bech32 ?? null);
const [balance, availableBalance] = useAddressBalance(network, state.bech32AddressDetails?.bech32 ?? null);
const [eventDetails] = useParticipationEventDetails(state.participations ?? undefined);

const [aliasContainsDID] = useAliasContainsDID(aliasOutput);
Expand Down Expand Up @@ -168,7 +168,7 @@ export const useAddressPageState = (): [IAddressState, React.Dispatch<Partial<IA
aliasFoundries,
isAliasFoundriesLoading,
balance,
sigLockedBalance,
availableBalance,
eventDetails,
aliasContainsDID,
resolvedDID,
Expand All @@ -189,7 +189,7 @@ export const useAddressPageState = (): [IAddressState, React.Dispatch<Partial<IA
aliasFoundries,
isAliasFoundriesLoading,
balance,
sigLockedBalance,
availableBalance,
eventDetails,
aliasContainsDID,
resolvedDID,
Expand Down
8 changes: 4 additions & 4 deletions client/src/helpers/hooks/useAddressBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useAddressBalance(network: string, address: string | null): [num
const isMounted = useIsMounted();
const [apiClient] = useState(ServiceFactory.get<StardustApiClient>(`api-client-${STARDUST}`));
const [balance, setBalance] = useState<number | null>(null);
const [sigLockedBalance, setSigLockedBalance] = useState<number | null>(null);
const [availableBalance, setAvailableBalance] = useState<number | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);

useEffect(() => {
Expand All @@ -26,14 +26,14 @@ export function useAddressBalance(network: string, address: string | null): [num

if (response?.totalBalance !== undefined && isMounted) {
setBalance(response.totalBalance);
setSigLockedBalance(response.sigLockedBalance ?? null);
setAvailableBalance(response.availableBalance ?? null);
} else if (isMounted) {
// Fallback balance from iotajs (node)
const addressDetailsWithBalance = await apiClient.addressBalance({ network, address });

if (addressDetailsWithBalance && isMounted) {
setBalance(Number(addressDetailsWithBalance.balance));
setSigLockedBalance(null);
setAvailableBalance(null);
}
}
})();
Expand All @@ -42,5 +42,5 @@ export function useAddressBalance(network: string, address: string | null): [num
}
}, [network, address]);

return [balance, sigLockedBalance, isLoading];
return [balance, availableBalance, isLoading];
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IAddressBalanceResponse extends IResponse {
/**
* The balance of trivialy unlockable outputs with address unlock condition.
*/
sigLockedBalance?: number;
availableBalance?: number;

/**
* The ledger index at which this balance data was valid.
Expand Down
Loading