Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

ENGB2C-104 Swap form #1877

Merged
merged 77 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
19a4c5f
LL-6623 integrate swap form v2 tab navigation
LFBarreto Aug 26, 2021
8e9a409
LL-6626 LL-6627 (SwapV2): integrate account selection
LFBarreto Aug 27, 2021
a156e02
LL-6625 (SwapFormV2): integrate form account and amount selection
LFBarreto Aug 30, 2021
a3642bb
in progress
LFBarreto Aug 31, 2021
e605ac6
(SwapFormV2): add in extra form inputs
LFBarreto Sep 1, 2021
5a422a2
in progress
LFBarreto Sep 2, 2021
402bb31
in progress
LFBarreto Sep 6, 2021
3518f15
in progress
LFBarreto Sep 6, 2021
53ed5b3
(SwapForm): currency selection fixes
LFBarreto Sep 6, 2021
d89a145
LL-6630 (SwapForm): integrate provider selection screen
LFBarreto Sep 10, 2021
e4df213
LL-7281 7280 LL-6632 Qa fixes
LFBarreto Sep 19, 2021
6802cb9
LL-6622 (Swap) No asset modal
LFBarreto Sep 19, 2021
a3d0c84
LL-7278 (Swap) disable cta if no rate or error
LFBarreto Sep 19, 2021
3a38d2b
LL 6631 swap form - select fees screen (#1906)
nparigi-ledger Sep 22, 2021
e332baa
cleanup
LFBarreto Sep 23, 2021
a136e04
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Sep 27, 2021
e9207ad
LL-6623 (SwapForm): integrate llc logic and clean everything up
LFBarreto Sep 29, 2021
fc1deff
fix lint
LFBarreto Sep 29, 2021
2ae7312
LL-6994 (Swap) add analytics events
LFBarreto Oct 4, 2021
664517c
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Oct 4, 2021
0b1ca0d
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Oct 12, 2021
f3c345e
LL-6889 LL-7281 LL-7330 LL-7178 LL-7125 LL-7077 (Swap): review and fixes
LFBarreto Oct 13, 2021
2188064
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Oct 29, 2021
cdc5ab5
fixes in progress
LFBarreto Oct 29, 2021
0f63196
install react navigation v6
JunichiSugiura Nov 2, 2021
9b99934
replace dangerouslyGetParent by getParent
valpinkman Nov 2, 2021
ed5695e
(Deeplink): update for v6 linking
LFBarreto Nov 2, 2021
0cbdac1
Merge branch 'LL-7937' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 2, 2021
fea7923
replace mode="modal" with new api
valpinkman Nov 2, 2021
e776e9e
Merge branch 'LL-7937' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 2, 2021
2fa2305
Remove useless dependency to hw-app-btc (#1962)
Oct 29, 2021
63dfee3
LL-7365 sunset stealthcoin (#1958)
gre Oct 29, 2021
ecccf4a
New translations common.json (Russian) (#1964)
gre Nov 2, 2021
df50ed7
Fix contrast of text colors in WebPlatformPlayer/InfoPanel (#1945)
ofreyssinet-ledger Nov 2, 2021
987f63f
update live-common
gre Nov 2, 2021
6d19297
remove header="modal" and update to new API
valpinkman Nov 2, 2021
057c124
(tab): update configs
LFBarreto Nov 2, 2021
b2d36a8
(Tab): remove height from style
LFBarreto Nov 2, 2021
2073ed3
remove tabBarVisible option
JunichiSugiura Nov 2, 2021
e15228f
downgrade react-native-tab-view due to FlatList issue
JunichiSugiura Nov 3, 2021
6d71733
(AnimatedHeaderView): fix initial height issue
LFBarreto Nov 3, 2021
59481db
Merge branch 'LL-7937' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 3, 2021
713768e
Revert "fixes in progress"
LFBarreto Nov 3, 2021
a778ca3
LL-7828 (Swap): fix rate expiration logic
LFBarreto Nov 3, 2021
be32afa
LL-7887 (Swap): capitalize provider name
LFBarreto Nov 3, 2021
c767b40
LL-7869 (Swap): issue during confimation step
LFBarreto Nov 3, 2021
7ff2e93
LL-7847 (SwapForm): fix padding in fees screen
LFBarreto Nov 12, 2021
ac7c522
LL-7281 (SwapForm): fix error message ellipsis
LFBarreto Nov 12, 2021
e29c390
LL-6625 (SwapForm): filter non swapable currencies on from selector
LFBarreto Nov 12, 2021
885e06d
LL-6631 (SwapForm): fix edit fees issue
LFBarreto Nov 12, 2021
ef8fb8a
LL-6994 (SwapForm): analytics page swap device history
LFBarreto Nov 12, 2021
6a09d30
LL-7846 (Swap form): use max should disabled from input
LFBarreto Nov 12, 2021
ee677f6
LL-6896 (Swap): change kyc pending wording
LFBarreto Nov 12, 2021
3caccbb
feat(swap): make target amount 'responsive' (#1973)
qd-qd Nov 12, 2021
debb42e
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 12, 2021
9499e89
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 25, 2021
fbfbb8e
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 26, 2021
d2083e0
fix: KeyboardView vertical offset (#2002)
qd-qd Nov 26, 2021
cee1c6b
LL-8168 (Swap): cta issue fix
LFBarreto Nov 26, 2021
85b6b79
Merge branch 'LL-6623' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Nov 26, 2021
e2c493b
LL-8169 (Swap): issue in default account selection
LFBarreto Nov 26, 2021
d27bad1
(Swap form): fix fees disabled
LFBarreto Dec 1, 2021
285484a
LL-6622 (SwapForm): no assets to swap fix issue
LFBarreto Dec 1, 2021
beb8ade
(SwapForm): fix some side effect issues
LFBarreto Dec 1, 2021
b9768c7
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Dec 1, 2021
cc3d0d6
LL-8169 (Swap): fix add account flow issue
LFBarreto Dec 20, 2021
15402bf
LL-7843 (Swap) input font size and some style issues
LFBarreto Dec 20, 2021
836b948
LL-7330 (Swap) fix send max value issue
LFBarreto Dec 20, 2021
a324210
(Swap) fix add account issue
LFBarreto Dec 22, 2021
3960a95
(Swap): fix default currency and default account reresh issue
LFBarreto Dec 23, 2021
ae1c65c
(Swap): fix default currency and default account reresh issue
LFBarreto Dec 23, 2021
c677679
(Swap): fix initial validation issue
LFBarreto Dec 24, 2021
55738ea
Merge branch 'develop' of github.com:LedgerHQ/ledger-live-mobile into…
LFBarreto Dec 24, 2021
78152b2
(Swap): remove legacy
LFBarreto Dec 24, 2021
326799f
(Swap): remove legacy
LFBarreto Dec 24, 2021
6fd08db
(Swap): cleanup legacy
LFBarreto Dec 24, 2021
3bd4c62
fix review
LFBarreto Jan 6, 2022
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"mock-android": "yarn android:mock && yarn android:install",
"staging-android": "yarn android:staging && yarn android:install",
"prettier": "prettier --write \"src/**/*.js\"",
"lint": "eslint src",
"lint": "eslint src --fix",
"flow": "flow",
"test": "yarn check --integrity && ./scripts/check-no-dups.sh && yarn lint --quiet",
"sync-flowtyped": "NODE_OPTIONS=--max_old_space_size=10000 flow-typed install -s -o && rm flow-typed/npm/axios_*",
Expand Down
38 changes: 36 additions & 2 deletions src/actions/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
sortAccountsComparatorFromOrder,
} from "@ledgerhq/live-common/lib/account";
import type { FlattenAccountsOptions } from "@ledgerhq/live-common/lib/account";
import type { TrackingPair } from "@ledgerhq/live-common/lib/countervalues/types";
import {
useCalculateCountervalueCallback as useCalculateCountervalueCallbackCommon,
useCountervaluesPolling,
useTrackingPairForAccounts,
} from "@ledgerhq/live-common/lib/countervalues/react";
import { useDistribution as useDistributionCommon } from "@ledgerhq/live-common/lib/portfolio/v2/react";
import { BehaviorSubject } from "rxjs";
import { reorderAccounts } from "./accounts";
import { accountsSelector } from "../reducers/accounts";
import {
Expand All @@ -22,6 +24,10 @@ import { clearBridgeCache } from "../bridge/cache";
import clearLibcore from "../helpers/clearLibcore";
import { flushAll } from "../components/DBSave";

const extraSessionTrackingPairsChanges: BehaviorSubject<
TrackingPair[],
> = new BehaviorSubject([]);

export function useDistribution() {
const accounts = useSelector(accountsSelector);
const to = useSelector(counterValueCurrencySelector);
Expand Down Expand Up @@ -116,8 +122,36 @@ export function useUserSettings() {
);
}

export function useTrackingPairs() {
export function addExtraSessionTrackingPair(trackingPair: TrackingPair) {
const value = extraSessionTrackingPairsChanges.value;
if (
!value.some(
tp => tp.from === trackingPair.from && tp.to === trackingPair.to,
)
)
extraSessionTrackingPairsChanges.next(value.concat(trackingPair));
}

export function useExtraSessionTrackingPair() {
const [extraSessionTrackingPair, setExtraSessionTrackingPair] = useState([]);

useEffect(() => {
const sub = extraSessionTrackingPairsChanges.subscribe(
setExtraSessionTrackingPair,
);
return () => sub && sub.unsubscribe();
}, []);

return extraSessionTrackingPair;
}

export function useTrackingPairs(): TrackingPair[] {
const accounts = useSelector(accountsSelector);
const countervalue = useSelector(counterValueCurrencySelector);
return useTrackingPairForAccounts(accounts, countervalue);
const trPairs = useTrackingPairForAccounts(accounts, countervalue);
const extraSessionTrackingPairs = useExtraSessionTrackingPair();
return useMemo(() => extraSessionTrackingPairs.concat(trPairs), [
extraSessionTrackingPairs,
trPairs,
]);
}
11 changes: 7 additions & 4 deletions src/components/ConfirmationModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Props = {|
confirmationTitle?: React$Node,
confirmationDesc?: React$Node,
Icon?: React$ComponentType<*>,
iconColor?: string,
image?: number,
confirmButtonText?: React$Node,
rejectButtonText?: React$Node,
Expand All @@ -41,12 +42,16 @@ class ConfirmationModal extends PureComponent<Props> {
rejectButtonText,
onConfirm,
Icon,
iconColor,
image,
alert,
hideRejectButton,
colors,
...rest
} = this.props;

const iColor = iconColor || colors.live;

return (
<BottomModal
id="ConfirmationModal"
Expand All @@ -56,10 +61,8 @@ class ConfirmationModal extends PureComponent<Props> {
{...rest}
>
{Icon && (
<View
style={[styles.icon, { backgroundColor: rgba(colors.live, 0.08) }]}
>
<Icon size={24} color={colors.live} />
<View style={[styles.icon, { backgroundColor: rgba(iColor, 0.08) }]}>
<Icon size={24} color={iColor} />
</View>
)}
{image && (
Expand Down
41 changes: 39 additions & 2 deletions src/components/CounterValue.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// @flow
import React, { useState, useCallback } from "react";
import React, { useState, useCallback, useMemo, useEffect } from "react";
import { BigNumber } from "bignumber.js";
import { useSelector } from "react-redux";
import type { Currency } from "@ledgerhq/live-common/lib/types";
import { useCalculate } from "@ledgerhq/live-common/lib/countervalues/react";
import {
useCalculate,
useCountervaluesPolling,
} from "@ledgerhq/live-common/lib/countervalues/react";
import { TouchableOpacity, StyleSheet } from "react-native";
import { Trans } from "react-i18next";
import { useTheme } from "@react-navigation/native";
import { counterValueCurrencySelector } from "../reducers/settings";
import {
useTrackingPairs,
addExtraSessionTrackingPair,
} from "../actions/general";
import CurrencyUnitValue from "./CurrencyUnitValue";
import LText from "./LText";
import Circle from "./Circle";
Expand Down Expand Up @@ -67,6 +74,36 @@ export default function CounterValue({
const value =
valueProp instanceof BigNumber ? valueProp.toNumber() : valueProp;
const counterValueCurrency = useSelector(counterValueCurrencySelector);

const trackingPairs = useTrackingPairs();
const cvPolling = useCountervaluesPolling();
const hasTrackingPair = useMemo(
() =>
trackingPairs.some(
tp => tp.from === currency && tp.to === counterValueCurrency,
),
[counterValueCurrency, currency, trackingPairs],
);

useEffect(() => {
let t;
if (!hasTrackingPair) {
addExtraSessionTrackingPair({ from: currency, to: counterValueCurrency });
t = setTimeout(cvPolling.poll, 2000); // poll after 2s to ensure debounced CV userSettings are effective after this update
}

return () => {
if (t) clearTimeout(t);
};
}, [
counterValueCurrency,
currency,
cvPolling,
cvPolling.poll,
hasTrackingPair,
trackingPairs,
]);

const countervalue = useCalculate({
from: currency,
to: counterValueCurrency,
Expand Down
5 changes: 4 additions & 1 deletion src/components/CurrencyInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Props = {
style?: *,
inputStyle?: *,
colors: *,
dynamicFontRatio?: number,
};

type State = {
Expand All @@ -68,6 +69,7 @@ class CurrencyInput extends PureComponent<Props, State> {
hasWarning: false,
autoFocus: false,
editable: true,
dynamicFontRatio: 0.75,
};

state = {
Expand Down Expand Up @@ -150,11 +152,12 @@ class CurrencyInput extends PureComponent<Props, State> {
editable,
placeholder,
colors,
dynamicFontRatio = 0.75,
} = this.props;
const { displayValue } = this.state;

// calculating an approximative font size
const screenWidth = Dimensions.get("window").width * 0.75;
const screenWidth = Dimensions.get("window").width * dynamicFontRatio;
const dynamicFontSize = Math.round(
clamp(
Math.sqrt((screenWidth * 32) / displayValue.length),
Expand Down
12 changes: 7 additions & 5 deletions src/components/FabActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow;
// @flow
import React from "react";

import { useTheme } from "@react-navigation/native";
Expand All @@ -12,8 +12,8 @@ import type { AccountLike, Account } from "@ledgerhq/live-common/lib/types";
import { isCurrencySupported } from "../screens/Exchange/coinifyConfig";

import {
swapSelectableCurrenciesSelector,
readOnlyModeEnabledSelector,
swapSelectableCurrenciesSelector,
} from "../reducers/settings";
import { accountsCountSelector } from "../reducers/accounts";
import { NavigatorName, ScreenName } from "../const";
Expand All @@ -37,9 +37,11 @@ function FabAccountActions({ account, parentAccount }: FabAccountActionsProps) {
const { colors } = useTheme();

const currency = getAccountCurrency(account);
const availableOnSwap = useSelector(state =>
swapSelectableCurrenciesSelector(state),
const swapSelectableCurrencies = useSelector(
swapSelectableCurrenciesSelector,
);
const availableOnSwap =
swapSelectableCurrencies.includes(currency.id) && account.balance.gt(0);
const readOnlyModeEnabled = useSelector(readOnlyModeEnabledSelector);

const canBeBought = isCurrencySupported(currency, "buy");
Expand Down Expand Up @@ -69,7 +71,7 @@ function FabAccountActions({ account, parentAccount }: FabAccountActionsProps) {
},
]
: []),
...(availableOnSwap.includes(currency.id)
...(availableOnSwap
? [
{
navigationParams: [
Expand Down
6 changes: 3 additions & 3 deletions src/components/InfoModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ type BulletItem = {

type InfoModalProps = ModalProps & {
id?: string,
title?: string | React$Element<*>,
desc?: string | React$Element<*>,
title?: React$Node,
desc?: React$Node,
bullets?: BulletItem[],
Icon?: React$ComponentType<*>,
withCancel?: boolean,
onContinue?: () => void,
children?: React$Node,
confirmLabel?: string | React$Element<*>,
confirmLabel?: React$Node,
confirmProps?: *,
};

Expand Down
16 changes: 13 additions & 3 deletions src/components/KeyboardView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// @flow
import React from "react";
import { KeyboardAvoidingView, Platform, NativeModules } from "react-native";
import {
KeyboardAvoidingView,
Platform,
NativeModules,
StatusBar,
} from "react-native";
import { useHeaderHeight } from "@react-navigation/elements";
import { HEIGHT as ExperimentalHeaderHeight } from "../screens/Settings/Experimental/ExperimentalHeader";
import useExperimental from "../screens/Settings/Experimental/useExperimental";

Expand All @@ -14,17 +20,21 @@ type Props = {
const KeyboardView = React.memo<Props>(
({ style = { flex: 1 }, children }: *) => {
const isExperimental = useExperimental();
const headerHeight = useHeaderHeight();

let behavior;
let keyboardVerticalOffset = isExperimental ? ExperimentalHeaderHeight : 0;
if (Platform.OS === "ios") {
keyboardVerticalOffset += DeviceInfo.isIPhoneX_deprecated ? 88 : 64;
behavior = "padding";
behavior = "height";
}

return (
<KeyboardAvoidingView
style={style}
keyboardVerticalOffset={keyboardVerticalOffset}
keyboardVerticalOffset={
headerHeight + StatusBar.currentHeight + keyboardVerticalOffset
}
behavior={behavior}
enabled
>
Expand Down
56 changes: 55 additions & 1 deletion src/components/RootNavigator/BaseNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ import RequestAccountNavigator from "./RequestAccountNavigator";
import VerifyAccount from "../../screens/VerifyAccount";
import PlatformApp from "../../screens/Platform/App";

import SwapFormSelectAccount from "../../screens/Swap/FormSelection/SelectAccountScreen";
import SwapFormSelectCurrency from "../../screens/Swap/FormSelection/SelectCurrencyScreen";
import SwapFormSelectFees from "../../screens/Swap/FormSelection/SelectFeesScreen";
import SwapFormSelectProviderRate from "../../screens/Swap/FormSelection/SelectProviderRateScreen";

export default function BaseNavigator() {
const { t } = useTranslation();
const { colors } = useTheme();
Expand Down Expand Up @@ -118,7 +123,56 @@ export default function BaseNavigator() {
<Stack.Screen
name={NavigatorName.Swap}
component={SwapNavigator}
options={{ headerShown: false }}
options={{
...stackNavigationConfig,
headerStyle: styles.headerNoShadow,
headerLeft: null,
title: t("transfer.swap.form.tab"),
}}
/>
<Stack.Screen
name={ScreenName.SwapV2FormSelectAccount}
component={SwapFormSelectAccount}
options={({ route }) => ({
headerTitle: () => (
<StepHeader
title={
route.params.target === "from"
? t("transfer.swap.form.from")
: t("transfer.swap.form.to")
}
/>
),
headerRight: null,
})}
/>
<Stack.Screen
name={ScreenName.SwapV2FormSelectCurrency}
component={SwapFormSelectCurrency}
options={{
headerTitle: () => <StepHeader title={t("transfer.swap.form.to")} />,
headerRight: null,
}}
/>
<Stack.Screen
name={ScreenName.SwapFormSelectProviderRate}
component={SwapFormSelectProviderRate}
options={{
headerTitle: () => (
<StepHeader title={t("transfer.swap.form.summary.method")} />
),
headerRight: null,
}}
/>
<Stack.Screen
name={ScreenName.SwapV2FormSelectFees}
component={SwapFormSelectFees}
options={{
headerTitle: () => (
<StepHeader title={t("transfer.swap.form.summary.fees")} />
),
headerRight: null,
}}
/>
<Stack.Screen
name={NavigatorName.Lending}
Expand Down
Loading