@skip-go/widget 1.2.4 → 1.2.5-alpha.1
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 +191 -191
- package/build/index.es.js +62 -58
- package/build/index.es.js.map +1 -1
- package/build/ui/WithStyledShadowDom.d.ts +4 -0
- package/build/ui/theme.d.ts +31 -0
- package/build/utils/withStyledComponent.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,191 +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
|
-
### 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
|
-
```
|
|
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
|
+
```
|