@skip-go/widget 1.2.3 → 1.2.5

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
@@ -2,6 +2,21 @@
2
2
 
3
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
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
+
5
20
  ## Installation
6
21
 
7
22
  To install the package, run the following command:
@@ -137,31 +152,40 @@ The props for the web component are the same as `SwapWidgetProps` except that al
137
152
  are passed to the web-component via attributes in kebab-case as strings or stringified objects ie.
138
153
 
139
154
  ```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',
155
+ <div
156
+ style={{
157
+ width: '450px',
158
+ height: '820px',
150
159
  }}
151
- />
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>
152
174
  ```
153
175
 
154
176
  becomes
155
177
 
156
178
  ```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>
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>
167
191
  ```
package/build/index.es.js CHANGED
@@ -1889,7 +1889,7 @@ function useSwapWidget() {
1889
1889
  const { assetsByChainID, getFeeAsset, isReady: isAssetsReady, getAsset, } = useAssets();
1890
1890
  const { data: chains } = useChains({
1891
1891
  select: (chains) => {
1892
- if (!allChainIDs)
1892
+ if (allChainIDs.length === 0)
1893
1893
  return chains;
1894
1894
  return chains === null || chains === void 0 ? void 0 : chains.filter(({ chainID }) => {
1895
1895
  return allChainIDs.includes(chainID);
@@ -2475,9 +2475,10 @@ function useSwapWidget() {
2475
2475
  if (!chains || !isAssetsReady || srcChain)
2476
2476
  return;
2477
2477
  if (defaultSourceChain) {
2478
- const findChain = chains
2479
- .filter((c) => sourceChainIDs === null || sourceChainIDs === void 0 ? void 0 : sourceChainIDs.includes(c.chainID))
2480
- .find((x) => x.chainID.toLowerCase() === defaultSourceChain.toLowerCase());
2478
+ const filteredChains = sourceChainIDs
2479
+ ? chains.filter((c) => sourceChainIDs === null || sourceChainIDs === void 0 ? void 0 : sourceChainIDs.includes(c.chainID))
2480
+ : chains;
2481
+ const findChain = filteredChains.find((x) => x.chainID.toLowerCase() === defaultSourceChain.toLowerCase());
2481
2482
  if (findChain) {
2482
2483
  if (defaultSourceAsset) {
2483
2484
  const assets = assetsByChainID(findChain.chainID, (_a = filter === null || filter === void 0 ? void 0 : filter.source) === null || _a === void 0 ? void 0 : _a[findChain.chainID]);
@@ -2502,9 +2503,10 @@ function useSwapWidget() {
2502
2503
  if (!chains || !isAssetsReady || dstChain)
2503
2504
  return;
2504
2505
  if (defaultDestinationChain) {
2505
- const findChain = chains
2506
- .filter((c) => destinationChainIDs === null || destinationChainIDs === void 0 ? void 0 : destinationChainIDs.includes(c.chainID))
2507
- .find((x) => x.chainID.toLowerCase() === defaultDestinationChain.toLowerCase());
2506
+ const filteredChains = destinationChainIDs
2507
+ ? chains.filter((c) => destinationChainIDs === null || destinationChainIDs === void 0 ? void 0 : destinationChainIDs.includes(c.chainID))
2508
+ : chains;
2509
+ const findChain = filteredChains.find((x) => x.chainID.toLowerCase() === defaultDestinationChain.toLowerCase());
2508
2510
  if (findChain) {
2509
2511
  if (defaultDestinationAsset) {
2510
2512
  const assets = assetsByChainID(findChain.chainID, (_a = filter === null || filter === void 0 ? void 0 : filter.destination) === null || _a === void 0 ? void 0 : _a[findChain.chainID]);