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:
@@ -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
|
* Fallback function to get wallet balances using direct RPC calls
|
||||||
* Used when Privy API is unavailable (503, timeout, etc.)
|
* Used when Privy API is unavailable (503, timeout, etc.)
|
||||||
@@ -1312,18 +1328,14 @@ export const getWalletBalanceImpl = async (
|
|||||||
const timeoutId = setTimeout(() => controller.abort(), 25000);
|
const timeoutId = setTimeout(() => controller.abort(), 25000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const balanceResponse = await makePrivyRequest<{
|
const balanceResponse = await makePrivyRequest<PrivyBalanceResponse>(
|
||||||
balances: Array<{
|
balanceUrl,
|
||||||
chain: string;
|
{},
|
||||||
asset: string;
|
true,
|
||||||
raw_value: string;
|
'GET',
|
||||||
raw_value_decimals: number;
|
fastify,
|
||||||
display_values: {
|
controller.signal
|
||||||
[key: string]: string;
|
);
|
||||||
usd: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}>(balanceUrl, {}, true, 'GET', fastify, controller.signal);
|
|
||||||
|
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user