Skip to content

Commit

Permalink
fix: eliminate double ternary
Browse files Browse the repository at this point in the history
  • Loading branch information
rozanagy committed Feb 13, 2025
1 parent 0d5c020 commit e1ce55e
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/app/hooks/use-proof-of-reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,40 @@ export function useProofOfReserve(): UseProofOfReserveReturnType {
chainName: string,
networkType: NetworkType
): Promise<ProofOfReserveByChainReturnType> {
try {
const baseApiURL = `${PROOF_OF_RESERVE_API_URL}/${appConfiguration.appEnvironment}?chain=`;
const formatChainParam = (chain: string, network: NetworkType): string => {
if (network === NetworkType.XRPL) {
return `${network.toLowerCase()}-${chain.toLowerCase()}`;
}
return chain ? chain.toLowerCase() : '';
};

const chainParam =
networkType === NetworkType.XRPL
? `${networkType.toLowerCase()}-${chainName.toLowerCase()}`
: chainName
? chainName.toLowerCase()
: '';
const buildApiUrl = (chainParam: string): string => {
const baseUrl = `${PROOF_OF_RESERVE_API_URL}/${appConfiguration.appEnvironment}`;
return `${baseUrl}?chain=${chainParam}`;
};

const apiURL = `${baseApiURL}${chainParam}`;
try {
const chainParam = formatChainParam(chainName, networkType);
const apiUrl = buildApiUrl(chainParam);

const response = await fetch(apiURL);
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('Error fetching Proof of Reserve by Chain');
}
return { chain: `${networkType}-${chainName}`, value: await response.json() };

const data = await response.json();
return {
chain: `${networkType}-${chainName}`,
value: data
};

} catch (error) {
// eslint-disable-next-line no-console
console.error('Error fetching Proof of Reserve by Chain', error);
return { chain: chainName, value: 0 };
return {
chain: chainName,
value: 0
};
}
}

Expand Down

0 comments on commit e1ce55e

Please sign in to comment.