enclave-wallet-sdk
Version:
A simple enclave wallet SDK for React applications
44 lines (39 loc) • 1.75 kB
text/typescript
// Add this mapping at the top (after TOKEN_NETWORKS)
export const NETWORK_NAME_TO_CHAIN_ID: Record<string, number> = {
Arbitrum: 42161,
Optimism: 10,
Base: 8453,
Solana: 792703809,
};
export function getNetworkName(chainId: string | number): string {
const chainIdNumber =
typeof chainId === "string" ? parseInt(chainId) : chainId;
const networkName = Object.entries(NETWORK_NAME_TO_CHAIN_ID).find(
([_, id]) => id === chainIdNumber
)?.[0];
return networkName || chainId.toString();
}
export const NETWORK_LOGO_URLS: Record<string, string> = {
42161:
"https://firebasestorage.googleapis.com/v0/b/enclave-wallet.appspot.com/o/wallet-sdk%2Farb.svg?alt=media&token=dfb699cd-eac2-4e4e-9809-22dc02345f3f",
10: "https://firebasestorage.googleapis.com/v0/b/enclave-wallet.appspot.com/o/wallet-sdk%2Foptimism-logo.svg?alt=media&token=f52cb44c-a33b-4f92-9548-845f16b5a078",
8453: "https://firebasestorage.googleapis.com/v0/b/enclave-wallet.appspot.com/o/wallet-sdk%2Fbase.svg?alt=media&token=20100f13-c8d9-4c5e-885c-9357d029cea1",
792703809:
"https://firebasestorage.googleapis.com/v0/b/enclave-wallet.appspot.com/o/wallet-sdk%2Fsol.png?alt=media&token=9e5e8ea1-b00c-4d31-ae09-32c146d9f099",
};
export function formatAmount(amount: string) {
const num = parseFloat(amount);
const decimalPlaces = amount.split(".")[1]?.length || 0;
return decimalPlaces > 6 ? num.toFixed(6) : amount;
}
// Simple debounce implementation
export const debounce = <T extends (...args: any[]) => any>(
func: T,
wait: number
): ((...args: Parameters<T>) => void) => {
let timeout: NodeJS.Timeout;
return (...args: Parameters<T>) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
};