-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathindex.tsx
141 lines (124 loc) · 4.42 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { useAtomValue } from 'jotai'
import { ReactNode } from 'react'
import { isSellOrder } from '@cowprotocol/common-utils'
import { Field } from 'legacy/state/types'
import { useAdvancedOrdersActions } from 'modules/advancedOrders/hooks/useAdvancedOrdersActions'
import { useAdvancedOrdersDerivedState } from 'modules/advancedOrders/hooks/useAdvancedOrdersDerivedState'
import { advancedOrdersSettingsAtom } from 'modules/advancedOrders/state/advancedOrdersSettingsAtom'
import { TradeWidget, TradeWidgetSlots, useReceiveAmountInfo, useTradePriceImpact } from 'modules/trade'
import { BulletListItem, UnlockWidgetScreen } from 'modules/trade/pure/UnlockWidgetScreen'
import { useTradeQuote } from 'modules/tradeQuote'
import { TWAP_LEARN_MORE_LINK } from 'modules/twap/const'
import { CurrencyInfo } from 'common/pure/CurrencyInputPanel/types'
import { useUpdateAdvancedOrdersRawState } from '../../hooks/useAdvancedOrdersRawState'
import { AdvancedOrdersSettings } from '../AdvancedOrdersSettings'
const TWAP_BULLET_LIST_CONTENT: BulletListItem[] = [
{ content: 'Get the Time-Weighted Average Price by splitting your large order into parts' },
{ content: 'Customize your order size, expiration, and number of parts' },
{ content: 'Receive surplus of your order' },
{ content: 'Reduce your slippage by breaking big orders into smaller ones' },
]
const UNLOCK_SCREEN = {
title: 'Unlock the Power of TWAP Orders',
subtitle: 'Begin with TWAP Today!',
orderType: 'TWAP',
buttonText: 'Unlock TWAP orders (BETA)',
// TODO: add actual link before deploy to PROD
buttonLink: TWAP_LEARN_MORE_LINK,
}
export type AdvancedOrdersWidgetParams = {
disablePriceImpact: boolean
}
export type AdvancedOrdersWidgetProps = {
updaters?: ReactNode
params: AdvancedOrdersWidgetParams
mapCurrencyInfo?: (info: CurrencyInfo) => CurrencyInfo
confirmContent: JSX.Element
children(warnings: ReactNode): ReactNode
}
export function AdvancedOrdersWidget({
children,
updaters,
params,
confirmContent,
mapCurrencyInfo,
}: AdvancedOrdersWidgetProps) {
const { disablePriceImpact } = params
const {
inputCurrency,
outputCurrency,
inputCurrencyAmount,
outputCurrencyAmount,
inputCurrencyBalance,
outputCurrencyBalance,
inputCurrencyFiatAmount,
outputCurrencyFiatAmount,
recipient,
orderKind,
isUnlocked,
} = useAdvancedOrdersDerivedState()
const actions = useAdvancedOrdersActions()
const { isLoading: isTradePriceUpdating } = useTradeQuote()
const { showRecipient } = useAtomValue(advancedOrdersSettingsAtom)
const priceImpact = useTradePriceImpact()
const receiveAmountInfo = useReceiveAmountInfo()
const updateAdvancedOrdersState = useUpdateAdvancedOrdersRawState()
const isSell = isSellOrder(orderKind)
const inputCurrencyInfo: CurrencyInfo = {
field: Field.INPUT,
currency: inputCurrency,
amount: inputCurrencyAmount,
isIndependent: isSell,
receiveAmountInfo: null,
balance: inputCurrencyBalance,
fiatAmount: inputCurrencyFiatAmount,
}
const outputCurrencyInfo: CurrencyInfo = {
field: Field.OUTPUT,
currency: outputCurrency,
amount: outputCurrencyAmount,
isIndependent: !isSell,
receiveAmountInfo,
balance: outputCurrencyBalance,
fiatAmount: outputCurrencyFiatAmount,
}
const slots: TradeWidgetSlots = {
settingsWidget: <AdvancedOrdersSettings />,
bottomContent(warnings) {
return children(warnings)
},
updaters,
lockScreen: isUnlocked ? undefined : (
<UnlockWidgetScreen
id="advanced-orders"
items={TWAP_BULLET_LIST_CONTENT}
buttonLink={UNLOCK_SCREEN.buttonLink}
title={UNLOCK_SCREEN.title}
subtitle={UNLOCK_SCREEN.subtitle}
orderType={UNLOCK_SCREEN.orderType}
buttonText={UNLOCK_SCREEN.buttonText}
handleUnlock={() => updateAdvancedOrdersState({ isUnlocked: true })}
/>
),
}
const tradeWidgetParams = {
recipient,
compactView: true,
showRecipient,
isTradePriceUpdating,
priceImpact,
disablePriceImpact,
}
return (
<TradeWidget
id="advanced-orders-page"
disableOutput={true}
slots={slots}
actions={actions}
params={tradeWidgetParams}
inputCurrencyInfo={mapCurrencyInfo ? mapCurrencyInfo(inputCurrencyInfo) : inputCurrencyInfo}
outputCurrencyInfo={mapCurrencyInfo ? mapCurrencyInfo(outputCurrencyInfo) : outputCurrencyInfo}
confirmModal={confirmContent}
/>
)
}