Skip to content

Commit

Permalink
Swap widget without providers (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao authored Jul 18, 2024
1 parent 6eb6740 commit dcb144b
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-fishes-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skip-go/widget': minor
---

Export SwapWidgetWithoutProvider
51 changes: 51 additions & 0 deletions examples/nextjs/pages/provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { NextPage } from 'next';
import React from 'react';
import { SwapWidgetWithoutProviders } from '@skip-go/widget';
import { SwapWidgetProvider } from '@skip-go/widget';

const Home: NextPage = () => {
return (
<div
style={{
display: 'flex',
flexDirection: 'row',
}}
>
<div
style={{
width: '450px',
height: '820px',
}}
>
<SwapWidgetProvider>
<SwapWidgetWithoutProviders
colors={{
primary: '#FF4FFF',
}}
defaultRoute={{
srcChainID: 'osmosis-1',
srcAssetDenom:
'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
}}
/>
</SwapWidgetProvider>
</div>
<button
onClick={() => {
if (window.confirm('Are you sure you want to purge all settings?')) {
window.localStorage.clear();
window.sessionStorage.clear();
window.location.reload();
}
}}
style={{
height: '40px',
}}
>
Purge Settings
</button>
</div>
);
};

export default Home;
2 changes: 0 additions & 2 deletions examples/nextjs/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ div,
p,
span {
color: gray;
border: 2px solid gray;
background: gray;
}
7 changes: 6 additions & 1 deletion packages/widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export { SwapWidgetProvider } from './provider';
export { SwapWidget, SwapWidgetProps } from './ui';
export {
SwapWidget,
SwapWidgetProps,
SwapWidgetWithoutProviders,
SwapWidgetWithoutProvidersProps,
} from './ui';
export { initializeSwapWidget } from './ui/WebComponent';
export { useAssets } from './provider/assets';
export { useChains, useChainByID } from './hooks/use-chains';
40 changes: 38 additions & 2 deletions packages/widget/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,49 @@ import cssReset from '../styles/cssReset.css';
import { Scope } from 'react-shadow-scope';
import { useInjectFontsToDocumentHead } from '../hooks/use-inject-fonts-to-document-head';

export type SwapWidgetProps = Pick<
export type SwapWidgetWithoutProvidersProps = Pick<
React.HTMLAttributes<HTMLDivElement>,
'className' | 'style'
> &
ConfigureSwapWidgetArgs &
ConfigureSwapWidgetArgs;

export type SwapWidgetProps = SwapWidgetWithoutProvidersProps &
Partial<SwapWidgetProviderProps>;

export const SwapWidgetWithoutProviders: React.FC<
SwapWidgetWithoutProvidersProps
> = ({
colors,
settings,
onlyTestnet,
defaultRoute,
routeConfig,
className,
style,
filter,
}) => {
useInjectFontsToDocumentHead();
useEffect(() => {
configureSwapWidget({
colors,
onlyTestnet,
settings,
defaultRoute,
routeConfig,
filter,
});
}, [colors, onlyTestnet, settings, defaultRoute, routeConfig]);

return (
<Scope
stylesheets={[cssReset, toastStyles, shadowDomStyles]}
config={{ dsd: 'emulated' }}
>
<SwapWidgetUI className={className} style={style} />
</Scope>
);
};

export const SwapWidget: React.FC<SwapWidgetProps> = ({
colors,
settings,
Expand Down

0 comments on commit dcb144b

Please sign in to comment.