Skip to content

Commit

Permalink
feat: replace chronicle balance response sigLockedBalance with availa…
Browse files Browse the repository at this point in the history
…bleBalance (#995)
  • Loading branch information
begonaalvarezd authored Jan 23, 2024
1 parent 53cc883 commit 1496662
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
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

0 comments on commit 1496662

Please sign in to comment.