Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1096: Add new Alice-Bob exchange pairs #1002

Merged
merged 10 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2642,34 +2642,31 @@
"enterCardNumber": {
"message": "Enter card number"
},
"onlyForUkrainianCards": {
"message": "Only for Ukrainian banking cards"
"onlyForCountryBankingCards": {
"message": "Only for $country$ banking cards",
"placeholders": {
"country": {
"content": "$1"
}
}
},
"buyWithCrypto": {
"message": "Buy with Crypto"
},
"buyWithExolix": {
"message": "Buy With Exolix"
},
"buyWithExolixDescription": {
"message": "Exchange $number$ cryptocurrencies to TEZ or USDT Tezos instantly and without registration",
"placeholders": {
"number": {
"content": "$1"
}
}
},
"buyWithRamp": {
"message": "Buy With Ramp"
},
"buyWithRampDescription": {
"message": "Buy TEZ using Visa, Mastercard, and all major debit and credit cards. Ramp is available in 160+ countries and territories."
},
"sellWithAliceBob": {
"message": "Sell TEZ with Alice-Bob (UAH only)"
"message": "Sell TEZ with Alice-Bob"
},
"sellWithAliceBobDescription": {
"message": "Fast and cost-effective exchange of TEZ to UAH."
"message": "Fast and cost-effective exchange of TEZ."
},
"selectPaymentProvider": {
"message": "Select payment provider"
Expand Down Expand Up @@ -2781,7 +2778,7 @@
"message": "Sell TEZ details"
},
"sellDetailsDescription": {
"message": "Sell TEZ to fiat. Get fiat to Visa, Mastercard Ukrainian cards."
"message": "Sell TEZ to fiat. Get fiat to Visa, Mastercard cards."
},
"privacyAndPolicyLinks": {
"message": "By clicking $buttonContent$ you agree with \n$termsOfUse$ and $privacyPolicy$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useAccount, useBalance } from 'lib/temple/front';

export const useDisabledProceed = (
inputAmount: number | undefined,
minExchangeAmount: number,
maxExchangeAmount: number,
minExchangeAmount = 0,
maxExchangeAmount = 0,
isWithdraw = false
) => {
const { publicKeyHash } = useAccount();
Expand Down
75 changes: 75 additions & 0 deletions src/app/hooks/AliceBob/use-output-currencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useCallback, useEffect, useState } from 'react';

import { getCurrencyNameByCode, knownAliceBobFiatCurrencies } from 'app/store/buy-with-credit-card/utils';
import { getAliceBobPairsInfo } from 'lib/apis/temple';
import { FIAT_ICONS_SRC } from 'lib/icons';

export interface AliceBobWithdrawCurrency {
name: string;
code: string;
icon: string;
minAmount?: number;
maxAmount?: number;
}

export const DEFAULT_OUTPUT_CURRENCY = {
name: getCurrencyNameByCode('UAH'),
code: 'UAH',
icon: FIAT_ICONS_SRC.UAH
};

export const useOutputCurrencies = (
setIsApiError: (v: boolean) => void,
outputCurrency: AliceBobWithdrawCurrency,
setOutputCurrency: (currency: AliceBobWithdrawCurrency) => void
) => {
const [isCurrenciesLoading, setIsCurrenciesLoading] = useState(false);

const [currencies, setCurrencies] = useState<AliceBobWithdrawCurrency[]>([]);

const getCurrenciesRequest = useCallback(() => {
setIsCurrenciesLoading(true);

getAliceBobPairsInfo(true)
.then(response => {
const newCurrencies = response.data.pairsInfo.map(pair => {
const code = pair.to.slice(-3);
const minAmount = Number(pair.minamount.split(' ')[0]);
const maxAmount = Number(pair.maxamount.split(' ')[0]);

if (knownAliceBobFiatCurrencies[code]) {
return {
...knownAliceBobFiatCurrencies[code],
minAmount,
maxAmount
};
}

return {
name: getCurrencyNameByCode(code),
code,
icon: `https://static.moonpay.com/widget/currencies/${code.toLowerCase()}.svg`,
minAmount,
maxAmount
};
});

setCurrencies(newCurrencies);

if (!outputCurrency.minAmount) {
setOutputCurrency(newCurrencies.find(currency => currency.code === 'UAH') ?? DEFAULT_OUTPUT_CURRENCY);
}
})
.catch(() => setIsApiError(true))
.finally(() => setIsCurrenciesLoading(false));
}, [outputCurrency.minAmount, setIsApiError, setOutputCurrency]);

useEffect(() => {
getCurrenciesRequest();
}, [getCurrenciesRequest]);

return {
isCurrenciesLoading,
currencies
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { estimateAliceBobOutput } from 'lib/apis/temple';

export const useOutputEstimation = (
inputAmount = 0,
outputAssetCode: string,
isMinAmountError: boolean,
isMaxAmountError: boolean,
setIsApiError: (v: boolean) => void,
isWithdraw = false
setIsApiError: (v: boolean) => void
) => {
const [outputAmount, setOutputAmount] = useState(0);
const [estimationIsLoading, setLoading] = useState(false);
Expand All @@ -23,14 +23,14 @@ export const useOutputEstimation = (
if (isValidInput) {
setLoading(true);

estimateAliceBobOutput(isWithdraw, inputAmount.toString())
estimateAliceBobOutput(inputAmount.toString(), 'XTZ', outputAssetCode)
.then(response => {
setOutputAmount(new BigNumber(response.data.outputAmount).dp(2, BigNumber.ROUND_FLOOR).toNumber());
})
.catch(() => setIsApiError(true))
.finally(() => setLoading(false));
}
}, [inputAmount, isValidInput, isWithdraw, setIsApiError, setLoading]);
}, [inputAmount, isValidInput, outputAssetCode, setIsApiError]);

useEffect(() => {
getOutputEstimation();
Expand Down
41 changes: 0 additions & 41 deletions src/app/hooks/AliceBob/useMinMaxExchangeAmounts.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/app/pages/BuyWithCreditCard/BuyWithCreditCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getAssetSymbolToDisplay } from 'lib/buy-with-credit-card/get-asset-symb
import { TopUpInputInterface } from 'lib/buy-with-credit-card/topup.interface';
import { shouldShowFieldError } from 'lib/form/should-show-field-error';
import { t, T, toLocalFormat } from 'lib/i18n';
import { FIAT_ICONS_SRC } from 'lib/icons';
import { useInterval } from 'lib/ui/hooks';

import { BuyWithCreditCardSelectors } from './BuyWithCreditCard.selectors';
Expand All @@ -32,7 +33,8 @@ import { usePaymentProviders } from './hooks/use-payment-providers';
import { useUpdateCurrentProvider } from './hooks/use-update-current-provider';
import { AmountErrorType } from './types/amount-error-type';

const fitFiatIconFn = (currency: TopUpInputInterface) => !currency.icon.startsWith(MOONPAY_ASSETS_BASE_URL);
const fitFiatIconFn = (currency: TopUpInputInterface) =>
!currency.icon.startsWith(MOONPAY_ASSETS_BASE_URL) && currency.icon !== FIAT_ICONS_SRC.UAH;

export const BuyWithCreditCard: FC = () => {
const dispatch = useDispatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ export const useBuyWithCreditCardForm = () => {
url = await createUtorgOrder(outputAmount, inputCurrency.code, publicKeyHash, outputToken.code);
break;
case TopUpProviderId.AliceBob:
const { data } = await createAliceBobOrder(false, inputAmount.toFixed(), userId, publicKeyHash);
const { data } = await createAliceBobOrder(
inputAmount.toFixed(),
inputCurrency.code,
outputToken.code,
userId,
publicKeyHash
);
url = data.orderInfo.payUrl;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const getOutputAmountFunctions: Record<TopUpProviderId, getOutputAmountFunction>
},
[TopUpProviderId.Utorg]: async (inputAmount, inputAsset, outputAsset) =>
convertFiatAmountToCrypto(inputAsset.code, outputAsset.code, inputAmount),
[TopUpProviderId.AliceBob]: async inputAmount => {
const response = await estimateAliceBobOutput(false, inputAmount.toString());
[TopUpProviderId.AliceBob]: async (inputAmount, inputAsset, outputAsset) => {
const response = await estimateAliceBobOutput(inputAmount.toString(), inputAsset.code, outputAsset.code);

return response.data.outputAmount;
}
Expand Down
Loading
Loading