Skip to content

Commit

Permalink
feat(widget): hide orders table (#4993)
Browse files Browse the repository at this point in the history
* feat: add widget option to hide orders table

* feat: use hideOrdersTable widget param

* fix: show orders button on SWAP form

* feat: add warning regarding the behaviour
  • Loading branch information
alfetopito authored Oct 17, 2024
1 parent ce3b5b8 commit 681fb20
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const scrollToMyOrders = () => {

export function TradeWidgetForm(props: TradeWidgetProps) {
const isInjectedWidgetMode = isInjectedWidget()
const { standaloneMode } = useInjectedWidgetParams()
const { standaloneMode, hideOrdersTable } = useInjectedWidgetParams()

const isAlternativeOrderModalVisible = useIsAlternativeOrderModalVisible()
const { pendingActivity } = useCategorizeRecentActivity()
Expand Down Expand Up @@ -113,6 +113,7 @@ export function TradeWidgetForm(props: TradeWidgetProps) {
const shouldShowMyOrdersButton =
!alternativeOrderModalVisible &&
(!isInjectedWidgetMode && isConnectedSwapMode ? isUpToLarge : true) &&
(isConnectedSwapMode || !hideOrdersTable) &&
((isConnectedSwapMode && standaloneMode !== true) ||
(isLimitOrderMode && isUpToLarge && isLimitOrdersUnlocked) ||
(isAdvancedMode && isUpToLarge && isAdvancedOrdersUnlocked))
Expand Down
16 changes: 11 additions & 5 deletions apps/cowswap-frontend/src/pages/AdvancedOrders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FillAdvancedOrdersDerivedStateUpdater,
SetupAdvancedOrderAmountsFromUrlUpdater,
} from 'modules/advancedOrders'
import { useInjectedWidgetParams } from 'modules/injectedWidget'
import { OrdersTableWidget, TabOrderTypes } from 'modules/ordersTable'
import * as styledEl from 'modules/trade/pure/TradePageLayout'
import {
Expand All @@ -19,6 +20,7 @@ import {
} from 'modules/twap'
import { TwapFormState } from 'modules/twap/pure/PrimaryActionButton/getTwapFormState'


export default function AdvancedOrdersPage() {
const { isUnlocked } = useAtomValue(advancedOrdersAtom)

Expand All @@ -32,6 +34,8 @@ export default function AdvancedOrdersPage() {

const advancedWidgetParams = { disablePriceImpact }

const { hideOrdersTable } = useInjectedWidgetParams()

return (
<>
<FillAdvancedOrdersDerivedStateUpdater slippage={twapSlippage} />
Expand All @@ -50,11 +54,13 @@ export default function AdvancedOrdersPage() {
</styledEl.PrimaryWrapper>

<styledEl.SecondaryWrapper>
<OrdersTableWidget
displayOrdersOnlyForSafeApp={true}
orderType={TabOrderTypes.ADVANCED}
orders={allEmulatedOrders}
/>
{!hideOrdersTable && (
<OrdersTableWidget
displayOrdersOnlyForSafeApp={true}
orderType={TabOrderTypes.ADVANCED}
orders={allEmulatedOrders}
/>
)}
</styledEl.SecondaryWrapper>
</styledEl.PageWrapper>
</>
Expand Down
15 changes: 10 additions & 5 deletions apps/cowswap-frontend/src/pages/LimitOrders/RegularLimitOrders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { useWalletInfo } from '@cowprotocol/wallet'

import { useOrders } from 'legacy/state/orders/hooks'

import { useInjectedWidgetParams } from 'modules/injectedWidget'
import { LimitOrdersWidget, useIsWidgetUnlocked } from 'modules/limitOrders'
import { OrdersTableWidget, TabOrderTypes } from 'modules/ordersTable'
import * as styledEl from 'modules/trade/pure/TradePageLayout'


export function RegularLimitOrders() {
const isUnlocked = useIsWidgetUnlocked()
const { chainId, account } = useWalletInfo()
const allLimitOrders = useOrders(chainId, account, UiOrderType.LIMIT)
const { hideOrdersTable } = useInjectedWidgetParams()

return (
<styledEl.PageWrapper isUnlocked={isUnlocked}>
Expand All @@ -19,11 +22,13 @@ export function RegularLimitOrders() {
</styledEl.PrimaryWrapper>

<styledEl.SecondaryWrapper>
<OrdersTableWidget
displayOrdersOnlyForSafeApp={false}
orderType={TabOrderTypes.LIMIT}
orders={allLimitOrders}
/>
{!hideOrdersTable && (
<OrdersTableWidget
displayOrdersOnlyForSafeApp={false}
orderType={TabOrderTypes.LIMIT}
orders={allLimitOrders}
/>
)}
</styledEl.SecondaryWrapper>
</styledEl.PageWrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function useWidgetParams(configuratorState: ConfiguratorState): CowSwapWi
disableToastMessages,
disableProgressBar,
hideBridgeInfo,
hideOrdersTable,
} = configuratorState

const themeColors = {
Expand Down Expand Up @@ -98,6 +99,7 @@ export function useWidgetParams(configuratorState: ConfiguratorState): CowSwapWi
}
: undefined,
hideBridgeInfo,
hideOrdersTable,
}

return params
Expand Down
12 changes: 12 additions & 0 deletions apps/widget-configurator/src/app/configurator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ export function Configurator({ title }: { title: string }) {
const [hideBridgeInfo, setHideBridgeInfo] = useState<boolean | undefined>(false)
const toggleHideBridgeInfo = useCallback(() => setHideBridgeInfo((curr) => !curr), [])

const [hideOrdersTable, setHideOrdersTable] = useState<boolean | undefined>(false)
const toggleHideOrdersTable = useCallback(() => setHideOrdersTable((curr) => !curr), [])

const LINKS = [
{ icon: <CodeIcon />, label: 'View embed code', onClick: () => handleDialogOpen() },
{ icon: <LanguageIcon />, label: 'Widget web', url: `https://cow.fi/widget/?${UTM_PARAMS}` },
Expand Down Expand Up @@ -177,6 +180,7 @@ export function Configurator({ title }: { title: string }) {
disableToastMessages,
disableProgressBar,
hideBridgeInfo,
hideOrdersTable,
}

const computedParams = useWidgetParams(state)
Expand Down Expand Up @@ -326,6 +330,14 @@ export function Configurator({ title }: { title: string }) {
</RadioGroup>
</FormControl>

<FormControl component="fieldset">
<FormLabel component="legend">Hide orders table:</FormLabel>
<RadioGroup row aria-label="mode" name="mode" value={hideOrdersTable} onChange={toggleHideOrdersTable}>
<FormControlLabel value="false" control={<Radio />} label="Show orders table" />
<FormControlLabel value="true" control={<Radio />} label="Hide orders table" />
</RadioGroup>
</FormControl>

{isDrawerOpen && (
<Fab
size="small"
Expand Down
1 change: 1 addition & 0 deletions apps/widget-configurator/src/app/configurator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export interface ConfiguratorState {
disableToastMessages: boolean
disableProgressBar: boolean
hideBridgeInfo: boolean | undefined
hideOrdersTable: boolean | undefined
}
9 changes: 8 additions & 1 deletion libs/widget-lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,17 @@ export interface CowSwapWidgetParams {
*/
hideBridgeInfo?: boolean

/**
* Option to hide orders table on LIMIT and TWAP forms.
*
* Warning! When `true`, users won't be able to see their LIMIT/TWAP order status or history, neither they'll be able to cancel active orders.
*/
hideOrdersTable?: boolean

/**
* Defines the widget mode.
* - `true` (standalone mode): The widget is standalone, so it will use its own Ethereum provider. The user can connect from within the widget.
* - `false` (dapp mode): The widget is embedded in a dapp which is responsible of providing the Ethereum provider. Therefore, there won't be a connect button in the widget as this should happen in the host app.
* - `false` (dapp mode): The widget is embedded in a dapp which is responsible for providing the Ethereum provider. Therefore, there won't be a connect button in the widget as this should happen in the host app.
*
* Defaults to standalone.
*/
Expand Down

0 comments on commit 681fb20

Please sign in to comment.