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" ;
75import { useTranslation } from "react-i18next" ;
6+ import styled from "styled-components" ;
87import Text from "~/renderer/components/Text" ;
9- import { rgba } from "~/renderer/styles/helpers " ;
8+ import { context } from "~/renderer/drawers/Provider " ;
109import CheckCircleIcon from "~/renderer/icons/CheckCircle" ;
1110import ClockIcon from "~/renderer/icons/Clock" ;
1211import 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" ;
1513import { 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
1719const StatusTag = styled . div `
1820 display: flex;
@@ -27,6 +29,9 @@ const StatusTag = styled.div`
2729export type SectionProviderProps = {
2830 provider ?: string ,
2931 status ?: KYCStatus ,
32+ ratesState : RatesReducerState ,
33+ fromCurrency : $PropertyType < SwapSelectorStateType , "currency" > ,
34+ toCurrency : $PropertyType < SwapSelectorStateType , "currency" > ,
3035} ;
3136type 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 >
0 commit comments