Skip to content

Commit

Permalink
fixup! feat(trading): otc market banner
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive committed Feb 27, 2025
1 parent 713cfad commit 3b424cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ export const TradingFormOfferOTC = () => {
? context.getValues().currencySelect.value
: context.getValues().outputs[0].currency.value;
const [otcUrl, setOtcUrl] = useState<string | null>(null);
const [allowedCurrencies, setAllowedCurrencies] = useState<string[]>([]);
const [minimumFiat, setMinimumFiat] = useState<string | null>(null);
const apiKey = invityAPI.getCurrentApiKey();

// constants will be refactor to be more dynamic in the future
const ALLOWED_FIAT_CURRENCIES = ['usd', 'eur'];
const FIAT_AMOUNT_ALLOWANCE = '50001';

const isCurrencyAllowed = ALLOWED_FIAT_CURRENCIES.includes(currencySelect);
const isCurrencyAllowed = allowedCurrencies.includes(currencySelect);
const shouldBeComponentHidden =
amountInCrypto ||
!isCurrencyAllowed ||
!fiatAmount ||
Number(fiatAmount) < Number(FIAT_AMOUNT_ALLOWANCE);
Number(fiatAmount) < Number(minimumFiat);

useEffect(() => {
if (shouldBeComponentHidden) return;
if (!fiatAmount || !apiKey) return;

const getOtcData = async () => {
const otcData = await invityAPI.getOTCData();
Expand All @@ -50,10 +50,15 @@ export const TradingFormOfferOTC = () => {
apiUrl.search = params.toString();

setOtcUrl(apiUrl.toString());
setAllowedCurrencies(otcData.allowedCurrencies);
setMinimumFiat(otcData.minimumFiat);
};

getOtcData();
}, [context.type, currencySelect, fiatAmount, shouldBeComponentHidden]);

// change only when apiKey changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [apiKey]);

if (shouldBeComponentHidden || !otcUrl) {
return null;
Expand Down
2 changes: 2 additions & 0 deletions suite-common/trading/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ export type TradingOTC = {
idWidget: string;
idOtcUser: string;
apiUrl: string;
minimumFiat: string;
allowedCurrencies: FiatCurrencyCode[];
};

0 comments on commit 3b424cc

Please sign in to comment.