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 order id retrieve in checkout #4366

Merged
merged 5 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 19 additions & 9 deletions app/components/UI/FiatOnRampAggregator/Views/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Engine from '../../../../core/Engine';
import { toLowerCaseEquals } from '../../../../util/general';
import { protectWalletModalVisible } from '../../../../actions/user';
import {
callbackBaseUrl,
processAggregatorOrder,
aggregatorInitialFiatOrder,
} from '../orderProcessor/aggregator';
Expand All @@ -28,7 +27,8 @@ import ErrorViewWithReporting from '../components/ErrorViewWithReporting';
import { strings } from '../../../../../locales/i18n';

const CheckoutWebView = () => {
const { selectedAddress, selectedChainId, sdkError } = useFiatOnRampSDK();
const { selectedAddress, selectedChainId, sdkError, callbackBaseUrl } =
useFiatOnRampSDK();
const dispatch = useDispatch();
const [error, setError] = useState('');
const [key, setKey] = useState(0);
Expand Down Expand Up @@ -91,6 +91,22 @@ const CheckoutWebView = () => {
params?.provider.id,
navState?.url,
);

if (!orderId) {
const parsedUrl = parseUrl(navState?.url);
if (Object.keys(parsedUrl.query).length === 0) {
wachunei marked this conversation as resolved.
Show resolved Hide resolved
// There was no query params in the URL to parse
// Most likely the user clicked the X in Wyre widget
// @ts-expect-error navigation prop mismatch
navigation.dangerouslyGetParent()?.pop();
return;
}

throw new Error(
`Order ID could not be retrieved. Callback was ${navState?.url}`,
);
}

const transformedOrder = await processAggregatorOrder(
aggregatorInitialFiatOrder({
id: orderId,
Expand All @@ -115,13 +131,7 @@ const CheckoutWebView = () => {
getNotificationDetails(transformedOrder as any),
);
} catch (navStateError) {
const parsedUrl = parseUrl(navState?.url);
if (Object.keys(parsedUrl.query).length === 0) {
// @ts-expect-error navigation prop mismatch
navigation.dangerouslyGetParent()?.pop();
} else {
setError((navStateError as Error)?.message);
}
setError((navStateError as Error)?.message);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/FiatOnRampAggregator/Views/GetQuotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import StyledButton from '../../StyledButton';
import BaseListItem from '../../../Base/ListItem';
import { getFiatOnRampAggNavbar } from '../../Navbar';

import { callbackBaseUrl } from '../orderProcessor/aggregator';
import useInterval from '../../../hooks/useInterval';
import { strings } from '../../../../../locales/i18n';
import Device from '../../../../util/device';
Expand Down Expand Up @@ -183,6 +182,7 @@ const GetQuotes = () => {
selectedAddress,
selectedFiatCurrencyId,
appConfig,
callbackBaseUrl,
sdkError,
} = useFiatOnRampSDK();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,3 @@ export async function processAggregatorOrder(
return order;
}
}

export const callbackBaseUrl = 'https://dummy.url.metamask.io';
6 changes: 6 additions & 0 deletions app/components/UI/FiatOnRampAggregator/sdk/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface IFiatOnRampSDK {
selectedChainId: string;

appConfig: IFiatOnRampSDKConfig;
callbackBaseUrl: string;
}

interface IProviderProps<T> {
Expand All @@ -75,6 +76,10 @@ export const SDK = OnRampSdk.create(
},
);

export const callbackBaseUrl = isDevelopment
? 'https://on-ramp-content.metaswap-dev.codefi.network/regions/fake-callback'
: 'https://on-ramp-content.metaswap.codefi.network/regions/fake-callback';

const appConfig = {
POLLING_INTERVAL: 20000,
POLLING_INTERVAL_HIGHLIGHT: 10000,
Expand Down Expand Up @@ -180,6 +185,7 @@ export const FiatOnRampSDKProvider = ({
selectedChainId,

appConfig,
callbackBaseUrl,
};

return <SDKContext.Provider value={value || contextValue} {...props} />;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"react-native-gesture-handler/**/cross-fetch": "3.1.5"
},
"dependencies": {
"@consensys/on-ramp-sdk": "^1.0.2",
"@consensys/on-ramp-sdk": "^1.0.3",
"@exodus/react-native-payments": "git+https://github.com/MetaMask/react-native-payments.git#dbc8cbbed570892d2fea5e3d183bf243e062c1e5",
"@keystonehq/bc-ur-registry-eth": "^0.7.7",
"@keystonehq/metamask-airgapped-keyring": "^0.3.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1104,10 +1104,10 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@consensys/on-ramp-sdk@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@consensys/on-ramp-sdk/-/on-ramp-sdk-1.0.2.tgz#b450227649cfa9084fd9c4b2d0e098c8f4bc2ca3"
integrity sha512-9hIuRrCsrifwVV+kPkuTw8wIJODAczZgNbWHvPdaWMGy3Qv1rQ0O9bmLHiO56Wrym/U+2bBpCdiwPtMiJiKUHA==
"@consensys/on-ramp-sdk@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@consensys/on-ramp-sdk/-/on-ramp-sdk-1.0.3.tgz#92cc982d00cde4b3749ec5024ce67a4a74d5cbf2"
integrity sha512-1WRuInJ5WTt1NHFVejI7BgTCRhYAQAlOg0wd3l60dgD1NqS3KI3z6hUqve3EPZGq/R/0DbQ8vjxBPl/rRNNxDg==
dependencies:
async "^3.2.3"
axios "^0.21.0"
Expand Down