Add PrivyBalanceResponse type for improved type safety in wallet balance retrieval

- Introduced a new type definition for Privy balance response to enhance type safety and clarity in the getWalletBalanceImpl function.
- Updated the makePrivyRequest call to utilize the new PrivyBalanceResponse type, streamlining the handling of balance data.
- This change aims to improve code maintainability and reduce potential errors during balance retrieval processes.
This commit is contained in:
2026-01-06 20:15:53 +07:00
parent ad654888f1
commit 8acb35719d

View File

@@ -1095,6 +1095,22 @@ export const sendTokenImpl = async (
}
};
/**
* Type for Privy balance response
*/
type PrivyBalanceResponse = {
balances: Array<{
chain: string;
asset: string;
raw_value: string;
raw_value_decimals: number;
display_values: {
[key: string]: string;
usd: string;
};
}>;
};
/**
* Fallback function to get wallet balances using direct RPC calls
* Used when Privy API is unavailable (503, timeout, etc.)
@@ -1312,18 +1328,14 @@ export const getWalletBalanceImpl = async (
const timeoutId = setTimeout(() => controller.abort(), 25000);
try {
const balanceResponse = await makePrivyRequest<{
balances: Array<{
chain: string;
asset: string;
raw_value: string;
raw_value_decimals: number;
display_values: {
[key: string]: string;
usd: string;
};
};
}>(balanceUrl, {}, true, 'GET', fastify, controller.signal);
const balanceResponse = await makePrivyRequest<PrivyBalanceResponse>(
balanceUrl,
{},
true,
'GET',
fastify,
controller.signal
);
clearTimeout(timeoutId);