Skip to content

Commit

Permalink
feat: withdrawal aggregator is hidde only when respond error code is 500
Browse files Browse the repository at this point in the history
  • Loading branch information
bobunderforest committed Feb 12, 2024
1 parent e768031 commit 0e4d49d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion features/withdrawals/hooks/useWithdrawalRates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { STRATEGY_LAZY } from 'utils/swrStrategies';
import { RequestFormInputType } from '../request/request-form-context';
import { getOpenOceanRate } from 'utils/get-open-ocean-rate';
import { standardFetcher } from 'utils/standardFetcher';
import { FetcherError } from 'utils/fetcherError';

type GetWithdrawalRateParams = {
amount: BigNumber;
Expand All @@ -27,6 +28,7 @@ type SingleWithdrawalRateResult = {
name: string;
rate: number | null;
toReceive: BigNumber | null;
displayEmpty?: boolean;
};

type GetRateType = (
Expand All @@ -50,6 +52,8 @@ const calculateRateReceive = (
};

const getOpenOceanWithdrawalRate: GetRateType = async ({ amount, token }) => {
let displayEmpty = false;

if (amount && amount.gt(Zero)) {
try {
const rate = await getOpenOceanRate(amount, token, 'ETH');
Expand All @@ -58,6 +62,7 @@ const getOpenOceanWithdrawalRate: GetRateType = async ({ amount, token }) => {
...rate,
};
} catch (e) {
displayEmpty = e instanceof FetcherError && e.status < 500;
console.warn('[getOpenOceanRate] Failed to receive withdraw rate', e);
}
}
Expand All @@ -66,6 +71,7 @@ const getOpenOceanWithdrawalRate: GetRateType = async ({ amount, token }) => {
name: 'openOcean',
rate: null,
toReceive: null,
displayEmpty,
};
};

Expand All @@ -78,6 +84,7 @@ type ParaSwapPriceResponsePartial = {

const getParaSwapRate: GetRateType = async ({ amount, token }) => {
let rateInfo: RateCalculationResult | null;
let displayEmpty = false;

try {
if (amount.isZero() || amount.isNegative()) {
Expand Down Expand Up @@ -111,14 +118,16 @@ const getParaSwapRate: GetRateType = async ({ amount, token }) => {
BigNumber.from(data.priceRoute.srcAmount),
BigNumber.from(data.priceRoute.destAmount),
);
} catch {
} catch (e) {
rateInfo = null;
displayEmpty = e instanceof FetcherError && e.status < 500;
}

return {
name: 'paraswap',
rate: rateInfo?.rate ?? null,
toReceive: rateInfo?.toReceive ?? null,
displayEmpty,
};
};

Expand Down
4 changes: 2 additions & 2 deletions features/withdrawals/request/form/options/dex-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export const DexOptions: React.FC<
useWithdrawalRates();

const dexesFiltered = useMemo(() => {
return data?.filter(({ rate, name }) => {
return data?.filter(({ rate, name, displayEmpty }) => {
const dex = dexInfo[name];
return dex && (amount.eq('0') || rate !== null);
return dex && (amount.eq('0') || rate !== null || displayEmpty);
});
}, [amount, data]);

Expand Down

0 comments on commit 0e4d49d

Please sign in to comment.