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

Commit 89cbc0e

Browse files
committed
Move change rate drawer to provider section
1 parent bb79946 commit 89cbc0e

3 files changed

Lines changed: 64 additions & 48 deletions

File tree

src/renderer/screens/exchange/Swap2/Form/FormSummary/SectionProvider.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// @flow
2-
import React from "react";
3-
import SummaryLabel from "./SummaryLabel";
4-
import SummaryValue, { NoValuePlaceholder } from "./SummaryValue";
5-
import SummarySection from "./SummarySection";
6-
import styled from "styled-components";
2+
import type { KYCStatus } from "@ledgerhq/live-common/lib/exchange/swap/utils";
3+
import { getProviderName } from "@ledgerhq/live-common/lib/exchange/swap/utils";
4+
import React, { useContext, useMemo } from "react";
75
import { useTranslation } from "react-i18next";
6+
import styled from "styled-components";
87
import Text from "~/renderer/components/Text";
9-
import { rgba } from "~/renderer/styles/helpers";
8+
import { context } from "~/renderer/drawers/Provider";
109
import CheckCircleIcon from "~/renderer/icons/CheckCircle";
1110
import ClockIcon from "~/renderer/icons/Clock";
1211
import ExclamationCircleIcon from "~/renderer/icons/ExclamationCircle";
13-
import { getProviderName } from "@ledgerhq/live-common/lib/exchange/swap/utils";
14-
import type { KYCStatus } from "@ledgerhq/live-common/lib/exchange/swap/utils";
12+
import { rgba } from "~/renderer/styles/helpers";
1513
import { iconByProviderName } from "../../utils";
14+
import RatesDrawer from "../RatesDrawer";
15+
import SummaryLabel from "./SummaryLabel";
16+
import SummarySection from "./SummarySection";
17+
import SummaryValue, { NoValuePlaceholder } from "./SummaryValue";
1618

1719
const StatusTag = styled.div`
1820
display: flex;
@@ -27,6 +29,9 @@ const StatusTag = styled.div`
2729
export type SectionProviderProps = {
2830
provider?: string,
2931
status?: KYCStatus,
32+
ratesState: RatesReducerState,
33+
fromCurrency: $PropertyType<SwapSelectorStateType, "currency">,
34+
toCurrency: $PropertyType<SwapSelectorStateType, "currency">,
3035
};
3136
type ProviderStatusTagProps = {
3237
status: $NonMaybeType<$PropertyType<SectionProviderProps, "status">>,
@@ -53,19 +58,41 @@ const ProviderStatusTag = ({ status }: ProviderStatusTagProps) => {
5358
);
5459
};
5560

