Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add split subvariant #81

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"@types/big.js": "^6.1.6",
"@types/eslint": "^8.37.0",
"@types/events": "^3.0.0",
"@types/node": "^18.16.2",
"@types/node": "^18.16.3",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.1",
"@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"cpy-cli": "^4.2.0",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
Expand All @@ -46,7 +46,6 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"lerna": "^6.6.1",
"nx": "^15.9.3",
"prettier": "^2.8.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/widget-embedded/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@
"@lifi/wallet-management": "^2.0.0-beta.4",
"@lifi/widget": "^2.0.0-beta.5",
"@mui/icons-material": "^5.11.16",
"@mui/lab": "^5.0.0-alpha.128",
"@mui/material": "^5.12.2",
"@mui/lab": "^5.0.0-alpha.129",
"@mui/material": "^5.12.3",
"@opensea/seaport-js": "^1.2.0",
"@tanstack/react-query": "^4.29.5",
"bignumber.js": "^9.1.1",
"ethers": "^5.7.2",
"events": "^3.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.10.0",
"react-router-dom": "^6.11.0",
"web3": "^1.9.0"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@vitejs/plugin-react": "^4.0.0",
"buffer": "^6.0.3",
"esbuild": "^0.17.18",
"rollup": "^3.21.0",
"rollup": "^3.21.3",
"rollup-plugin-polyfill-node": "^0.12.0",
"typescript": "^5.0.4",
"vite": "^4.3.3",
"vite": "^4.3.4",
"web-vitals": "^3.3.1"
},
"eslintConfig": {
Expand Down
8 changes: 4 additions & 4 deletions packages/widget-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
"@lifi/wallet-management": "^2.0.0-beta.4",
"@lifi/widget": "^2.0.0-beta.5",
"@mui/icons-material": "^5.11.16",
"@mui/lab": "^5.0.0-alpha.128",
"@mui/material": "^5.12.2",
"@mui/lab": "^5.0.0-alpha.129",
"@mui/material": "^5.12.3",
"ethers": "^5.7.2",
"events": "^3.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.10.0"
"react-router-dom": "^6.11.0"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@vitejs/plugin-react": "^4.0.0",
"rollup-plugin-polyfill-node": "^0.12.0",
"typescript": "^5.0.4",
"vite": "^4.3.3",
"vite": "^4.3.4",
"web-vitals": "^3.3.1"
},
"eslintConfig": {
Expand Down
24 changes: 23 additions & 1 deletion packages/widget-playground/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StaticToken } from '@lifi/sdk';
import type { WidgetVariant } from '@lifi/widget';
import type { WidgetSubvariant, WidgetVariant } from '@lifi/widget';
import { LiFiWidget } from '@lifi/widget';
import {
Box,
Expand All @@ -25,6 +25,7 @@ import { WalletButtons } from './components/WalletButtons';
import { WidgetEvents } from './components/WidgetEvents';
import {
METAMASK_WALLET,
WidgetSubvariants,
WidgetVariants,
widgetBaseConfig,
widgetConfig,
Expand All @@ -44,6 +45,7 @@ export const App = () => {
const [variant, setVariant] = useState<WidgetVariant>(
searchParams.drawer ? 'drawer' : 'expandable',
);
const [subvariant, setSubvariant] = useState<WidgetSubvariant>('default');
const [fontFamily, setFontFamily] = useState('Inter var, Inter, sans-serif');
const [borderRadius, setBorderRadius] = useState(12);
const [borderRadiusSecondary, setBorderRadiusSecondary] = useState(8);
Expand Down Expand Up @@ -106,6 +108,7 @@ export const App = () => {
components: widgetConfig.theme?.components,
},
variant,
subvariant,
}));
}, [
borderRadius,
Expand All @@ -115,6 +118,7 @@ export const App = () => {
prefersDarkMode,
primary,
secondary,
subvariant,
systemColor,
variant,
]);
Expand Down Expand Up @@ -220,6 +224,24 @@ export const App = () => {
</Select>
</FormControl>
</Box>
<Box pb={2} flex={1}>
<FormControl size="small" fullWidth>
<InputLabel>Widget subvariant</InputLabel>
<Select
value={subvariant}
label="Widget subvariant"
onChange={(event) =>
setSubvariant(event.target.value as WidgetSubvariant)
}
>
{WidgetSubvariants.map((variant) => (
<MenuItem key={variant} value={variant}>
{variant}
</MenuItem>
))}
</Select>
</FormControl>
</Box>

<Box px={1} flex={1}>
<FormControlLabel
Expand Down
5 changes: 4 additions & 1 deletion packages/widget-playground/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const WidgetVariants = [
'refuel',
] as const;

export const WidgetSubvariants = ['default', 'split'] as const;

export const widgetBaseConfig: WidgetConfig = {
// fromChain: 137,
// toChain: 10,
Expand All @@ -22,8 +24,9 @@ export const widgetBaseConfig: WidgetConfig = {
// toAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',

variant: 'expandable',
// subvariant: 'split',
integrator: 'li.fi-playground',
// hiddenUI: ['poweredBy', 'language', 'appearance'],
// hiddenUI: ['poweredBy', 'language', 'appearance', 'drawerButton'],
chains: {
allow: [], // 1, 1285, 10, 56, 137
deny: [],
Expand Down
6 changes: 3 additions & 3 deletions packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"@lifi/sdk": "^2.0.0-beta.11",
"@lifi/wallet-management": "^2.0.0-beta.4",
"@mui/icons-material": "^5.11.16",
"@mui/lab": "^5.0.0-alpha.128",
"@mui/material": "^5.12.2",
"@mui/lab": "^5.0.0-alpha.129",
"@mui/material": "^5.12.3",
"@tanstack/react-query": "^4.29.5",
"@tanstack/react-virtual": "^3.0.0-beta.54",
"big.js": "^6.2.1",
Expand All @@ -70,7 +70,7 @@
"react-hook-form": "^7.43.9",
"react-i18next": "^12.2.2",
"react-intersection-observer": "^9.4.3",
"react-router-dom": "^6.10.0",
"react-router-dom": "^6.11.0",
"react-timer-hook": "^3.0.5",
"uuid": "^9.0.0",
"zustand": "^4.3.7"
Expand Down
25 changes: 16 additions & 9 deletions packages/widget/src/AppDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AppDefault } from './App';
import { DrawerButton, DrawerButtonTypography } from './AppDrawer.style';
import { AppProvider } from './AppProvider';
import type { WidgetConfig, WidgetProps } from './types';
import { HiddenUI } from './types';

export interface WidgetDrawer {
isOpen(): void;
Expand Down Expand Up @@ -64,15 +65,21 @@ export const AppDrawer = forwardRef<WidgetDrawer, WidgetProps>(

return (
<AppProvider config={widgetConfig}>
<DrawerButton
variant="contained"
onClick={toggleDrawer}
open={drawerOpen}
drawerProps={config?.containerStyle}
>
{drawerOpen ? <KeyboardArrowRightIcon /> : <KeyboardArrowLeftIcon />}
<DrawerButtonText open={drawerOpen} />
</DrawerButton>
{!widgetConfig.hiddenUI?.includes(HiddenUI.DrawerButton) ? (
<DrawerButton
variant="contained"
onClick={toggleDrawer}
open={drawerOpen}
drawerProps={config?.containerStyle}
>
{drawerOpen ? (
<KeyboardArrowRightIcon />
) : (
<KeyboardArrowLeftIcon />
)}
<DrawerButtonText open={drawerOpen} />
</DrawerButton>
) : null}
<Drawer
ref={elementRef}
anchor="right"
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const AppProvider: React.FC<PropsWithChildren<WidgetConfigProps>> = ({
}) => {
return (
<QueryClientProvider client={queryClient}>
<StoreProvider namePrefix={config?.localStorageKeyPrefix}>
<StoreProvider config={config}>
<WidgetProvider config={config}>
<SDKProvider>
<ThemeProvider>
Expand Down
8 changes: 7 additions & 1 deletion packages/widget/src/components/ChainSelect/useChainSelect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EVMChain } from '@lifi/sdk';
import { useController, useFormContext } from 'react-hook-form';
import { useChains } from '../../hooks';
import { useChains, useSwapOnly } from '../../hooks';
import type { SwapFormType } from '../../providers';
import { SwapFormKey, SwapFormKeyHelper } from '../../providers';
import { useChainOrder } from '../../stores';
Expand All @@ -13,6 +13,7 @@ export const useChainSelect = (formType: SwapFormType) => {
const { setValue } = useFormContext();
const { chains, isLoading } = useChains();
const [chainOrder, setChainOrder] = useChainOrder();
const swapOnly = useSwapOnly();

const getChains = () => {
if (!chains) {
Expand All @@ -28,6 +29,11 @@ export const useChainSelect = (formType: SwapFormType) => {
const setCurrentChain = (chainId: number) => {
onChange(chainId);
onBlur();
if (swapOnly) {
setValue(SwapFormKeyHelper.getChainKey('to'), chainId, {
shouldTouch: true,
});
}
setValue(SwapFormKeyHelper.getTokenKey(formType), '');
setValue(SwapFormKeyHelper.getAmountKey(formType), '');
setValue(SwapFormKey.TokenSearchFilter, '');
Expand Down
3 changes: 3 additions & 0 deletions packages/widget/src/components/Header/Header.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ export const WalletButton = styled(Button)(({ theme }) => ({
[`.${buttonClasses.endIcon} > *:nth-of-type(1)`]: {
fontSize: '24px',
},
[`.${buttonClasses.startIcon} > *:nth-of-type(1)`]: {
fontSize: '24px',
},
}));
6 changes: 3 additions & 3 deletions packages/widget/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FC, PropsWithChildren } from 'react';
import { useLocation } from 'react-router-dom';
import { useDefaultElementId } from '../../hooks';
import { useWidgetConfig } from '../../providers';
import { createElementId, ElementId, stickyHeaderRoutes } from '../../utils';
import { ElementId, createElementId, stickyHeaderRoutes } from '../../utils';
import { Container } from './Header.style';
import { NavigationHeader } from './NavigationHeader';
import { WalletHeader } from './WalletHeader';
Expand All @@ -21,10 +21,10 @@ export const HeaderContainer: FC<PropsWithChildren<{}>> = ({ children }) => {
};

export const Header: FC = () => {
const { walletManagement } = useWidgetConfig();
const { walletManagement, subvariant } = useWidgetConfig();
return (
<HeaderContainer>
{!walletManagement ? <WalletHeader /> : null}
{!walletManagement && subvariant !== 'split' ? <WalletHeader /> : null}
<NavigationHeader />
</HeaderContainer>
);
Expand Down
Loading