@skip-go/widget 1.2.3 → 1.2.5-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,167 +1,191 @@
1
- # Skip Go Widget
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/).
4
-
5
- ## Installation
6
-
7
- To install the package, run the following command:
8
-
9
- ```bash
10
- npm install @skip-go/widget
11
- ```
12
-
13
- ## React Component usage
14
-
15
- import the `SwapWidget` from `'@skip-go/widget'` to render the swap interface:
16
-
17
- ```tsx
18
- import { SwapWidget } from '@skip-go/widget';
19
-
20
- const SwapPage = () => {
21
- return (
22
- <div
23
- style={{
24
- width: '450px',
25
- height: '820px',
26
- }}
27
- >
28
- <SwapWidget
29
- colors={{
30
- primary: '#FF4FFF',
31
- }}
32
- />
33
- </div>
34
- );
35
- };
36
- ```
37
-
38
- ### SwapWidget props
39
-
40
- The `SwapWidget` component accepts the following props:
41
-
42
- ````tsx
43
- interface SwapWidgetProps {
44
- colors?: {
45
- primary?: string; // Custom primary color for the widget. Defaults to `#FF486E`.
46
- };
47
- defaultRoute?: {
48
- // Default route for the widget.
49
- amountIn?: number;
50
- amountOut?: number;
51
- srcChainID?: string;
52
- srcAssetDenom?: string;
53
- destChainID?: string;
54
- destAssetDenom?: string;
55
- };
56
- routeConfig?: {
57
- experimentalFeatures?: ['hyperlane'];
58
- allowMultiTx?: boolean;
59
- allowUnsafe?: boolean;
60
- bridges?: ('IBC' | 'AXELAR' | 'CCTP' | 'HYPERLANE')[];
61
- swapVenues?: {
62
- name: string;
63
- chainID: string;
64
- }[];
65
- };
66
- /**
67
- * Filter chains and assets in selection
68
- *
69
- * Record<chainID, assetDenoms>
70
- * if assetDenoms is undefined, all assets are allowed
71
- * @example
72
- * ```ts
73
- * {
74
- * source: {
75
- * 'noble-1': undefined,
76
- * },
77
- * destination: {
78
- * 'cosmoshub-4': [
79
- * 'uatom',
80
- * 'ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86',
81
- * ],
82
- * 'agoric-3': [
83
- * 'ibc/FE98AAD68F02F03565E9FA39A5E627946699B2B07115889ED812D8BA639576A9',
84
- * ],
85
- * 'osmosis-1': undefined,
86
- * }
87
- * ```
88
- */
89
- filter?: {
90
- source?: Record<string, string[] | undefined>;
91
- destination?: Record<string, string[] | undefined>;
92
- };
93
- className?: string;
94
- style?: React.CSSProperties;
95
- settings?: {
96
- customGasAmount?: number; // custom gas amount for validation defaults to 200_000
97
- slippage?: number; //percentage of slippage 0-100. defaults to 3
98
- };
99
- onlyTestnet?: boolean; // Only show testnet chains
100
- toasterProps?: {
101
- // Refer to [ToasterProps](https://react-hot-toast.com/docs/toast-options) for more details. Defaults to `{ position: 'top-right' }`
102
- position?: ToastPosition;
103
- toastOptions?: DefaultToastOptions;
104
- reverseOrder?: boolean;
105
- gutter?: number;
106
- containerStyle?: React.CSSProperties;
107
- containerClassName?: string;
108
- children?: (toast: Toast) => JSX.Element;
109
- };
110
- endpointOptions?: {
111
- // Endpoint options to override endpoints. Defaults to Skip proxied endpoints. Please reach out to us first if you want to be whitelisted.
112
- endpoints?: Record<string, EndpointOptions>;
113
- getRpcEndpointForChain?: (chainID: string) => Promise<string>;
114
- getRestEndpointForChain?: (chainID: string) => Promise<string>;
115
- };
116
- 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.
117
- }
118
- ````
119
-
120
- # Experimental features (still in development)
121
-
122
- ## Web Component usage
123
-
124
- The web component is created with the `@r2wc/react-to-web-component` library.
125
-
126
- In order to register the web-component, you must first call the `initializeSwapWidget` function:
127
-
128
- ```tsx
129
- import { initializeSwapWidget } from '@skip-go/widget';
130
-
131
- initializeSwapWidget();
132
- ```
133
-
134
- et voilà! you can now use the `swap-widget` web-component as `<swap-widget></swap-widget>`
135
-
136
- The props for the web component are the same as `SwapWidgetProps` except that all props
137
- are passed to the web-component via attributes in kebab-case as strings or stringified objects ie.
138
-
139
- ```tsx
140
- <SwapWidget
141
- className="test-class"
142
- onlyTestnet={true}
143
- colors={{
144
- primary: '#FF4FFF',
145
- }}
146
- defaultRoute={{
147
- srcChainID: 'osmosis-1',
148
- srcAssetDenom:
149
- 'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
150
- }}
151
- />
152
- ```
153
-
154
- becomes
155
-
156
- ```tsx
157
- <swap-widget
158
- class-name="test-class"
159
- onlyTestnet="true"
160
- colors='{"primary":"#FF4FFF"}'
161
- default-route={JSON.stringify({
162
- srcChainID: 'osmosis-1',
163
- srcAssetDenom:
164
- 'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
165
- })}
166
- ></swap-widget>
167
- ```
1
+ # Skip Go Widget
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/).
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
+ colors?: {
60
+ primary?: string; // Custom primary color for the widget. Defaults to `#FF486E`.
61
+ };
62
+ defaultRoute?: {
63
+ // Default route for the widget.
64
+ amountIn?: number;
65
+ amountOut?: number;
66
+ srcChainID?: string;
67
+ srcAssetDenom?: string;
68
+ destChainID?: string;
69
+ destAssetDenom?: string;
70
+ };
71
+ routeConfig?: {
72
+ experimentalFeatures?: ['hyperlane'];
73
+ allowMultiTx?: boolean;
74
+ allowUnsafe?: boolean;
75
+ bridges?: ('IBC' | 'AXELAR' | 'CCTP' | 'HYPERLANE')[];
76
+ swapVenues?: {
77
+ name: string;
78
+ chainID: string;
79
+ }[];
80
+ };
81
+ /**
82
+ * Filter chains and assets in selection
83
+ *
84
+ * Record<chainID, assetDenoms>
85
+ * if assetDenoms is undefined, all assets are allowed
86
+ * @example
87
+ * ```ts
88
+ * {
89
+ * source: {
90
+ * 'noble-1': undefined,
91
+ * },
92
+ * destination: {
93
+ * 'cosmoshub-4': [
94
+ * 'uatom',
95
+ * 'ibc/2181AAB0218EAC24BC9F86BD1364FBBFA3E6E3FCC25E88E3E68C15DC6E752D86',
96
+ * ],
97
+ * 'agoric-3': [
98
+ * 'ibc/FE98AAD68F02F03565E9FA39A5E627946699B2B07115889ED812D8BA639576A9',
99
+ * ],
100
+ * 'osmosis-1': undefined,
101
+ * }
102
+ * ```
103
+ */
104
+ filter?: {
105
+ source?: Record<string, string[] | undefined>;
106
+ destination?: Record<string, string[] | undefined>;
107
+ };
108
+ className?: string;
109
+ style?: React.CSSProperties;
110
+ settings?: {
111
+ customGasAmount?: number; // custom gas amount for validation defaults to 200_000
112
+ slippage?: number; //percentage of slippage 0-100. defaults to 3
113
+ };
114
+ onlyTestnet?: boolean; // Only show testnet chains
115
+ toasterProps?: {
116
+ // Refer to [ToasterProps](https://react-hot-toast.com/docs/toast-options) for more details. Defaults to `{ position: 'top-right' }`
117
+ position?: ToastPosition;
118
+ toastOptions?: DefaultToastOptions;
119
+ reverseOrder?: boolean;
120
+ gutter?: number;
121
+ containerStyle?: React.CSSProperties;
122
+ containerClassName?: string;
123
+ children?: (toast: Toast) => JSX.Element;
124
+ };
125
+ endpointOptions?: {
126
+ // Endpoint options to override endpoints. Defaults to Skip proxied endpoints. Please reach out to us first if you want to be whitelisted.
127
+ endpoints?: Record<string, EndpointOptions>;
128
+ getRpcEndpointForChain?: (chainID: string) => Promise<string>;
129
+ getRestEndpointForChain?: (chainID: string) => Promise<string>;
130
+ };
131
+ 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.
132
+ }
133
+ ````
134
+
135
+ # Experimental features (still in development)
136
+
137
+ ## Web Component usage
138
+
139
+ The web component is created with the `@r2wc/react-to-web-component` library.
140
+
141
+ In order to register the web-component, you must first call the `initializeSwapWidget` function:
142
+
143
+ ```tsx
144
+ import { initializeSwapWidget } from '@skip-go/widget';
145
+
146
+ initializeSwapWidget();
147
+ ```
148
+
149
+ et voilà! you can now use the `swap-widget` web-component as `<swap-widget></swap-widget>`
150
+
151
+ The props for the web component are the same as `SwapWidgetProps` except that all props
152
+ are passed to the web-component via attributes in kebab-case as strings or stringified objects ie.
153
+
154
+ ```tsx
155
+ <div
156
+ style={{
157
+ width: '450px',
158
+ height: '820px',
159
+ }}
160
+ >
161
+ <SwapWidget
162
+ className="test-class"
163
+ onlyTestnet={true}
164
+ colors={{
165
+ primary: '#FF4FFF',
166
+ }}
167
+ defaultRoute={{
168
+ srcChainID: 'osmosis-1',
169
+ srcAssetDenom:
170
+ 'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
171
+ }}
172
+ />
173
+ </div>
174
+ ```
175
+
176
+ becomes
177
+
178
+ ```tsx
179
+ <div style="width:450px;height:820px;">
180
+ <swap-widget
181
+ class-name="test-class"
182
+ onlyTestnet="true"
183
+ colors='{"primary":"#FF4FFF"}'
184
+ default-route={JSON.stringify({
185
+ srcChainID: 'osmosis-1',
186
+ srcAssetDenom:
187
+ 'ibc/1480b8fd20ad5fcae81ea87584d269547dd4d436843c1d20f15e00eb64743ef4',
188
+ })}
189
+ ></swap-widget>
190
+ </div>
191
+ ```