@skip-go/widget 2.3.8 → 2.4.1-alpha.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/README.md CHANGED
@@ -1,196 +1,5 @@
1
1
  # Skip Go Widget
2
2
 
3
- The `@skip-go/widget` package is an npm package providing a React component for a full swap interface using the [Skip Go API](https://skip.build/).
3
+ We document everything about Skip Go Widget in [docs.skip.build/go/widget](https://docs.skip.build/go/widget)
4
4
 
5
- ### Polyfilling Node core modules
6
-
7
- If you encounter an error like "Buffer is not defined" when importing and using @skip-go/widget, it may be necessary to polyfill Node.js modules because Skip Go Widget relies on them.
8
-
9
- Here are some polyfill plugins for common environments:
10
-
11
- - [Webpack](https://www.npmjs.com/package/node-polyfill-webpack-plugin),
12
- - [Rollup](https://www.npmjs.com/package/rollup-plugin-polyfill-node),
13
- - [Vite](https://www.npmjs.com/package/vite-plugin-node-polyfills),
14
- - [ESBuild](https://www.npmjs.com/package/esbuild-plugins-node-modules-polyfill)
15
-
16
- ### Wrap the widget with a fixed container
17
-
18
- It is recommended to wrap the widget with a container element that has a fixed size. This helps to prevent layout shifting as the widget uses shadow-dom (which currently needs to be rendered client-side)
19
-
20
- ## Installation
21
-
22
- To install the package, run the following command:
23
-
24
- ```bash
25
- npm install @skip-go/widget
26
- ```
27
-
28
- ## React Component usage
29
-
30
- import the `SwapWidget` from `'@skip-go/widget'` to render the swap interface:
31
-
32
- ```tsx
33
- import { SwapWidget } from '@skip-go/widget';
34
-
35
- const SwapPage = () => {
36
- return (
37
- <div
38
- style={{
39
- width: '450px',
40
- height: '820px',
41
- }}
42
- >
43
- <SwapWidget
44
- colors={{
45
- primary: '#FF4FFF',
46
- }}
47
- />
48
- </div>
49
- );
50
- };
51
- ```
52
-
53
- ### SwapWidget props
54
-
55
- The `SwapWidget` component accepts the following props:
56
-
57
- ````tsx
58
- interface SwapWidgetProps {
59
- defaultRoute?: {
60
- // Default route for the widget.
61
- amountIn?: number;
62
- amountOut?: number;
63
- srcChainID?: string;
64
- srcAssetDenom?: string;
65
- destChainID?: string;
66
- destAssetDenom?: string;
67
- };
68
- routeConfig?: {
69
- experimentalFeatures?: ['hyperlane'];
70
- allowMultiTx?: boolean;
71
- allowUnsafe?: boolean;
72
- bridges?: ('IBC' | 'AXELAR' | 'CCTP' | 'HYPERLANE')[];
73
- swapVenues?: {
74
- name: string;
75
- chainID: string;
76
- }[];
77
- };
78
- /**
79
- * Filter chains and assets in selection
80
- *
81
- * Record<chainID, assetDenoms>
82
- * if assetDenoms is undefined, all assets are allowed
83
- * @example
84
- * ```ts
85
- * {
86
- * source: {
87
- * 'noble-1': undefined,
88
- * },
89
- * destination: {
90
- * 'cosmoshub-4': [
91
- * 'uatom',
92
- * 'ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86',
93
- * ],
94
- * 'agoric-3': [
95
- * 'ibc/FE98AAD68F02F03565E9FA39A5E627946699B2B07115889ED812D8BA639576A9',
96
- * ],
97
- * 'osmosis-1': undefined,
98
- * }
99
- * ```
100
- */
101
- filter?: {
102
- source?: Record<string, string[] | undefined>;
103
- destination?: Record<string, string[] | undefined>;
104
- };
105
- className?: string;
106
- style?: React.CSSProperties;
107
- settings?: {
108
- customGasAmount?: number; // custom gas amount for validation defaults to 200_000
109
- slippage?: number; //percentage of slippage 0-100. defaults to 3
110
- };
111
- onlyTestnet?: boolean; // Only show testnet chains
112
- toasterProps?: {
113
- // Refer to [ToasterProps](https://react-hot-toast.com/docs/toast-options) for more details. Defaults to `{ position: 'top-right' }`
114
- position?: ToastPosition;
115
- toastOptions?: DefaultToastOptions;
116
- reverseOrder?: boolean;
117
- gutter?: number;
118
- containerStyle?: React.CSSProperties;
119
- containerClassName?: string;
120
- children?: (toast: Toast) => JSX.Element;
121
- };
122
- endpointOptions?: {
123
- // Endpoint options to override endpoints. Defaults to Skip proxied endpoints. Please reach out to us first if you want to be whitelisted.
124
- endpoints?: Record<string, EndpointOptions>;
125
- getRpcEndpointForChain?: (chainID: string) => Promise<string>;
126
- getRestEndpointForChain?: (chainID: string) => Promise<string>;
127
- };
128
- apiURL?: string; // Custom API URL to override Skip API endpoint. Defaults to Skip proxied endpoints. Please reach out to us first if you want to be whitelisted.
129
- theme?: {
130
- backgroundColor: string; // background color
131
- textColor: string; // text color
132
- borderColor: string; // border color
133
- brandColor: string; // color used for confirmation buttons
134
- highlightColor: string; // color used when hovering over buttons, and in select chain/asset dropdown
135
- };
136
- persistSwapWidgetState?: boolean; // whether or not swap widget state should persist after refresh. Defaults to true
137
- }
138
- ````
139
-
140
- # Experimental features (still in development)
141
-
142
- ## Web Component usage
143
-
144
- The web component is created with the `@r2wc/react-to-web-component` library.
145
-
146
- In order to register the web-component, you must first call the `initializeSwapWidget` function:
147
-
148
- ```tsx
149
- import { initializeSwapWidget } from '@skip-go/widget';
150
-
151
- initializeSwapWidget();
152
- ```
153
-
154
- et voilà! you can now use the `swap-widget` web-component as `<swap-widget></swap-widget>`
155
-
156
- The props for the web component are the same as `SwapWidgetProps` except that all props
157
- are passed to the web-component via attributes in kebab-case as strings or stringified objects ie.
158
-
159
- ```tsx
160
- <div
161
- style={{
162
- width: '450px',
163
- height: '820px',
164
- }}
165
- >
166
- <SwapWidget
167
- className="test-class"
168
- onlyTestnet={true}
169
- colors={{
170
- primary: '#FF4FFF',
171
- }}
172
- defaultRoute={{
173
- srcChainID: 'osmosis-1',
174
- srcAssetDenom:
175
- 'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
176
- }}
177
- />
178
- </div>
179
- ```
180
-
181
- becomes
182
-
183
- ```tsx
184
- <div style="width:450px;height:820px;">
185
- <swap-widget
186
- class-name="test-class"
187
- onlyTestnet="true"
188
- colors='{"primary":"#FF4FFF"}'
189
- default-route={JSON.stringify({
190
- srcChainID: 'osmosis-1',
191
- srcAssetDenom:
192
- 'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
193
- })}
194
- ></swap-widget>
195
- </div>
196
- ```
5
+ [Here](https://github.com/skip-mev/skip-go/blob/main/docs/widget/) is where all of the markdown lives
@@ -1,4 +1,3 @@
1
- import { AssetsRequest } from '@skip-go/client';
2
- export declare function useAssets(options?: AssetsRequest): import("@tanstack/react-query/build/legacy/types").UseQueryResult<{
3
- [k: string]: import("@skip-go/client/dist/shared-CvoSvr3u").a[];
4
- }, Error>;
1
+ import { Asset, AssetsRequest } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
3
+ export declare function useAssets(options?: AssetsRequest): UseQueryResult<Record<string, Asset[]>>;
@@ -1,4 +1,5 @@
1
1
  import { Chain } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
2
3
  import { ChainAddresses, SetChainAddressesParam } from '../ui/PreviewRoute/types';
3
4
  export declare const useAutoSetAddress: ({ chain, chainID, index, enabled, signRequired, chainAddresses, setChainAddresses, }: {
4
5
  chain?: Chain | undefined;
@@ -8,4 +9,4 @@ export declare const useAutoSetAddress: ({ chain, chainID, index, enabled, signR
8
9
  signRequired?: boolean | undefined;
9
10
  chainAddresses: ChainAddresses;
10
11
  setChainAddresses: (v: SetChainAddressesParam) => void;
11
- }) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<null, Error>;
12
+ }) => UseQueryResult;
@@ -1,4 +1,5 @@
1
- import { Asset, SkipRouter } from '@skip-go/client';
1
+ import { Asset, SkipClient } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
2
3
  import { PublicClient } from 'viem';
3
4
  import { Chain } from './use-chains';
4
5
  interface Args {
@@ -8,8 +9,8 @@ interface Args {
8
9
  enabled?: boolean;
9
10
  solanaRpcUrl?: string;
10
11
  }
11
- export declare function useBalancesByChain({ address, chain, assets, enabled, }: Args): import("@tanstack/react-query/build/legacy/types").UseQueryResult<Record<string, string> | undefined, Error>;
12
+ export declare function useBalancesByChain({ address, chain, assets, enabled, }: Args): UseQueryResult<Record<string, string> | undefined>;
12
13
  export declare function getBalancesByChain(rpcURL: string, address: string, chainID: string, assets: Asset[]): Promise<Record<string, string>>;
13
- export declare function getEvmChainBalances(skipClient: SkipRouter, publicClient: PublicClient, address: string, chainID: string): Promise<Record<string, string>>;
14
+ export declare function getEvmChainBalances(skipClient: SkipClient, publicClient: PublicClient, address: string, chainID: string): Promise<Record<string, string>>;
14
15
  export declare const getSvmChainBalances: (rpcUrl: string, address: string, chainID: string, assets: Asset[]) => Promise<Record<string, string>>;
15
16
  export {};
@@ -1,7 +1,8 @@
1
1
  import { Bridge } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
2
3
  export type UseBridgesQueryArgs<T = Bridge[]> = {
3
4
  enabled?: boolean;
4
5
  select?: (arr?: Bridge[]) => T;
5
6
  };
6
- export declare function useBridges<T = Bridge[]>(args?: UseBridgesQueryArgs<T>): import("@tanstack/react-query/build/legacy/types").UseQueryResult<T, Error>;
7
- export declare function useBridgeByID(bridgeID?: Bridge['id']): import("@tanstack/react-query/build/legacy/types").UseQueryResult<Bridge | undefined, Error>;
7
+ export declare function useBridges<T = Bridge[]>(args?: UseBridgesQueryArgs<T>): UseQueryResult<T>;
8
+ export declare function useBridgeByID(bridgeID?: Bridge['id']): UseQueryResult<Bridge | undefined>;
@@ -1,4 +1,5 @@
1
1
  import { ChainTransaction, TransferState, StatusState } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
2
3
  interface TransferSequence {
3
4
  srcChainID: string;
4
5
  destChainID: string;
@@ -8,6 +9,12 @@ interface TransferSequence {
8
9
  };
9
10
  state: TransferState;
10
11
  }
12
+ interface TxsStatus {
13
+ isSuccess: boolean;
14
+ isSettled: boolean;
15
+ transferSequence: TransferSequence[];
16
+ states: StatusState[];
17
+ }
11
18
  export declare const useBroadcastedTxsStatus: ({ txs, txsRequired, enabled, }: {
12
19
  txsRequired: number;
13
20
  txs: {
@@ -15,10 +22,5 @@ export declare const useBroadcastedTxsStatus: ({ txs, txsRequired, enabled, }: {
15
22
  txHash: string;
16
23
  }[] | undefined;
17
24
  enabled?: boolean | undefined;
18
- }) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<{
19
- isSuccess: boolean;
20
- isSettled: boolean;
21
- transferSequence: TransferSequence[];
22
- states: StatusState[];
23
- } | undefined, Error>;
25
+ }) => UseQueryResult<TxsStatus>;
24
26
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Chain as SkipChain } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
2
3
  export type Chain = SkipChain & {
3
4
  prettyName: string;
4
5
  };
@@ -6,5 +7,5 @@ export type UseChainsQueryArgs<T = Chain[]> = {
6
7
  enabled?: boolean;
7
8
  select?: (arr?: Chain[]) => T;
8
9
  };
9
- export declare function useChains<T = Chain[]>(args?: UseChainsQueryArgs<T>): import("@tanstack/react-query/build/legacy/types").UseQueryResult<T, Error>;
10
- export declare function useChainByID(chainID?: string): import("@tanstack/react-query/build/legacy/types").UseQueryResult<Chain | undefined, Error>;
10
+ export declare function useChains<T = Chain[]>(args?: UseChainsQueryArgs<T>): UseQueryResult<T>;
11
+ export declare function useChainByID(chainID?: string): UseQueryResult<Chain | undefined>;
@@ -1,4 +1,5 @@
1
- import { BridgeType, ExperimentalFeature, SmartSwapOptions, SwapVenueRequest } from '@skip-go/client';
1
+ import { BridgeType, ExperimentalFeature, RouteResponse, SmartSwapOptions, SwapVenueRequest } from '@skip-go/client';
2
+ import { UseQueryResult } from '@tanstack/react-query';
2
3
  export interface RouteConfig {
3
4
  experimentalFeatures?: ExperimentalFeature[];
4
5
  allowMultiTx?: boolean;
@@ -16,5 +17,5 @@ interface UseRouteArgs extends RouteConfig {
16
17
  destinationAssetChainID?: string;
17
18
  enabled?: boolean;
18
19
  }
19
- export declare function useRoute({ direction, amount, sourceAsset, sourceAssetChainID, destinationAsset, destinationAssetChainID, enabled, swapVenues, bridges, experimentalFeatures, allowMultiTx, allowUnsafe, smartSwapOptions, }: UseRouteArgs): import("@tanstack/react-query/build/legacy/types").UseQueryResult<import("@skip-go/client/dist/shared-CvoSvr3u").R | undefined, Error>;
20
+ export declare function useRoute({ direction, amount, sourceAsset, sourceAssetChainID, destinationAsset, destinationAssetChainID, enabled, swapVenues, bridges, experimentalFeatures, allowMultiTx, allowUnsafe, smartSwapOptions, }: UseRouteArgs): UseQueryResult<RouteResponse | undefined>;
20
21
  export {};
@@ -1,4 +1,4 @@
1
- export declare function useSkipClient(): import("@skip-go/client").SkipRouter;
1
+ export declare function useSkipClient(): import("@skip-go/client").SkipClient;
2
2
  export declare function useSkipConfig(): {
3
3
  apiURL: string | undefined;
4
4
  endpointOptions: {
@@ -31,7 +31,7 @@ export declare function useSwapWidget(persistSwapWidgetState?: boolean): {
31
31
  onSourceAssetChange: (asset: Asset) => void;
32
32
  onSourceChainChange: (chain: Chain, injectAsset?: Asset) => Promise<void>;
33
33
  priceImpactThresholdReached: boolean;
34
- route: import("@skip-go/client/dist/shared-CvoSvr3u").R | undefined;
34
+ route: import("@skip-go/client/dist/shared-CpfDn0H3").R | undefined;
35
35
  routeError: string;
36
36
  routeLoading: boolean;
37
37
  routeWarningMessage: string | undefined;
@@ -1,8 +1,9 @@
1
+ import { UseQueryResult } from '@tanstack/react-query';
1
2
  export type Args = {
2
3
  chainId: string;
3
4
  denom: string;
4
5
  coingeckoID?: string;
5
6
  value: string;
6
7
  };
7
- export declare function useUsdValue(args: Args): import("@tanstack/react-query/build/legacy/types").UseQueryResult<number, Error>;
8
- export declare function useUsdDiffValue([args1, args2]: [Args, Args]): import("@tanstack/react-query/build/legacy/types").UseQueryResult<number, Error>;
8
+ export declare function useUsdValue(args: Args): UseQueryResult<number>;
9
+ export declare function useUsdDiffValue([args1, args2]: [Args, Args]): UseQueryResult<number, Error>;