@lifi/widget 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +7 -0
- package/components/Header/Header.js +5 -1
- package/components/Header/Header.style.d.ts +1 -3
- package/components/Header/Header.style.js +5 -4
- package/components/Header/WalletHeader.js +19 -3
- package/components/SwapButton/SwapButton.js +9 -2
- package/package.json +13 -13
- package/providers/WalletProvider/WalletProvider.js +59 -18
- package/providers/WalletProvider/types.d.ts +2 -1
- package/types/widget.d.ts +11 -15
package/App.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
2
3
|
import { Route, Routes } from 'react-router-dom';
|
|
3
4
|
import { AppProvider } from './AppProvider';
|
|
4
5
|
import { AppContainer } from './components/AppContainer';
|
|
@@ -10,10 +11,16 @@ import { SelectWalletPage } from './pages/SelectWalletPage';
|
|
|
10
11
|
import { SettingsPage } from './pages/SettingsPage';
|
|
11
12
|
import { SwapPage } from './pages/SwapPage';
|
|
12
13
|
import { SwapRoutesPage } from './pages/SwapRoutesPage';
|
|
14
|
+
import { useWallet } from './providers/WalletProvider';
|
|
13
15
|
import { routes } from './utils/routes';
|
|
14
16
|
export const App = ({ config }) => {
|
|
15
17
|
return (_jsx(AppProvider, Object.assign({ config: config }, { children: _jsx(AppDefault, {}) })));
|
|
16
18
|
};
|
|
17
19
|
export const AppDefault = () => {
|
|
20
|
+
const { attemptEagerConnect } = useWallet();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
attemptEagerConnect();
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, []);
|
|
18
25
|
return (_jsxs(AppContainer, { children: [_jsx(Header, {}), _jsxs(Routes, { children: [_jsx(Route, { path: routes.home, element: _jsx(MainPage, {}) }), _jsx(Route, { path: routes.selectWallet, element: _jsx(SelectWalletPage, {}) }), _jsx(Route, { path: routes.settings, element: _jsx(SettingsPage, {}) }), _jsx(Route, { path: routes.fromToken, element: _jsx(SelectTokenPage, { formType: "from" }) }), _jsx(Route, { path: routes.toToken, element: _jsx(SelectTokenPage, { formType: "to" }) }), _jsx(Route, { path: routes.swapRoutes, element: _jsx(SwapRoutesPage, {}) }), _jsx(Route, { path: `${routes.swapRoutes}/${routes.swap}`, element: _jsx(SwapPage, {}) }), _jsx(Route, { path: routes.swap, element: _jsx(SwapPage, {}) })] }), _jsx(Initializer, {})] }));
|
|
19
26
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useWidgetConfig } from '@lifi/widget/providers/WidgetProvider';
|
|
2
3
|
import { useLocation } from 'react-router-dom';
|
|
3
4
|
import { ElementId } from '../../utils/elements';
|
|
4
5
|
import { routes } from '../../utils/routes';
|
|
@@ -14,4 +15,7 @@ const HeaderContainer = ({ children }) => {
|
|
|
14
15
|
const { pathname } = useLocation();
|
|
15
16
|
return (_jsx(Container, Object.assign({ id: ElementId.Header, sticky: stickyHeaderRoutes.some((route) => pathname.includes(route)) }, { children: children })));
|
|
16
17
|
};
|
|
17
|
-
export const Header = () =>
|
|
18
|
+
export const Header = () => {
|
|
19
|
+
const { walletManagement } = useWidgetConfig();
|
|
20
|
+
return (_jsxs(HeaderContainer, { children: [!walletManagement ? _jsx(WalletHeader, {}) : null, _jsx(NavigationHeader, {})] }));
|
|
21
|
+
};
|
|
@@ -7,9 +7,7 @@ export declare const HeaderAppBar: import("@emotion/styled").StyledComponent<Omi
|
|
|
7
7
|
sx?: import("@mui/material").SxProps<import("@mui/material").Theme> | undefined;
|
|
8
8
|
} & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, keyof import("react").HTMLAttributes<HTMLElement> | "key"> & {
|
|
9
9
|
ref?: ((instance: HTMLElement | null) => void) | import("react").RefObject<HTMLElement> | null | undefined;
|
|
10
|
-
}, keyof import("@mui/material/OverridableComponent").CommonProps | "slot" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "ref" | "key" | "position" | "variant" | "square" | "elevation" | "enableColorOnDark"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme
|
|
11
|
-
pt?: number | undefined;
|
|
12
|
-
}, {}, {}>;
|
|
10
|
+
}, keyof import("@mui/material/OverridableComponent").CommonProps | "slot" | "title" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "children" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "sx" | "ref" | "key" | "position" | "variant" | "square" | "elevation" | "enableColorOnDark"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
13
11
|
export declare const Container: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material").Theme> & {
|
|
14
12
|
children?: import("react").ReactNode;
|
|
15
13
|
component?: import("react").ElementType<any> | undefined;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { AppBar, Box } from '@mui/material';
|
|
2
2
|
import { styled } from '@mui/material/styles';
|
|
3
|
-
export const HeaderAppBar = styled(AppBar
|
|
4
|
-
shouldForwardProp: (prop) => prop !== 'pt',
|
|
5
|
-
})(({ theme, pt }) => ({
|
|
3
|
+
export const HeaderAppBar = styled(AppBar)(({ theme }) => ({
|
|
6
4
|
backgroundColor: theme.palette.background.default,
|
|
7
5
|
color: theme.palette.text.primary,
|
|
8
6
|
flexDirection: 'row',
|
|
9
7
|
alignItems: 'center',
|
|
10
8
|
position: 'relative',
|
|
11
9
|
minHeight: 48,
|
|
12
|
-
padding: theme.spacing(
|
|
10
|
+
padding: theme.spacing(0, 3, 0, 3),
|
|
11
|
+
'&:first-of-type': {
|
|
12
|
+
paddingTop: theme.spacing(1.5),
|
|
13
|
+
},
|
|
13
14
|
}));
|
|
14
15
|
export const Container = styled(Box, {
|
|
15
16
|
shouldForwardProp: (prop) => prop !== 'sticky',
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
11
|
import { AccountBalanceWallet as AccountBalanceWalletIcon, Logout as LogoutIcon, } from '@mui/icons-material';
|
|
3
12
|
import { Box, IconButton, Typography } from '@mui/material';
|
|
4
13
|
import { useTranslation } from 'react-i18next';
|
|
5
14
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
6
15
|
import { useWallet } from '../../providers/WalletProvider';
|
|
16
|
+
import { useWidgetConfig } from '../../providers/WidgetProvider';
|
|
7
17
|
import { routes } from '../../utils/routes';
|
|
8
18
|
import { HeaderAppBar } from './Header.style';
|
|
9
19
|
export const WalletHeader = () => {
|
|
@@ -12,7 +22,7 @@ export const WalletHeader = () => {
|
|
|
12
22
|
const walletAddress = account.address
|
|
13
23
|
? `${account.address.substring(0, 7)}...${account.address.substring(account.address.length - 7)}`
|
|
14
24
|
: null;
|
|
15
|
-
return (_jsx(HeaderAppBar, Object.assign({ elevation: 0
|
|
25
|
+
return (_jsx(HeaderAppBar, Object.assign({ elevation: 0 }, { children: walletAddress ? (_jsxs(_Fragment, { children: [_jsxs(Box, Object.assign({ sx: {
|
|
16
26
|
display: 'flex',
|
|
17
27
|
flex: 1,
|
|
18
28
|
flexDirection: 'column',
|
|
@@ -20,9 +30,15 @@ export const WalletHeader = () => {
|
|
|
20
30
|
};
|
|
21
31
|
const ConnectButton = () => {
|
|
22
32
|
const { pathname } = useLocation();
|
|
33
|
+
const config = useWidgetConfig();
|
|
34
|
+
const { connect: walletConnect } = useWallet();
|
|
23
35
|
const navigate = useNavigate();
|
|
24
|
-
const connect = () => {
|
|
36
|
+
const connect = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
if (config.walletManagement) {
|
|
38
|
+
yield walletConnect();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
25
41
|
navigate(routes.selectWallet);
|
|
26
|
-
};
|
|
42
|
+
});
|
|
27
43
|
return (_jsx(IconButton, Object.assign({ size: "medium", "aria-label": "disconnect", edge: "end", onClick: !pathname.includes(routes.selectWallet) ? connect : undefined }, { children: _jsx(AccountBalanceWalletIcon, {}) })));
|
|
28
44
|
};
|
|
@@ -15,6 +15,7 @@ import { useNavigate } from 'react-router-dom';
|
|
|
15
15
|
import { useChains, useHasSufficientBalance, useSwapRoutes } from '../../hooks';
|
|
16
16
|
import { SwapFormKeyHelper } from '../../providers/SwapFormProvider';
|
|
17
17
|
import { useWallet } from '../../providers/WalletProvider';
|
|
18
|
+
import { useWidgetConfig } from '../../providers/WidgetProvider';
|
|
18
19
|
import { useCurrentRoute, useSetExecutableRoute } from '../../stores';
|
|
19
20
|
import { routes } from '../../utils/routes';
|
|
20
21
|
import { ButtonTooltip } from './ButtonTooltip';
|
|
@@ -24,7 +25,8 @@ export const SwapButton = () => {
|
|
|
24
25
|
const navigate = useNavigate();
|
|
25
26
|
const { t } = useTranslation();
|
|
26
27
|
const { getChainById } = useChains();
|
|
27
|
-
const
|
|
28
|
+
const config = useWidgetConfig();
|
|
29
|
+
const { account, switchChain, connect: walletConnect } = useWallet();
|
|
28
30
|
const [currentRoute] = useCurrentRoute();
|
|
29
31
|
const setExecutableRoute = useSetExecutableRoute();
|
|
30
32
|
const { routes: swapRoutes, isLoading, isFetching } = useSwapRoutes();
|
|
@@ -35,7 +37,12 @@ export const SwapButton = () => {
|
|
|
35
37
|
const isCurrentChainMatch = ((_a = getChainById(chainId || ChainId.ETH)) === null || _a === void 0 ? void 0 : _a.id) === account.chainId;
|
|
36
38
|
const handleSwapButtonClick = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
39
|
if (!account.isActive) {
|
|
38
|
-
|
|
40
|
+
if (config.walletManagement) {
|
|
41
|
+
yield walletConnect();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
navigate(routes.selectWallet);
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
else if (!isCurrentChainMatch) {
|
|
41
48
|
yield switchChain(chainId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./index.js",
|
|
@@ -39,22 +39,22 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@emotion/react": "^11.9.3",
|
|
41
41
|
"@emotion/styled": "^11.9.3",
|
|
42
|
-
"@ethersproject/experimental": "^5.6.
|
|
42
|
+
"@ethersproject/experimental": "^5.6.3",
|
|
43
43
|
"@ethersproject/providers": "^5.6.8",
|
|
44
|
-
"@lifi/wallet-management": "^1.0.
|
|
44
|
+
"@lifi/wallet-management": "^1.0.4",
|
|
45
45
|
"@lifinance/sdk": "^1.0.0-beta.11",
|
|
46
|
-
"@mui/icons-material": "^5.8.
|
|
47
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
48
|
-
"@mui/material": "^5.8.
|
|
46
|
+
"@mui/icons-material": "^5.8.4",
|
|
47
|
+
"@mui/lab": "^5.0.0-alpha.87",
|
|
48
|
+
"@mui/material": "^5.8.5",
|
|
49
49
|
"big.js": "^6.2.0",
|
|
50
|
-
"i18next": "^21.8.
|
|
51
|
-
"immer": "^9.0.
|
|
52
|
-
"react": "^18.
|
|
53
|
-
"react-dom": "^18.
|
|
54
|
-
"react-hook-form": "^7.
|
|
55
|
-
"react-i18next": "^11.17.
|
|
50
|
+
"i18next": "^21.8.11",
|
|
51
|
+
"immer": "^9.0.15",
|
|
52
|
+
"react": "^18.2.0",
|
|
53
|
+
"react-dom": "^18.2.0",
|
|
54
|
+
"react-hook-form": "^7.33.0",
|
|
55
|
+
"react-i18next": "^11.17.3",
|
|
56
56
|
"react-query": "^4.0.0-beta.23",
|
|
57
|
-
"react-resize-detector": "^7.1.
|
|
57
|
+
"react-resize-detector": "^7.1.2",
|
|
58
58
|
"react-router-dom": "^6.3.0",
|
|
59
59
|
"react-timer-hook": "^3.0.5",
|
|
60
60
|
"react-virtual": "^2.10.4",
|
|
@@ -20,63 +20,104 @@ const initialContext = {
|
|
|
20
20
|
switchChain: stub,
|
|
21
21
|
addChain: stub,
|
|
22
22
|
addToken: stub,
|
|
23
|
+
attemptEagerConnect: stub,
|
|
23
24
|
account: {},
|
|
24
25
|
};
|
|
25
26
|
const WalletContext = createContext(initialContext);
|
|
26
27
|
export const useWallet = () => useContext(WalletContext);
|
|
27
28
|
export const WalletProvider = ({ children }) => {
|
|
29
|
+
var _a;
|
|
28
30
|
const config = useWidgetConfig();
|
|
29
31
|
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, } = useLifiWalletManagement();
|
|
30
32
|
const [account, setAccount] = useState({});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
var _a;
|
|
35
|
+
console.log('WalletProvider: signer changed.', (_a = config.walletManagement) === null || _a === void 0 ? void 0 : _a.signer);
|
|
36
|
+
const updateSigner = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _b;
|
|
38
|
+
const account = yield extractAccountFromSigner((_b = config.walletManagement) === null || _b === void 0 ? void 0 : _b.signer);
|
|
39
|
+
setAccount(account);
|
|
40
|
+
console.log('WalletProvider: signer changed account.', account);
|
|
41
|
+
});
|
|
42
|
+
updateSigner();
|
|
43
|
+
}, [(_a = config.walletManagement) === null || _a === void 0 ? void 0 : _a.signer]);
|
|
31
44
|
const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
if (config.
|
|
33
|
-
|
|
45
|
+
if (config.walletManagement) {
|
|
46
|
+
const signer = yield config.walletManagement.connect();
|
|
47
|
+
const account = yield extractAccountFromSigner(signer);
|
|
48
|
+
setAccount(account);
|
|
34
49
|
return;
|
|
35
50
|
}
|
|
36
51
|
yield walletManagementConnect(wallet);
|
|
37
|
-
}), [config.
|
|
52
|
+
}), [config.walletManagement, walletManagementConnect]);
|
|
38
53
|
const disconnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
if (config.
|
|
54
|
+
if (config.walletManagement) {
|
|
55
|
+
yield config.walletManagement.disconnect();
|
|
40
56
|
setAccount({});
|
|
57
|
+
return;
|
|
41
58
|
}
|
|
42
59
|
yield walletManagementDisconnect();
|
|
43
|
-
}), [config.
|
|
60
|
+
}), [config.walletManagement, walletManagementDisconnect]);
|
|
44
61
|
// only for injected wallets
|
|
45
62
|
const switchChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
if (config.
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
if (config.walletManagement) {
|
|
64
|
+
const signer = yield config.walletManagement.switchChain(chainId);
|
|
65
|
+
const account = yield extractAccountFromSigner(signer);
|
|
66
|
+
setAccount(account);
|
|
49
67
|
}
|
|
50
68
|
return walletSwitchChain(chainId);
|
|
51
|
-
}), [config.
|
|
69
|
+
}), [config.walletManagement]);
|
|
52
70
|
const addChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
-
if (
|
|
54
|
-
|
|
71
|
+
if (config.walletManagement) {
|
|
72
|
+
return config.walletManagement.addChain(chainId);
|
|
55
73
|
}
|
|
56
|
-
|
|
74
|
+
return walletAddChain(chainId);
|
|
75
|
+
}), [config.walletManagement]);
|
|
57
76
|
const addToken = useCallback((chainId, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
if (
|
|
59
|
-
|
|
77
|
+
if (config.walletManagement) {
|
|
78
|
+
return config.walletManagement.addToken(token, chainId);
|
|
79
|
+
}
|
|
80
|
+
return switchChainAndAddToken(chainId, token);
|
|
81
|
+
}), [config.walletManagement]);
|
|
82
|
+
const attemptEagerConnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
if (config.walletManagement) {
|
|
84
|
+
try {
|
|
85
|
+
const signer = yield config.walletManagement.getSigner();
|
|
86
|
+
const account = yield extractAccountFromSigner(signer);
|
|
87
|
+
setAccount(() => (Object.assign({}, account)));
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
console.warn('WalletProvider: attempted eager connect.', e);
|
|
91
|
+
}
|
|
60
92
|
}
|
|
61
|
-
}), [config.
|
|
93
|
+
}), [config.walletManagement]);
|
|
62
94
|
// keep account information up to date
|
|
63
95
|
useEffect(() => {
|
|
64
96
|
const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
if (!config.
|
|
97
|
+
if (!config.walletManagement) {
|
|
66
98
|
const account = yield extractAccountFromSigner(signer);
|
|
67
99
|
setAccount(account);
|
|
68
100
|
}
|
|
69
101
|
});
|
|
70
102
|
updateAccount();
|
|
71
|
-
}, [signer, config.
|
|
103
|
+
}, [signer, config.walletManagement]);
|
|
72
104
|
const value = useMemo(() => ({
|
|
73
105
|
connect,
|
|
74
106
|
disconnect,
|
|
75
107
|
switchChain,
|
|
76
108
|
addChain,
|
|
77
109
|
addToken,
|
|
110
|
+
attemptEagerConnect,
|
|
78
111
|
account,
|
|
79
|
-
}), [
|
|
112
|
+
}), [
|
|
113
|
+
account,
|
|
114
|
+
addChain,
|
|
115
|
+
addToken,
|
|
116
|
+
connect,
|
|
117
|
+
disconnect,
|
|
118
|
+
switchChain,
|
|
119
|
+
attemptEagerConnect,
|
|
120
|
+
]);
|
|
80
121
|
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
81
122
|
};
|
|
82
123
|
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -3,11 +3,12 @@ import { Token } from '@lifinance/sdk';
|
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
export interface WalletContextProps {
|
|
5
5
|
account: WalletAccount;
|
|
6
|
-
addChain(chainId: number): Promise<
|
|
6
|
+
addChain(chainId: number): Promise<boolean>;
|
|
7
7
|
addToken(chainId: number, token: Token): Promise<void>;
|
|
8
8
|
disconnect(): void;
|
|
9
9
|
switchChain(chainId: number): Promise<boolean>;
|
|
10
10
|
connect(wallet?: Wallet | undefined): Promise<void>;
|
|
11
|
+
attemptEagerConnect(): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
export interface WalletAccount {
|
|
13
14
|
address?: string;
|
package/types/widget.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainKey } from '@lifinance/sdk';
|
|
1
|
+
import { ChainKey, Token } from '@lifinance/sdk';
|
|
2
2
|
import { PaletteMode, PaletteOptions, Shape } from '@mui/material';
|
|
3
3
|
import { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
4
4
|
import { Signer } from 'ethers';
|
|
@@ -9,12 +9,14 @@ export declare type ThemeConfig = {
|
|
|
9
9
|
shape?: Shape;
|
|
10
10
|
typography?: TypographyOptions;
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
13
|
-
connect(): Signer
|
|
14
|
-
disconnect(): void
|
|
15
|
-
|
|
16
|
-
switchChain(): Signer
|
|
17
|
-
addToken(): void
|
|
12
|
+
export interface WidgetWalletManagement {
|
|
13
|
+
connect(): Promise<Signer>;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
getSigner(): Promise<Signer | undefined>;
|
|
16
|
+
switchChain(reqChainId: number): Promise<Signer>;
|
|
17
|
+
addToken(token: Token, chainId: number): Promise<void>;
|
|
18
|
+
addChain(chainId: number): Promise<boolean>;
|
|
19
|
+
signer?: Signer;
|
|
18
20
|
}
|
|
19
21
|
interface WidgetConfigBase {
|
|
20
22
|
fromAmount?: number;
|
|
@@ -23,6 +25,7 @@ interface WidgetConfigBase {
|
|
|
23
25
|
theme?: ThemeConfig;
|
|
24
26
|
appearance?: Appearance;
|
|
25
27
|
disableAppearance?: boolean;
|
|
28
|
+
walletManagement?: WidgetWalletManagement;
|
|
26
29
|
}
|
|
27
30
|
declare type WidgetFromTokenConfig = {
|
|
28
31
|
fromChain: `${ChainKey}` | number;
|
|
@@ -38,12 +41,5 @@ declare type WidgetToTokenConfig = {
|
|
|
38
41
|
toChain?: never;
|
|
39
42
|
toToken?: never;
|
|
40
43
|
};
|
|
41
|
-
declare type
|
|
42
|
-
disableInternalWalletManagement: true;
|
|
43
|
-
walletCallbacks: WidgetWalletCallbacks;
|
|
44
|
-
} | {
|
|
45
|
-
disableInternalWalletManagement?: false;
|
|
46
|
-
walletCallbacks?: never;
|
|
47
|
-
};
|
|
48
|
-
export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig & WidgetWalletManagementConfig;
|
|
44
|
+
export declare type WidgetConfig = WidgetConfigBase & WidgetFromTokenConfig & WidgetToTokenConfig;
|
|
49
45
|
export {};
|