56-
const SectionProvider = ({ provider, status }: SectionProviderProps) => {
61+
const SectionProvider = ({
62+
provider,
63+
status,
64+
fromCurrency,
65+
toCurrency,
66+
ratesState,
67+
}: SectionProviderProps) => {
5768
const { t } = useTranslation();
5869
const ProviderIcon = provider && iconByProviderName[provider.toLowerCase()];
5970

71+
const { setDrawer } = useContext(context);
72+
const rates = ratesState.value;
73+
const handleChange = useMemo(
74+
() =>
75+
rates &&
76+
rates.length > 1 &&
77+
(() =>
78+
setDrawer(RatesDrawer, {
79+
fromCurrency,
80+
toCurrency,
81+
rates,
82+
provider,
83+
})),
84+
[setDrawer, rates, fromCurrency, toCurrency, provider],
85+
);
86+
6087
return (
6188
<SummarySection>
6289
<SummaryLabel label={t("swap2.form.details.label.provider")} />
6390
{(provider && (
6491
<div style={{ display: "flex", columnGap: "6px", alignItems: "center" }}>
65-
<SummaryValue value={getProviderName(provider)}>
92+
<SummaryValue value={getProviderName(provider)} handleChange={handleChange}>
93+
{status ? <ProviderStatusTag status={status} /> : null}
6694
{ProviderIcon && <ProviderIcon size={19} />}
6795
</SummaryValue>
68-
{status ? <ProviderStatusTag status={status} /> : null}
6996
</div>
7097
)) || (
7198
<SummaryValue>

src/renderer/screens/exchange/Swap2/Form/FormSummary/SectionRate.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
// @flow
2-
import React, { useContext, useMemo } from "react";
3-
import { useSelector } from "react-redux";
4-
import SummaryLabel from "./SummaryLabel";
5-
import SummaryValue, { NoValuePlaceholder } from "./SummaryValue";
6-
import { useTranslation } from "react-i18next";
7-
import IconLock from "~/renderer/icons/Lock";
8-
import IconLockOpen from "~/renderer/icons/LockOpen";
9-
import SummarySection from "./SummarySection";
10-
import { context } from "~/renderer/drawers/Provider";
11-
import RatesDrawer from "../RatesDrawer";
122
import type {
13-
SwapSelectorStateType,
143
RatesReducerState,
154
SwapDataType,
5+
SwapSelectorStateType,
166
} from "@ledgerhq/live-common/lib/exchange/swap/hooks";
17-
import Price from "~/renderer/components/Price";
18-
import { rateSelector, rateExpirationSelector } from "~/renderer/actions/swap";
19-
import CountdownTimer from "~/renderer/components/CountdownTimer";
20-
import Box from "~/renderer/components/Box";
7+
import React from "react";
8+
import { useTranslation } from "react-i18next";
9+
import { useSelector } from "react-redux";
10+
import { rateExpirationSelector, rateSelector } from "~/renderer/actions/swap";
2111
import AnimatedCountdown from "~/renderer/components/AnimatedCountdown";
12+
import Box from "~/renderer/components/Box";
13+
import CountdownTimer from "~/renderer/components/CountdownTimer";
14+
import Price from "~/renderer/components/Price";
15+
import IconLock from "~/renderer/icons/Lock";
16+
import IconLockOpen from "~/renderer/icons/LockOpen";
2217
import { ratesExpirationThreshold } from "~/renderer/reducers/swap";
18+
import SummaryLabel from "./SummaryLabel";
19+
import SummarySection from "./SummarySection";
20+
import SummaryValue, { NoValuePlaceholder } from "./SummaryValue";
2321

2422
type Props = {
2523
ratesState: RatesReducerState,
@@ -30,29 +28,14 @@ type Props = {
3028
};
3129
const SectionRate = ({ fromCurrency, toCurrency, ratesState, refetchRates, provider }: Props) => {
3230
const { t } = useTranslation();
33-
const { setDrawer } = useContext(context);
3431
const exchangeRate = useSelector(rateSelector);
3532
const ratesExpiration = useSelector(rateExpirationSelector);
36-
const rates = ratesState.value;
37-
const handleChange = useMemo(
38-
() =>
39-
rates &&
40-
rates.length > 1 &&
41-
(() =>
42-
setDrawer(RatesDrawer, {
43-
fromCurrency,
44-
toCurrency,
45-
rates,
46-
provider,
47-
})),
48-
[setDrawer, rates, fromCurrency, toCurrency, provider],
49-
);
5033

5134
const summaryValue =
5235
ratesState.status === "loading" ? (
5336
<NoValuePlaceholder />
5437
) : exchangeRate && fromCurrency && toCurrency ? (
55-
<SummaryValue handleChange={handleChange}>
38+
<SummaryValue>
5639
{ratesExpiration && exchangeRate.tradeMethod === "fixed" && ratesExpiration > Date.now() && (
5740
<Box horizontal alignItems="center" mr={2}>
5841
<Box mr={1}>

src/renderer/screens/exchange/Swap2/Form/FormSummary/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// @flow
2+
import type { SwapTransactionType } from "@ledgerhq/live-common/lib/exchange/swap/hooks";
23
import React, { useEffect, useState } from "react";
4+
import styled from "styled-components";
5+
import type { ThemedComponent } from "~/renderer/styles/StyleProvider";
6+
import SectionFees from "./SectionFees";
7+
import type { SectionProviderProps } from "./SectionProvider";
38
import SectionProvider from "./SectionProvider";
49
import SectionRate from "./SectionRate";
5-
import SectionFees from "./SectionFees";
610
import SectionTarget from "./SectionTarget";
7-
import type { ThemedComponent } from "~/renderer/styles/StyleProvider";
8-
import styled from "styled-components";
9-
import type { SwapTransactionType } from "@ledgerhq/live-common/lib/exchange/swap/hooks";
10-
import type { SectionProviderProps } from "./SectionProvider";
1111

1212
const Form: ThemedComponent<{}> = styled.section.attrs(({ ready }) => ({
1313
style: ready ? { opacity: 1, maxHeight: "100vh", overflow: "auto" } : {},
@@ -54,7 +54,13 @@ const SwapFormSummary = ({ swapTransaction, kycStatus, provider }: SwapFormSumma
5454

5555
return (
5656
<Form ready={hasFetchedRates}>
57-
<SectionProvider provider={provider} status={kycStatus} />
57+
<SectionProvider
58+
provider={provider}
59+
status={kycStatus}
60+
fromCurrency={fromCurrency}
61+
toCurrency={toCurrency}
62+
ratesState={ratesState}
63+
/>
5864
<SectionRate
5965
fromCurrency={fromCurrency}
6066
toCurrency={toCurrency}

0 commit comments

Comments
 (0)