Skip to content

Commit

Permalink
fix:replace onramper to moonpay (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
linleiqin authored Feb 20, 2023
1 parent e6262ea commit 8bff2e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
12 changes: 6 additions & 6 deletions packages/kit-bg/src/services/ServiceToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,12 @@ export default class ServiceToken extends ServiceBase {
}) {
const { engine } = this.backgroundApi;
const tokens = await engine.getTokens(networkId);
if (type === 'buy') {
return tokens.filter((t) => {
const { onramperId } = t;
return typeof onramperId === 'string' && onramperId.length > 0;
});
}
// if (type === 'buy') {
// return tokens.filter((t) => {
// const { onramperId } = t;
// return typeof onramperId === 'string' && onramperId.length > 0;
// });
// }
return tokens.filter((t) => {
const { moonpayId } = t;
return typeof moonpayId === 'string' && moonpayId.length > 0;
Expand Down
24 changes: 15 additions & 9 deletions packages/kit/src/views/FiatPay/SupportTokenList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useMemo, useState } from 'react';

import { useNavigation, useRoute } from '@react-navigation/native';
import Fuse from 'fuse.js';
import { Spinner } from 'native-base';
import { useIntl } from 'react-intl';

import {
Expand Down Expand Up @@ -139,15 +140,15 @@ const TokenListCell: FC<ListCellProps> = ({
const buyAction = useCallback(async () => {
const signedUrl = await serviceFiatPay.getFiatPayUrl({
type,
cryptoCode: token.onramperId,
cryptoCode: token.moonpayId,
address,
});
if (signedUrl.length > 0) {
navigation.navigate(FiatPayRoutes.MoonpayWebViewModal, {
url: signedUrl,
});
}
}, [address, navigation, serviceFiatPay, token.onramperId, type]);
}, [address, navigation, serviceFiatPay, token.moonpayId, type]);
const sellAction = useCallback(async () => {
const signedUrl = await serviceFiatPay.getFiatPayUrl({
type,
Expand Down Expand Up @@ -197,9 +198,8 @@ export const SupportTokenList: FC = () => {
const intl = useIntl();
const route = useRoute<RouteProps>();
const { networkId, accountId, type = 'buy' } = route.params;
const { tokenList } = useFiatPayTokens(networkId, type);
const { tokenList, loading } = useFiatPayTokens(networkId, type);
const { account, network } = useActiveSideAccount({ networkId, accountId });

const [searchResult, updateSearchResult] = useState<Token[]>([]);
const [searchText, updateSearchText] = useState<string>('');

Expand All @@ -222,8 +222,15 @@ export const SupportTokenList: FC = () => {
[account?.address, accountId, network, networkId, type],
);

const ListEmptyComponent = useCallback(
() => (
const ListEmptyComponent = useCallback(() => {
if (loading) {
return (
<Box height="400px" justifyContent="center">
<Spinner size="lg" />
</Box>
);
}
return (
<Box>
<Empty
title={intl.formatMessage({
Expand All @@ -238,9 +245,8 @@ export const SupportTokenList: FC = () => {
icon="DatabaseMini"
/>
</Box>
),
[intl, type],
);
);
}, [intl, loading, type]);

const separator = useCallback(() => <Box h="8px" />, []);

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/views/Market/MarketDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const MarketDetailLayout: FC<MarketDetailLayoutProps> = ({
async (t: TokenType) => {
const signedUrl = await backgroundApiProxy.serviceFiatPay.getFiatPayUrl({
type: 'buy',
cryptoCode: t.onramperId,
cryptoCode: t.moonpayId,
});
if (signedUrl.length > 0) {
navigation.navigate(RootRoutes.Modal, {
Expand Down Expand Up @@ -292,7 +292,7 @@ const MarketDetailLayout: FC<MarketDetailLayoutProps> = ({
}}
/>
) : null}
{token?.onramperId ? (
{token?.moonpayId ? (
<PurchaseButton
onPress={() => {
buyAction(token);
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/views/TokenDetail/TokenInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ const TokenInfo: FC<TokenInfoProps> = ({ token, priceReady, sendAddress }) => {
balance: '0',
};

const buyEnable = !!(token?.onramperId && token?.onramperId?.length > 0);
const buyEnable = !!(token?.moonpayId && token?.moonpayId?.length > 0);
const sellEnable = !!(token?.moonpayId && token?.moonpayId?.length > 0);

const buyAction = useCallback(
async (t: TokenDO) => {
const signedUrl = await backgroundApiProxy.serviceFiatPay.getFiatPayUrl({
type: 'buy',
address: account?.address,
cryptoCode: t.onramperId,
cryptoCode: t.moonpayId,
});
if (signedUrl) {
navigation.navigate(RootRoutes.Modal, {
Expand All @@ -84,7 +84,7 @@ const TokenInfo: FC<TokenInfoProps> = ({ token, priceReady, sendAddress }) => {
const signedUrl = await backgroundApiProxy.serviceFiatPay.getFiatPayUrl({
type: 'sell',
address: account?.id,
cryptoCode: t.onramperId,
cryptoCode: t.moonpayId,
});
if (signedUrl) {
navigation.navigate(RootRoutes.Modal, {
Expand Down

0 comments on commit 8bff2e9

Please sign in to comment.