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
Fix issue with not possible to buy tokens
ost-ptk committed Nov 25, 2024
commit 6640b2371ae572397e13ef1c9aa024fefb0b9036
70 changes: 31 additions & 39 deletions src/apps/popup/pages/buy-cspr/index.tsx
Original file line number Diff line number Diff line change
@@ -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';

@@ -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();
@@ -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;

@@ -111,6 +119,7 @@ export const BuyCSPRPage = () => {
defaultCountry,
defaultCurrency,
defaultDepositAmount,
handleError,
isLoadingOnRampCountriesAndCurrencies,
navigate,
onRampCountriesAndCurrenciesError,
@@ -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,
@@ -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 = {

Unchanged files with check annotations Beta

export * from './paths';
export * from './types';

Check warning on line 2 in src/apps/signature-request/router/index.ts

GitHub Actions / build (18.x)

Dependency cycle via @libs/layout:1=>./layout-tab:5=>@libs/ui/components:4=>./account-list/account-list:37=>@background/create-open-window:11
export * from './use-typed-navigate';
export * from './use-typed-location';
import { ErrorLocationState } from '@libs/layout';

Check warning on line 1 in src/apps/signature-request/router/types.ts

GitHub Actions / build (18.x)

Dependency cycle via ./layout-tab:5=>@libs/ui/components:4=>./account-list/account-list:37=>@background/create-open-window:11=>@signature-request/router:3
export interface LocationState extends ErrorLocationState {}
import { useLocation } from 'react-router-dom';
import { LocationState } from './types';

Check warning on line 3 in src/apps/signature-request/router/use-typed-location.ts

GitHub Actions / build (18.x)

Dependency cycle via @libs/layout:1=>./layout-tab:5=>@libs/ui/components:4=>./account-list/account-list:37=>@background/create-open-window:11=>@signature-request/router:3
export function useTypedLocation() {
const location = useLocation();
import { To, useNavigate } from 'react-router-dom';
import { LocationState } from './types';

Check warning on line 3 in src/apps/signature-request/router/use-typed-navigate.ts

GitHub Actions / build (18.x)

Dependency cycle via @libs/layout:1=>./layout-tab:5=>@libs/ui/components:4=>./account-list/account-list:37=>@background/create-open-window:11=>@signature-request/router:3
export function useTypedNavigate() {
const navigate = useNavigate();
import { Windows, tabs, windows } from 'webextension-polyfill';
import { RouterPath } from '@signature-request/router';

Check warning on line 3 in src/background/create-open-window.ts

GitHub Actions / build (18.x)

Dependency cycle via ./types:2=>@libs/layout:1=>./layout-tab:5=>@libs/ui/components:4=>./account-list/account-list:37
export enum WindowApp {
ImportAccount = 'ImportAccount',
[askPermissionUrlData.domain, askPermissionUrlData.hash, params]
);
const makeSubmitLedgerAction = (transport?: LedgerTransport) => async () => {

Check warning on line 82 in src/hooks/use-ledger.ts

GitHub Actions / build (18.x)

The 'makeSubmitLedgerAction' function makes the dependencies of useEffect Hook (at line 170) change on every render. To fix this, wrap the definition of 'makeSubmitLedgerAction' in its own useCallback() Hook
if (!transport && !selectedTransportRef.current) {
selectedTransportRef.current = await getPreferredTransport();
}
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { createOpenWindow } from '@background/create-open-window';

Check warning on line 4 in src/hooks/use-window-manager.ts

GitHub Actions / build (18.x)

Dependency cycle via @signature-request/router:3=>./types:2=>@libs/layout:1=>./layout-tab:5=>@libs/ui/components:4=>./account-list/account-list:37
import { dispatchToMainStore } from '@background/redux/utils';
import {
windowIdChanged,
import React from 'react';
import {

Check warning on line 3 in src/libs/layout/error/content.tsx

GitHub Actions / build (18.x)

Dependency cycle via ./error:6=>./tab-page:22
ContentContainer,
IllustrationContainer,
OnboardingIllustrationContainer,
import { PasswordDoesNotExistError } from '@src/errors';
import { WindowErrorPage, createErrorLocationState } from '@libs/layout';

Check warning on line 5 in src/libs/layout/error/error-boundary.tsx

GitHub Actions / build (18.x)

Dependency cycle via ./error:6
interface Props {
children: ReactNode;
};
}
export * from './error-boundary';

Check warning on line 21 in src/libs/layout/error/index.ts

GitHub Actions / build (18.x)

Dependency cycle via @libs/layout:5
export * from './tab-page';
export * from './types';
export * from './window-page';