From b9cda2830cdda521f3bf74ef6b61f17e59da6d05 Mon Sep 17 00:00:00 2001 From: Alexandr Kazachenko Date: Wed, 25 Oct 2023 11:10:17 +0600 Subject: [PATCH] feat(widget): display embed code (#3264) --- .../configurator/controls/NetworkControl.tsx | 1 + .../src/app/configurator/embedDialog.tsx | 38 +++++++++-- .../hooks/useWidgetParamsAndSettings.ts | 52 ++++++++++++++ .../src/app/configurator/index.tsx | 68 ++++++------------- .../src/app/configurator/types.ts | 16 +++++ 5 files changed, 124 insertions(+), 51 deletions(-) create mode 100644 apps/widget-configurator/src/app/configurator/hooks/useWidgetParamsAndSettings.ts create mode 100644 apps/widget-configurator/src/app/configurator/types.ts diff --git a/apps/widget-configurator/src/app/configurator/controls/NetworkControl.tsx b/apps/widget-configurator/src/app/configurator/controls/NetworkControl.tsx index 5c4a84f396..f652b73a3c 100644 --- a/apps/widget-configurator/src/app/configurator/controls/NetworkControl.tsx +++ b/apps/widget-configurator/src/app/configurator/controls/NetworkControl.tsx @@ -13,6 +13,7 @@ export type NetworkOption = { export const NetworkOptions: NetworkOption[] = [ { chainId: SupportedChainId.MAINNET, label: 'Ethereum' }, { chainId: SupportedChainId.GNOSIS_CHAIN, label: 'Gnosis Chain' }, + { chainId: SupportedChainId.GOERLI, label: 'Goerli' }, ] export function NetworkControl({ state }: { state: [NetworkOption, Dispatch>] }) { diff --git a/apps/widget-configurator/src/app/configurator/embedDialog.tsx b/apps/widget-configurator/src/app/configurator/embedDialog.tsx index 6af1847b37..4332acc987 100644 --- a/apps/widget-configurator/src/app/configurator/embedDialog.tsx +++ b/apps/widget-configurator/src/app/configurator/embedDialog.tsx @@ -1,5 +1,7 @@ import { useEffect, useRef, useState } from 'react' +import { CowSwapWidgetParams, CowSwapWidgetSettings } from '@cowprotocol/widget-lib' + import Button from '@mui/material/Button' import Dialog, { DialogProps } from '@mui/material/Dialog' import DialogActions from '@mui/material/DialogActions' @@ -7,7 +9,17 @@ import DialogContent from '@mui/material/DialogContent' import DialogContentText from '@mui/material/DialogContentText' import DialogTitle from '@mui/material/DialogTitle' -export function EmbedDialog({ iframeUrl }: { iframeUrl: string }) { +const CodeStyles = { + whiteSpace: 'break-spaces', + fontSize: '13px', +} + +export interface EmbedDialogProps { + params: CowSwapWidgetParams + settings: CowSwapWidgetSettings +} + +export function EmbedDialog({ params, settings }: EmbedDialogProps) { const [open, setOpen] = useState(false) const [scroll, setScroll] = useState('paper') @@ -31,7 +43,25 @@ export function EmbedDialog({ iframeUrl }: { iframeUrl: string }) { } }, [open]) - const code = `