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

fix: fix issue with not possible to buy tokens #1098

Merged
Merged
Changes from all 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
70 changes: 31 additions & 39 deletions src/apps/popup/pages/buy-cspr/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IOnRampProvider,
IProviderSelectionData
} from 'casper-wallet-core/src/domain';
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

Expand Down Expand Up @@ -59,6 +59,7 @@ export const BuyCSPRPage = () => {
>([]);
const [selectedProvider, setSelectedProvider] =
useState<IOnRampProvider | null>(null);
const [providerUrl, setProviderUrl] = useState<string | null>(null);

const { t } = useTranslation();
const navigate = useTypedNavigate();
Expand All @@ -81,21 +82,28 @@ export const BuyCSPRPage = () => {
getOnRampProviderLocation
} = useGetOnRampProviders();

useEffect(() => {
if (onRampCountriesAndCurrenciesError) {
const handleError = useCallback(
(error: Error) => {
navigate(
ErrorPath,
createErrorLocationState({
errorHeaderText: t('Something went wrong'),
errorContentText:
onRampCountriesAndCurrenciesError.message ||
error.message ||
t(
'Please check browser console for error details, this will be a valuable for our team to fix the issue.'
),
errorPrimaryButtonLabel: t('Close'),
errorRedirectPath: RouterPath.Home
})
);
},
[navigate, t]
);

useEffect(() => {
if (onRampCountriesAndCurrenciesError) {
handleError(onRampCountriesAndCurrenciesError);
}
if (isLoadingOnRampCountriesAndCurrencies) return;

Expand All @@ -111,6 +119,7 @@ export const BuyCSPRPage = () => {
defaultCountry,
defaultCurrency,
defaultDepositAmount,
handleError,
isLoadingOnRampCountriesAndCurrencies,
navigate,
onRampCountriesAndCurrenciesError,
Expand Down Expand Up @@ -138,26 +147,12 @@ export const BuyCSPRPage = () => {
setBuyCSPRStep(BuyCSPRSteps.Provider);
}
},
onError: error => {
navigate(
ErrorPath,
createErrorLocationState({
errorHeaderText: t('Something went wrong'),
errorContentText:
error.message ||
t(
'Please check browser console for error details, this will be a valuable for our team to fix the issue.'
),
errorPrimaryButtonLabel: t('Close'),
errorRedirectPath: RouterPath.Home
})
);
}
onError: handleError
});
};

const handleSubmit = () => {
if (activeAccount && selectedProvider) {
useEffect(() => {
if (activeAccount?.publicKey && selectedProvider?.providerKey) {
const data: IProviderSelectionData = {
account: activeAccount.publicKey,
fiatCurrency: selectedCurrency.code,
Expand All @@ -169,27 +164,24 @@ export const BuyCSPRPage = () => {

getOnRampProviderLocation(data, {
onSuccess: providerLocation => {
window.open(providerLocation.location, '_blank');
setProviderUrl(providerLocation.location);
},
onError: error => {
console.error(error.message, 'provider selection request failed');

navigate(
ErrorPath,
createErrorLocationState({
errorHeaderText: t('Something went wrong'),
errorContentText:
error.message ||
t(
'Please check browser console for error details, this will be a valuable for our team to fix the issue.'
),
errorPrimaryButtonLabel: t('Close'),
errorRedirectPath: RouterPath.Home
})
);
}
onError: handleError
});
}
}, [
activeAccount?.publicKey,
selectedProvider?.providerKey,
selectedCurrency.code,
fiatAmount,
getOnRampProviderLocation,
handleError
]);

const handleSubmit = () => {
if (providerUrl) {
window.open(providerUrl, '_blank');
}
};

const content = {
Expand Down
Loading