Skip to content

Commit b500bbb

Browse files
committed
use the new route for buy - fix deeplinks
1 parent 2e74bda commit b500bbb

File tree

14 files changed

+103
-103
lines changed

14 files changed

+103
-103
lines changed

src/components/modal/transact-menu/TransactMenu.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import SheetModal from '../base/sheet/SheetModal';
1818
import Icons from './TransactMenuIcons';
1919
import {useTranslation} from 'react-i18next';
2020
import {useAppDispatch, useAppSelector} from '../../../utils/hooks';
21-
import {WalletScreens} from '../../../navigation/wallet/WalletGroup';
2221
import {Analytics} from '../../../store/analytics/analytics.effects';
2322
import {sleep} from '../../../utils/helper-methods';
2423
import {css} from 'styled-components/native';
24+
import {ExternalServicesScreens} from '../../../navigation/services/ExternalServicesGroup';
2525

2626
const TransactButton = styled.View`
2727
justify-content: center;
@@ -136,12 +136,7 @@ const TransactModal = () => {
136136
context: 'TransactMenu',
137137
}),
138138
);
139-
navigation.navigate(WalletScreens.AMOUNT, {
140-
onAmountSelected: async (amount: string, setButtonState: any) => {
141-
navigation.navigate('BuyCryptoRoot', {
142-
amount: Number(amount),
143-
});
144-
},
139+
navigation.navigate(ExternalServicesScreens.ROOT_BUY_AND_SELL, {
145140
context: 'buyCrypto',
146141
});
147142
},

src/navigation/services/components/externalServicesOfferSelector.tsx

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,49 @@ const ExternalServicesOfferSelector: React.FC<
374374
_paymentMethod,
375375
);
376376

377+
BuyCryptoSupportedExchanges.forEach((exchange: BuyCryptoExchangeKey) => {
378+
if (offersDefault[exchange]) {
379+
offersDefault[exchange].fiatCurrency = getAvailableFiatCurrencies(
380+
exchange,
381+
).includes(fiatCurrency)
382+
? fiatCurrency
383+
: 'USD';
384+
385+
if (paymentMethod) {
386+
if (
387+
preSetPartner &&
388+
BuyCryptoSupportedExchanges.includes(preSetPartner)
389+
) {
390+
offersDefault[exchange].showOffer =
391+
preSetPartner === exchange
392+
? isPaymentMethodSupported(
393+
preSetPartner,
394+
paymentMethod,
395+
coin,
396+
chain,
397+
offersDefault[preSetPartner].fiatCurrency,
398+
country,
399+
) &&
400+
(!buyCryptoConfig?.[preSetPartner] ||
401+
!buyCryptoConfig?.[preSetPartner]?.removed)
402+
: false;
403+
} else {
404+
offersDefault[exchange].showOffer =
405+
isPaymentMethodSupported(
406+
exchange,
407+
paymentMethod,
408+
coin,
409+
chain,
410+
offersDefault[exchange].fiatCurrency,
411+
country,
412+
) &&
413+
(!buyCryptoConfig?.[exchange] ||
414+
!buyCryptoConfig?.[exchange]?.removed);
415+
}
416+
}
417+
}
418+
});
419+
377420
const [offers, setOffers] = useState(cloneDeep(offersDefault));
378421
const [selectedOffer, setSelectedOffer] = useState<CryptoOffer | undefined>();
379422
const [selectedOfferLoading, setSelectedOfferLoading] =
@@ -1462,49 +1505,6 @@ const ExternalServicesOfferSelector: React.FC<
14621505
};
14631506

14641507
const getBuyCryptoQuotes = (selectedWallet: Wallet) => {
1465-
BuyCryptoSupportedExchanges.forEach((exchange: BuyCryptoExchangeKey) => {
1466-
if (offersDefault[exchange]) {
1467-
offersDefault[exchange].fiatCurrency = getAvailableFiatCurrencies(
1468-
exchange,
1469-
).includes(fiatCurrency)
1470-
? fiatCurrency
1471-
: 'USD';
1472-
1473-
if (paymentMethod) {
1474-
if (
1475-
preSetPartner &&
1476-
BuyCryptoSupportedExchanges.includes(preSetPartner)
1477-
) {
1478-
offersDefault[exchange].showOffer =
1479-
preSetPartner === exchange
1480-
? isPaymentMethodSupported(
1481-
preSetPartner,
1482-
paymentMethod,
1483-
coin,
1484-
chain,
1485-
offersDefault[preSetPartner].fiatCurrency,
1486-
country,
1487-
) &&
1488-
(!buyCryptoConfig?.[preSetPartner] ||
1489-
!buyCryptoConfig?.[preSetPartner]?.removed)
1490-
: false;
1491-
} else {
1492-
offersDefault[exchange].showOffer =
1493-
isPaymentMethodSupported(
1494-
exchange,
1495-
paymentMethod,
1496-
coin,
1497-
chain,
1498-
offersDefault[exchange].fiatCurrency,
1499-
country,
1500-
) &&
1501-
(!buyCryptoConfig?.[exchange] ||
1502-
!buyCryptoConfig?.[exchange]?.removed);
1503-
}
1504-
}
1505-
}
1506-
});
1507-
15081508
const showedOffersCount = Object.values(cloneDeep(offers)).filter(
15091509
offer => offer.showOffer,
15101510
).length;

src/navigation/services/screens/BuyAndSellRoot.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ const BuyAndSellRoot = ({
500500
useEffect(() => {
501501
if (selectedOffer && buttonState !== 'loading' && !openingBrowser) {
502502
setContinueEnabled(true);
503+
} else {
504+
setContinueEnabled(false);
503505
}
504506
}, [selectedOffer, buttonState, openingBrowser]);
505507

@@ -546,7 +548,12 @@ const BuyAndSellRoot = ({
546548
if (!currency) {
547549
return;
548550
}
549-
updateAmount('0');
551+
if (fromAmount && !isNaN(fromAmount)) {
552+
// Valid fromAmount
553+
updateAmount(fromAmount.toString());
554+
} else {
555+
updateAmount('0');
556+
}
550557
// if added for dev (hot reload)
551558
if (
552559
!primaryIsFiat &&
@@ -617,8 +624,6 @@ const BuyAndSellRoot = ({
617624

618625
const initBuyCrypto = async () => {
619626
try {
620-
await sleep(100);
621-
dispatch(startOnGoingProcessModal('GENERAL_AWAITING'));
622627
const requestData: ExternalServicesConfigRequestParams = {
623628
currentLocationCountry: locationData?.countryShortCode,
624629
currentLocationState: locationData?.stateShortCode,
@@ -808,12 +813,14 @@ const BuyAndSellRoot = ({
808813
};
809814

810815
useMount(() => {
816+
dispatch(startOnGoingProcessModal('GENERAL_AWAITING'));
811817
if (context === 'buyCrypto') {
812818
try {
813819
initBuyCrypto();
814820
} catch (err: any) {
815821
const errStr = err instanceof Error ? err.message : JSON.stringify(err);
816822
logger.error(`[Buy] could not initialize view: ${errStr}`);
823+
dispatch(dismissOnGoingProcessModal());
817824
}
818825
} else if (context === 'sellCrypto') {
819826
// TODO initSellCrypto();
@@ -865,6 +872,13 @@ const BuyAndSellRoot = ({
865872
const goTo = (offer: CryptoOffer, paymentMethod: PaymentMethod): void => {
866873
setButtonState('loading');
867874
setOpeningBrowser(true);
875+
dispatch(
876+
BuyCryptoActions.updateBuyCryptoOpts({
877+
buyCryptoOpts: {
878+
selectedPaymentMethod: paymentMethod.method,
879+
},
880+
}),
881+
);
868882
switch (offer.key) {
869883
case 'banxa':
870884
goToBanxaBuyPage(offer, paymentMethod);

src/navigation/tabs/home/components/advertisements/AdvertisementsList.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import AdvertisementCard from './AdvertisementCard';
66
import {BoxShadow} from '../Styled';
77
import {useNavigation} from '@react-navigation/native';
88
import {useRequireKeyAndWalletRedirect} from '../../../../../utils/hooks/useRequireKeyAndWalletRedirect';
9-
import {WalletScreens} from '../../../../wallet/WalletGroup';
9+
import {ExternalServicesScreens} from '../../../../services/ExternalServicesGroup';
1010

1111
interface AdvertisementListProps {
1212
contentCards: ContentCard[];
@@ -27,12 +27,7 @@ const AdvertisementsList: React.FC<AdvertisementListProps> = props => {
2727
const navigation = useNavigation();
2828

2929
const buyCryptoCta = useRequireKeyAndWalletRedirect(() => {
30-
navigation.navigate(WalletScreens.AMOUNT, {
31-
onAmountSelected: (amount: string) => {
32-
navigation.navigate('BuyCryptoRoot', {
33-
amount: Number(amount),
34-
});
35-
},
30+
navigation.navigate(ExternalServicesScreens.ROOT_BUY_AND_SELL, {
3631
context: 'buyCrypto',
3732
});
3833
});

src/navigation/tabs/home/components/advertisements/DefaultAdvertisements.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const DefaultAdvertisements = (
5656
cardDescription: t(
5757
'Buy direct using your debit, credit card, or Apple Pay.',
5858
),
59-
url: `${APP_DEEPLINK_PREFIX}buy/50`,
59+
url: `${APP_DEEPLINK_PREFIX}buy/100`,
6060
openURLInWebView: false,
6161
},
6262
];

src/navigation/wallet/screens/AccountDetails.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ import {
167167
import {startOnGoingProcessModal} from '../../../store/app/app.effects';
168168
import {BWCErrorMessage} from '../../../constants/BWCError';
169169
import {BitpaySupportedTokenOptsByAddress} from '../../../constants/tokens';
170+
import {ExternalServicesScreens} from '../../services/ExternalServicesGroup';
170171

171172
export type AccountDetailsScreenParamList = {
172173
selectedAccountAddress: string;
@@ -1296,15 +1297,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
12961297
context: 'AccountDetails',
12971298
}),
12981299
);
1299-
navigation.navigate(WalletScreens.AMOUNT, {
1300-
onAmountSelected: async (
1301-
amount: string,
1302-
setButtonState: any,
1303-
) => {
1304-
navigation.navigate('BuyCryptoRoot', {
1305-
amount: Number(amount),
1306-
});
1307-
},
1300+
navigation.navigate(ExternalServicesScreens.ROOT_BUY_AND_SELL, {
13081301
context: 'buyCrypto',
13091302
});
13101303
},

src/navigation/wallet/screens/Backup.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import {OnboardingImage} from '../../onboarding/components/Containers';
1616
import haptic from '../../../components/haptic-feedback/haptic';
1717
import {showBottomNotificationModal} from '../../../store/app/app.actions';
1818
import {WalletGroupParamList, WalletScreens} from '../WalletGroup';
19-
import {Key, Wallet} from '../../../store/wallet/wallet.models';
19+
import {Key} from '../../../store/wallet/wallet.models';
2020
import {NavigationProp, useNavigation} from '@react-navigation/native';
2121
import {StackActions} from '@react-navigation/native';
2222
import {RootState} from '../../../store';
2323
import {NativeStackScreenProps} from '@react-navigation/native-stack';
2424
import {useThemeType} from '../../../utils/hooks/useThemeType';
2525
import {useTranslation} from 'react-i18next';
26+
import {ExternalServicesScreens} from '../../services/ExternalServicesGroup';
2627

2728
const BackupImage = {
2829
light: (
@@ -89,7 +90,9 @@ export const backupRedirect = ({
8990
} else if (context === 'swapCrypto' || context === 'swapTo') {
9091
navigation.navigate('SwapCryptoRoot');
9192
} else if (context === 'buyCrypto') {
92-
navigation.navigate('BuyCryptoRoot');
93+
navigation.navigate(ExternalServicesScreens.ROOT_BUY_AND_SELL, {
94+
context: 'buyCrypto',
95+
});
9396
} else {
9497
navigation.dispatch(StackActions.popToTop());
9598
navigation.dispatch(StackActions.push('KeyOverview', {id: key.id}));

src/navigation/wallet/screens/GlobalSelect.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,10 @@ const GlobalSelect: React.FC<GlobalSelectScreenProps | GlobalSelectProps> = ({
876876
params: {screen: 'Home'},
877877
},
878878
{
879-
name: 'BuyCryptoRoot',
879+
name: 'BuyAndSellRoot',
880880
params: {
881881
amount: 200,
882+
context: 'buyCrypto',
882883
},
883884
},
884885
],

src/navigation/wallet/screens/KeyOverview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ const KeyOverview = () => {
212212
const showArchaxBanner = useAppSelector(({APP}) => APP.showArchaxBanner);
213213
const [showKeyOptions, setShowKeyOptions] = useState(false);
214214
const [refreshing, setRefreshing] = useState(false);
215-
const {keys}: {keys: {[key: string]: Key}} = useAppSelector(({WALLET}) => WALLET);
215+
const {keys}: {keys: {[key: string]: Key}} = useAppSelector(
216+
({WALLET}) => WALLET,
217+
);
216218
const {rates} = useAppSelector(({RATE}) => RATE);
217219
const {defaultAltCurrency, hideAllBalances} = useAppSelector(({APP}) => APP);
218220
const linkedCoinbase = useAppSelector(

src/navigation/wallet/screens/WalletDetails.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import {getGiftCardIcons} from '../../../lib/gift-cards/gift-card';
138138
import {BillPayAccount} from '../../../store/shop/shop.models';
139139
import debounce from 'lodash.debounce';
140140
import ArchaxFooter from '../../../components/archax/archax-footer';
141+
import {ExternalServicesScreens} from '../../services/ExternalServicesGroup';
141142

142143
export type WalletDetailsScreenParamList = {
143144
walletId: string;
@@ -1164,15 +1165,13 @@ const WalletDetails: React.FC<WalletDetailsScreenProps> = ({route}) => {
11641165
chain: fullWalletObj.chain || '',
11651166
}),
11661167
);
1167-
navigation.navigate(WalletScreens.AMOUNT, {
1168-
onAmountSelected: async (amount: string) => {
1169-
navigation.navigate('BuyCryptoRoot', {
1170-
amount: Number(amount),
1171-
fromWallet: fullWalletObj,
1172-
});
1168+
navigation.navigate(
1169+
ExternalServicesScreens.ROOT_BUY_AND_SELL,
1170+
{
1171+
context: 'buyCrypto',
1172+
fromWallet: fullWalletObj,
11731173
},
1174-
context: 'buyCrypto',
1175-
});
1174+
);
11761175
},
11771176
}}
11781177
sell={{

0 commit comments

Comments
 (0)