@@ -2,12 +2,9 @@ import type { PropTypes } from './Inputs.types';
2
2
3
3
import { i18n } from '@lingui/core' ;
4
4
import { SwapInput } from '@rango-dev/ui' ;
5
- import BigNumber from 'bignumber.js' ;
6
5
import React from 'react' ;
7
6
8
- import { SwitchFromAndToButton } from '../../components/SwitchFromAndTo' ;
9
7
import { errorMessages } from '../../constants/errors' ;
10
- import { ZERO } from '../../constants/numbers' ;
11
8
import {
12
9
PERCENTAGE_CHANGE_MAX_DECIMALS ,
13
10
PERCENTAGE_CHANGE_MIN_DECIMALS ,
@@ -16,51 +13,26 @@ import {
16
13
USD_VALUE_MAX_DECIMALS ,
17
14
USD_VALUE_MIN_DECIMALS ,
18
15
} from '../../constants/routing' ;
19
- import { useAppStore } from '../../store/AppStore' ;
20
16
import { useQuoteStore } from '../../store/quote' ;
21
17
import { getContainer } from '../../utils/common' ;
22
18
import { numberToString } from '../../utils/numbers' ;
23
19
import { getPriceImpact , getPriceImpactLevel } from '../../utils/quote' ;
24
20
import { canComputePriceImpact } from '../../utils/swap' ;
25
- import { formatBalance , isFetchingBalance } from '../../utils/wallets' ;
26
21
27
- import { Container , FromContainer } from './Inputs.styles' ;
22
+ import { Container , DestinationInputStyles } from './Inputs.styles' ;
23
+ import { SourceInput } from './SourceInput/SourceInput' ;
28
24
29
25
export function Inputs ( props : PropTypes ) {
30
26
const { fetchingQuote, fetchMetaStatus, onClickToken, isExpandable } = props ;
31
27
const {
32
- fromToken,
33
- fromBlockchain,
34
28
toToken,
35
29
toBlockchain,
36
- setInputAmount,
37
- sanitizeInputAmount,
38
30
inputAmount,
39
31
inputUsdValue,
40
32
outputAmount,
41
33
outputUsdValue,
42
34
selectedQuote,
43
35
} = useQuoteStore ( ) ;
44
- const { connectedWallets, getBalanceFor } = useAppStore ( ) ;
45
- const fromTokenBalance = fromToken ? getBalanceFor ( fromToken ) : null ;
46
- const fromTokenFormattedBalance =
47
- formatBalance ( fromTokenBalance ) ?. amount ?? '0' ;
48
-
49
- const fromBalanceAmount = fromTokenBalance
50
- ? new BigNumber ( fromTokenBalance . amount ) . shiftedBy (
51
- - fromTokenBalance . decimals
52
- )
53
- : ZERO ;
54
-
55
- const fetchingBalance =
56
- ! ! fromBlockchain &&
57
- isFetchingBalance ( connectedWallets , fromBlockchain . name ) ;
58
-
59
- const priceImpactInputCanNotBeComputed = ! canComputePriceImpact (
60
- selectedQuote ,
61
- inputAmount ,
62
- inputUsdValue
63
- ) ;
64
36
65
37
const priceImpactOutputCanNotBeComputed = ! canComputePriceImpact (
66
38
selectedQuote ,
@@ -75,63 +47,13 @@ export function Inputs(props: PropTypes) {
75
47
76
48
return (
77
49
< Container >
78
- < FromContainer >
79
- < SwapInput
80
- label = { i18n . t ( 'From' ) }
81
- id = "widget-swap-from"
82
- mode = "From"
83
- onInputChange = { setInputAmount }
84
- onInputBlur = { sanitizeInputAmount }
85
- balance = { fromTokenFormattedBalance }
86
- chain = { {
87
- displayName : fromBlockchain ?. displayName || '' ,
88
- image : fromBlockchain ?. logo ,
89
- } }
90
- token = { {
91
- displayName : fromToken ?. symbol || '' ,
92
- image : fromToken ?. image ,
93
- securityWarning : ! ! fromToken ?. warning ,
94
- } }
95
- onClickToken = { ( ) => onClickToken ( 'from' ) }
96
- price = { {
97
- value : inputAmount ,
98
- usdValue : priceImpactInputCanNotBeComputed
99
- ? undefined
100
- : numberToString (
101
- inputUsdValue ,
102
- USD_VALUE_MIN_DECIMALS ,
103
- USD_VALUE_MAX_DECIMALS
104
- ) ,
105
- realUsdValue : priceImpactInputCanNotBeComputed
106
- ? undefined
107
- : inputUsdValue ?. toString ( ) ,
108
- error : priceImpactInputCanNotBeComputed
109
- ? errorMessages ( ) . unknownPriceError . impactTitle
110
- : undefined ,
111
- } }
112
- disabled = { fetchMetaStatus === 'failed' }
113
- loading = { fetchMetaStatus === 'loading' }
114
- loadingBalance = { fetchingBalance }
115
- tooltipContainer = { getContainer ( ) }
116
- onSelectMaxBalance = { ( ) => {
117
- const tokenBalanceReal = numberToString (
118
- fromBalanceAmount ,
119
- fromTokenBalance ?. decimals
120
- ) ;
121
-
122
- // if a token hasn't any value, we will reset the input by setting an empty string.
123
- const nextInputAmount = ! ! fromTokenBalance ?. amount
124
- ? tokenBalanceReal . split ( ',' ) . join ( '' )
125
- : '' ;
126
-
127
- setInputAmount ( nextInputAmount ) ;
128
- } }
129
- anyWalletConnected = { connectedWallets . length > 0 }
130
- />
131
- < SwitchFromAndToButton />
132
- </ FromContainer >
50
+ < SourceInput onClickToken = { ( ) => onClickToken ( 'from' ) } />
133
51
< SwapInput
134
- sharpBottomStyle = { ! isExpandable && ( ! ! selectedQuote || fetchingQuote ) }
52
+ style = {
53
+ ! isExpandable && ( ! ! selectedQuote || fetchingQuote )
54
+ ? DestinationInputStyles
55
+ : undefined
56
+ }
135
57
label = { i18n . t ( 'To' ) }
136
58
mode = "To"
137
59
id = "widget-swap-to-input"
0 commit comments