@cowprotocol/widget-react 1.0.11 → 1.2.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/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@cowprotocol/widget-lib"),h=require("react/jsx-runtime"),t=require("react");function E(u){const{params:n,provider:i,listeners:s}=u,[a,g]=t.useState(null),o=t.useRef(null),r=t.useRef(i),w=t.useRef(s),d=t.useRef(null),c=t.useRef(null),f=t.useCallback((e,y)=>{try{console.log(`[WIDGET] ${e}`),y()}catch(l){const m=`Error ${e.toLowerCase()}`,v=l instanceof Error?l:new Error("Unknown CowSwapWidget error",{cause:l});console.error(`[WIDGET] ${m}`,v),g({message:m,error:v})}},[]);return t.useEffect(()=>()=>{o.current=null,r.current=void 0,w.current=void 0;const e=c.current;e&&(f("💥 Destroy widget",()=>e.destroy()),c.current=null)},[]),t.useEffect(()=>{const e=!!o.current&&S(o.current,n);if(!d.current||JSON.stringify(o.current)===JSON.stringify(n)&&!e)return;const y=d.current,l=c.current;o.current=n,l===null?f("Creating a new widget",()=>{c.current=p.createCowSwapWidget(y,{params:n,provider:r.current,listeners:s}),w.current=s}):f("Updating the widget",()=>l.updateParams(n))},[n,f]),t.useEffect(()=>{if(!c.current||r.current===i)return;r.current=i;const e=d.current;e&&f("Updating the provider",()=>{c.current?.destroy(),c.current=p.createCowSwapWidget(e,{params:n,provider:r.current,listeners:s})})},[i,f]),t.useEffect(()=>{if(!c.current||w.current===s)return;const e=c.current;f("Updating the listeners",()=>e.updateListeners(s))},[s,f]),a?h.jsxs("div",{style:{color:"#ff3a3a"},children:[a.message,a.error.message&&h.jsx("pre",{style:{whiteSpace:"pre-wrap",fontSize:"0.75em"},children:a.error.message})]}):h.jsx("div",{ref:d,style:{width:"100%"}})}function S(u,n){const i=n.hooks??{},s=Object.keys(i),a=u.hooks??{},g=Object.keys(a);return s.some(o=>{const r=o;return i[r]!==a[r]})||g.some(o=>{const r=o;return i[r]!==a[r]})}exports.CowSwapWidget=E;Object.keys(p).forEach(u=>{u!=="default"&&!Object.prototype.hasOwnProperty.call(exports,u)&&Object.defineProperty(exports,u,{enumerable:!0,get:()=>p[u]})});
package/index.js ADDED
@@ -0,0 +1,79 @@
1
+ import { createCowSwapWidget as k } from "@cowprotocol/widget-lib";
2
+ export * from "@cowprotocol/widget-lib";
3
+ import { jsxs as E, jsx as v } from "react/jsx-runtime";
4
+ import { useState as S, useRef as l, useCallback as x, useEffect as d } from "react";
5
+ function O(p) {
6
+ const {
7
+ params: t,
8
+ provider: c,
9
+ listeners: n
10
+ } = p, [i, g] = S(null), o = l(null), e = l(c), m = l(n), f = l(null), s = l(null), u = x((r, w) => {
11
+ try {
12
+ console.log(`[WIDGET] ${r}`), w();
13
+ } catch (a) {
14
+ const y = `Error ${r.toLowerCase()}`, h = a instanceof Error ? a : new Error("Unknown CowSwapWidget error", {
15
+ cause: a
16
+ });
17
+ console.error(`[WIDGET] ${y}`, h), g({
18
+ message: y,
19
+ error: h
20
+ });
21
+ }
22
+ }, []);
23
+ return d(() => () => {
24
+ o.current = null, e.current = void 0, m.current = void 0;
25
+ const r = s.current;
26
+ r && (u("💥 Destroy widget", () => r.destroy()), s.current = null);
27
+ }, []), d(() => {
28
+ const r = !!o.current && C(o.current, t);
29
+ if (!f.current || JSON.stringify(o.current) === JSON.stringify(t) && !r)
30
+ return;
31
+ const w = f.current, a = s.current;
32
+ o.current = t, a === null ? u("Creating a new widget", () => {
33
+ s.current = k(w, {
34
+ params: t,
35
+ provider: e.current,
36
+ listeners: n
37
+ }), m.current = n;
38
+ }) : u("Updating the widget", () => a.updateParams(t));
39
+ }, [t, u]), d(() => {
40
+ if (!s.current || e.current === c)
41
+ return;
42
+ e.current = c;
43
+ const r = f.current;
44
+ r && u("Updating the provider", () => {
45
+ s.current?.destroy(), s.current = k(r, {
46
+ params: t,
47
+ provider: e.current,
48
+ listeners: n
49
+ });
50
+ });
51
+ }, [c, u]), d(() => {
52
+ if (!s.current || m.current === n) return;
53
+ const r = s.current;
54
+ u("Updating the listeners", () => r.updateListeners(n));
55
+ }, [n, u]), i ? /* @__PURE__ */ E("div", { style: {
56
+ color: "#ff3a3a"
57
+ }, children: [
58
+ i.message,
59
+ i.error.message && /* @__PURE__ */ v("pre", { style: {
60
+ whiteSpace: "pre-wrap",
61
+ fontSize: "0.75em"
62
+ }, children: i.error.message })
63
+ ] }) : /* @__PURE__ */ v("div", { ref: f, style: {
64
+ width: "100%"
65
+ } });
66
+ }
67
+ function C(p, t) {
68
+ const c = t.hooks ?? {}, n = Object.keys(c), i = p.hooks ?? {}, g = Object.keys(i);
69
+ return n.some((o) => {
70
+ const e = o;
71
+ return c[e] !== i[e];
72
+ }) || g.some((o) => {
73
+ const e = o;
74
+ return c[e] !== i[e];
75
+ });
76
+ }
77
+ export {
78
+ O as CowSwapWidget
79
+ };
@@ -1,3 +1,3 @@
1
- import { ReactNode } from 'react';
1
+ import { JSX } from 'react';
2
2
  import { CowSwapWidgetProps } from '@cowprotocol/widget-lib';
3
- export declare function CowSwapWidget(props: CowSwapWidgetProps): ReactNode;
3
+ export declare function CowSwapWidget(props: CowSwapWidgetProps): JSX.Element;
package/package.json CHANGED
@@ -1,45 +1,35 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-react",
3
- "version": "1.0.11",
3
+ "version": "1.2.0",
4
4
  "description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your React application.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/cowprotocol/cowswap.git",
8
8
  "directory": "libs/widget-react"
9
9
  },
10
- "type": "commonjs",
11
- "main": "./src/index.js",
12
- "types": "./src/index.d.ts",
10
+ "type": "module",
11
+ "main": "./index.js",
12
+ "types": "./index.d.ts",
13
13
  "license": "ISC",
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
17
  "dependencies": {
18
- "@cowprotocol/cow-sdk": "8.0.0",
19
- "@cowprotocol/events": "^4.0.1",
20
- "@cowprotocol/sdk-bridging": "3.0.0",
21
- "@cowprotocol/types": "^4.0.1",
22
- "@cowprotocol/widget-lib": "^2.0.1",
23
- "@types/react": "19.1.3",
24
- "@uniswap/sdk-core": "3.2.6",
25
- "@web3-react/types": "8.2.3",
26
- "eventemitter3": "4.0.7",
27
- "@cowprotocol/iframe-transport": "2.0.9",
28
- "tslib": "1.14.1"
18
+ "@cowprotocol/events": "^4.1.0",
19
+ "@cowprotocol/types": "^4.1.0",
20
+ "@cowprotocol/widget-lib": "^2.1.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/react": "19.1.3"
29
24
  },
30
25
  "peerDependencies": {
31
26
  "react": "19.1.2"
32
27
  },
33
- "resolutions": {
34
- "@safe-global/safe-apps-sdk": "^9.1.0",
35
- "@types/react": "19.1.3",
36
- "@types/react-dom": "19.1.3",
37
- "stylus": "npm:empty-npm-package@1.0.0",
38
- "@babel/traverse": "^7.23.2",
39
- "@walletconnect/ethereum-provider": "2.18.0",
40
- "@walletconnect/sign-client": "2.18.0",
41
- "@walletconnect/universal-provider": "2.18.0",
42
- "@walletconnect/utils": "2.18.0",
43
- "@walletconnect/types": "2.18.0"
28
+ "exports": {
29
+ ".": {
30
+ "types": "./index.d.ts",
31
+ "import": "./index.js",
32
+ "require": "./index.cjs"
33
+ }
44
34
  }
45
35
  }
package/CHANGELOG.md DELETED
@@ -1,325 +0,0 @@
1
- # Changelog
2
-
3
- ## [1.0.11](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.10...widget-react-v1.0.11) (2026-03-18)
4
-
5
-
6
- ### 🐛 Bug Fixes
7
-
8
- * update libs publising and bundling ([#7173](https://github.com/cowprotocol/cowswap/issues/7173)) ([e3bc5f1](https://github.com/cowprotocol/cowswap/commit/e3bc5f179124c11590a992789db43d912f8ee4a6))
9
-
10
-
11
- ### Dependencies
12
-
13
- * The following workspace dependencies were updated
14
- * dependencies
15
- * @cowprotocol/events bumped to 4.0.1
16
- * @cowprotocol/types bumped to 4.0.1
17
- * @cowprotocol/widget-lib bumped to 2.0.1
18
-
19
- ## [1.0.10](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.9...widget-react-v1.0.10) (2026-03-11)
20
-
21
-
22
- ### Dependencies
23
-
24
- * The following workspace dependencies were updated
25
- * dependencies
26
- * @cowprotocol/events bumped to 4.0.0
27
- * @cowprotocol/types bumped to 4.0.0
28
- * @cowprotocol/widget-lib bumped to 2.0.0
29
-
30
- ## [1.0.9](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.8...widget-react-v1.0.9) (2026-03-10)
31
-
32
-
33
- ### Dependencies
34
-
35
- * The following workspace dependencies were updated
36
- * dependencies
37
- * @cowprotocol/events bumped to 3.4.0
38
- * @cowprotocol/types bumped to 3.4.0
39
- * @cowprotocol/widget-lib bumped to 1.3.0
40
-
41
- ## [1.0.8](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.7...widget-react-v1.0.8) (2026-02-25)
42
-
43
-
44
- ### 🔧 Miscellaneous
45
-
46
- * main -> dev ([9c6611e](https://github.com/cowprotocol/cowswap/commit/9c6611e90a4b23e23f6aaadc513de3c6d7f3b562))
47
-
48
-
49
- ### Dependencies
50
-
51
- * The following workspace dependencies were updated
52
- * dependencies
53
- * @cowprotocol/events bumped to 3.3.2
54
- * @cowprotocol/types bumped to 3.3.2
55
- * @cowprotocol/widget-lib bumped to 1.2.2
56
-
57
- ## [1.0.7](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.6...widget-react-v1.0.7) (2026-02-24)
58
-
59
-
60
- ### 🔧 Miscellaneous
61
-
62
- * merge main into dev 23 02 ([#7062](https://github.com/cowprotocol/cowswap/issues/7062)) ([ac48c9c](https://github.com/cowprotocol/cowswap/commit/ac48c9c83284c6228ba71392edc1c1e0483b53ff))
63
- * release 23-02 ([bab3bf6](https://github.com/cowprotocol/cowswap/commit/bab3bf640c5b0eacc7ead017ea68ab1eb1687aab))
64
-
65
-
66
- ### Dependencies
67
-
68
- * The following workspace dependencies were updated
69
- * dependencies
70
- * @cowprotocol/events bumped to 3.3.1
71
- * @cowprotocol/types bumped to 3.3.1
72
- * @cowprotocol/widget-lib bumped to 1.2.1
73
-
74
- ## [1.0.6](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.5...widget-react-v1.0.6) (2026-02-20)
75
-
76
-
77
- ### Dependencies
78
-
79
- * The following workspace dependencies were updated
80
- * dependencies
81
- * @cowprotocol/events bumped to 3.3.0
82
- * @cowprotocol/types bumped to 3.3.0
83
- * @cowprotocol/widget-lib bumped to 1.2.0
84
-
85
- ## [1.0.5](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.4...widget-react-v1.0.5) (2026-02-13)
86
-
87
-
88
- ### Dependencies
89
-
90
- * The following workspace dependencies were updated
91
- * dependencies
92
- * @cowprotocol/events bumped to 3.2.0
93
- * @cowprotocol/types bumped to 3.2.0
94
- * @cowprotocol/widget-lib bumped to 1.1.2
95
-
96
- ## [1.0.4](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.3...widget-react-v1.0.4) (2026-02-10)
97
-
98
-
99
- ### Dependencies
100
-
101
- * The following workspace dependencies were updated
102
- * dependencies
103
- * @cowprotocol/widget-lib bumped to 1.1.1
104
-
105
- ## [1.0.3](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.2...widget-react-v1.0.3) (2026-02-09)
106
-
107
-
108
- ### 🐛 Bug Fixes
109
-
110
- * clean up widget-react lib code ([#6982](https://github.com/cowprotocol/cowswap/issues/6982)) ([2283aba](https://github.com/cowprotocol/cowswap/commit/2283aba8ea22ba219d7ddd8059478a524e50915e))
111
-
112
- ## [1.0.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.1...widget-react-v1.0.2) (2026-02-05)
113
-
114
-
115
- ### Dependencies
116
-
117
- * The following workspace dependencies were updated
118
- * dependencies
119
- * @cowprotocol/events bumped to 3.1.0
120
- * @cowprotocol/types bumped to 3.1.0
121
- * @cowprotocol/widget-lib bumped to 1.1.0
122
-
123
- ## [1.0.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.0...widget-react-v1.0.1) (2026-02-02)
124
-
125
-
126
- ### Dependencies
127
-
128
- * The following workspace dependencies were updated
129
- * dependencies
130
- * @cowprotocol/events bumped to 3.0.1
131
- * @cowprotocol/types bumped to 3.0.1
132
- * @cowprotocol/widget-lib bumped to 1.0.1
133
-
134
- ## [1.0.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.6...widget-react-v1.0.0) (2026-01-28)
135
-
136
-
137
- ### ⚠ BREAKING CHANGES
138
-
139
- * migrate from yarn to pnpm ([#6847](https://github.com/cowprotocol/cowswap/issues/6847))
140
-
141
- ### Features
142
-
143
- * migrate from yarn to pnpm ([#6847](https://github.com/cowprotocol/cowswap/issues/6847)) ([1c5d115](https://github.com/cowprotocol/cowswap/commit/1c5d11516d0ddb997b0ebbb4eee4adcb491204a4))
144
-
145
-
146
- ### Dependencies
147
-
148
- * The following workspace dependencies were updated
149
- * dependencies
150
- * @cowprotocol/events bumped to 3.0.0
151
- * @cowprotocol/types bumped to 3.0.0
152
- * @cowprotocol/widget-lib bumped to 1.0.0
153
-
154
- ## [0.14.6](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.5...widget-react-v0.14.6) (2026-01-26)
155
-
156
-
157
- ### Dependencies
158
-
159
- * The following workspace dependencies were updated
160
- * dependencies
161
- * @cowprotocol/widget-lib bumped from ^0.22.2 to ^0.22.3
162
-
163
- ## [0.14.5](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.4...widget-react-v0.14.5) (2026-01-26)
164
-
165
-
166
- ### Dependencies
167
-
168
- * The following workspace dependencies were updated
169
- * dependencies
170
- * @cowprotocol/widget-lib bumped from ^0.22.1 to ^0.22.2
171
-
172
- ## [0.14.4](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.3...widget-react-v0.14.4) (2025-12-24)
173
-
174
-
175
- ### Dependencies
176
-
177
- * The following workspace dependencies were updated
178
- * dependencies
179
- * @cowprotocol/widget-lib bumped from ^0.22.0 to ^0.22.1
180
-
181
- ## [0.14.3](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.2...widget-react-v0.14.3) (2025-12-22)
182
-
183
-
184
- ### Dependencies
185
-
186
- * The following workspace dependencies were updated
187
- * dependencies
188
- * @cowprotocol/widget-lib bumped from ^0.21.1 to ^0.22.0
189
-
190
- ## [0.14.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.1...widget-react-v0.14.2) (2025-12-16)
191
-
192
-
193
- ### Dependencies
194
-
195
- * The following workspace dependencies were updated
196
- * dependencies
197
- * @cowprotocol/widget-lib bumped from ^0.21.0 to ^0.21.1
198
-
199
- ## [0.14.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.11.2...widget-react-v0.14.1) (2025-11-24)
200
-
201
-
202
- ### Dependencies
203
-
204
- * The following workspace dependencies were updated
205
- * dependencies
206
- * @cowprotocol/widget-lib bumped from ^0.20.0 to ^0.21.0
207
-
208
- ## [0.11.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.11.1...widget-react-v0.11.2) (2025-06-18)
209
-
210
-
211
- ### Bug Fixes
212
-
213
- * make order progress bar UI more stable ([#5834](https://github.com/cowprotocol/cowswap/issues/5834)) ([80cebd1](https://github.com/cowprotocol/cowswap/commit/80cebd1104a0a2e30e12ce8a4b3d62c212559cec))
214
-
215
- ## [0.11.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.11.0...widget-react-v0.11.1) (2025-05-19)
216
-
217
-
218
- ### Bug Fixes
219
-
220
- * **dev-deps-update:** bump the dev-deps group with 76 updates ([#5663](https://github.com/cowprotocol/cowswap/issues/5663)) ([552b349](https://github.com/cowprotocol/cowswap/commit/552b349f53762a01ccf008e9a2083248424cbafa))
221
-
222
- ## [0.11.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.10.2...widget-react-v0.11.0) (2024-09-30)
223
-
224
-
225
- ### Features
226
-
227
- * **hooks-store:** support iframe hook-dapps ([#4885](https://github.com/cowprotocol/cowswap/issues/4885)) ([5116f29](https://github.com/cowprotocol/cowswap/commit/5116f296a0e4866d0a51a806b7abe55e809d26e9))
228
-
229
- ## [0.10.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.10.1...widget-react-v0.10.2) (2024-09-17)
230
-
231
-
232
- ### Bug Fixes
233
-
234
- * **libs:** fix import error on multiple libs ([#4869](https://github.com/cowprotocol/cowswap/issues/4869)) ([8cfd70b](https://github.com/cowprotocol/cowswap/commit/8cfd70b6000a1a021b76ad1f924829cb42cb2bcd))
235
-
236
- ## [0.10.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.10.0...widget-react-v0.10.1) (2024-09-05)
237
-
238
-
239
- ### Bug Fixes
240
-
241
- * **widget-react:** fix @cowprotocol/widget-lib build export path ([#4839](https://github.com/cowprotocol/cowswap/issues/4839)) ([2b56673](https://github.com/cowprotocol/cowswap/commit/2b566737e603aeca7f278c059c892f6cc6fe539d))
242
-
243
- ## [0.10.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.9.0...widget-react-v0.10.0) (2024-08-28)
244
-
245
-
246
- ### Features
247
-
248
- * **widget-react:** bump widget-lib version to 0.14.0 ([468e780](https://github.com/cowprotocol/cowswap/commit/468e78047acaf577b66a22798bcf2298d5ed426a))
249
-
250
- ## [0.9.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.8.2...widget-react-v0.9.0) (2024-05-01)
251
-
252
-
253
- ### Features
254
-
255
- * allow to specify your own fee label and tooltip ([#4350](https://github.com/cowprotocol/cowswap/issues/4350)) ([e5955d4](https://github.com/cowprotocol/cowswap/commit/e5955d479e099f6e1f68ec0531d57fe26a59f63d))
256
-
257
- ## [0.8.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.8.1...widget-react-v0.8.2) (2024-04-23)
258
-
259
-
260
- ### Bug Fixes
261
-
262
- * update widget-lib version ([#4294](https://github.com/cowprotocol/cowswap/issues/4294)) ([84e5d41](https://github.com/cowprotocol/cowswap/commit/84e5d41f40475d108e53975290c571631b430f02))
263
-
264
- ## [0.8.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.8.0...widget-react-v0.8.1) (2024-04-18)
265
-
266
-
267
- ### Bug Fixes
268
-
269
- * rearrange widget imports ([b297608](https://github.com/cowprotocol/cowswap/commit/b297608ff3005295322cbd58a19d3fb7c00f5653))
270
- * cleanup widget to prevent memory leaks ([#4262][https://github.com/cowprotocol/cowswap/pull/4262])
271
-
272
- ## [0.8.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.7.0...widget-react-v0.8.0) (2024-04-15)
273
-
274
-
275
- ### Features
276
-
277
- * make widget to use all space ([#4197](https://github.com/cowprotocol/cowswap/issues/4197)) ([3ab6cb9](https://github.com/cowprotocol/cowswap/commit/3ab6cb98f03e571670031248af9419f301bbdaf8))
278
- * up widget-lib version ([#4085](https://github.com/cowprotocol/cowswap/issues/4085)) ([a64efee](https://github.com/cowprotocol/cowswap/commit/a64efeec97ef3309431c19653c3e35d085bc27ff))
279
- * **widget-react:** update widget-lib ([#3674](https://github.com/cowprotocol/cowswap/issues/3674)) ([26b4776](https://github.com/cowprotocol/cowswap/commit/26b477659a157e3c04ccac0e62907f95ad901559))
280
- * **widget:** add error handling for React widget ([#3823](https://github.com/cowprotocol/cowswap/issues/3823)) ([dfc3e4c](https://github.com/cowprotocol/cowswap/commit/dfc3e4c8848b8d47a3858f3415959cc80972baed))
281
- * **widget:** implement all listeners and fix types ([#3817](https://github.com/cowprotocol/cowswap/issues/3817)) ([11a7226](https://github.com/cowprotocol/cowswap/commit/11a7226a5d3811139e784fe668ee2eebf2167a38))
282
- * **widget:** misc to address issues and comments ([#3827](https://github.com/cowprotocol/cowswap/issues/3827)) ([ef83a5a](https://github.com/cowprotocol/cowswap/commit/ef83a5ad520d072ebf4f2cccde5fcfd0c1d88cd2))
283
- * **widget:** optimise widget updates ([#3822](https://github.com/cowprotocol/cowswap/issues/3822)) ([d1a1e7d](https://github.com/cowprotocol/cowswap/commit/d1a1e7d05a1fed94dece9afbbc65f43af1a4f748))
284
- * **widget:** subscribe to cow events (from iframe) ([#3816](https://github.com/cowprotocol/cowswap/issues/3816)) ([c3b8104](https://github.com/cowprotocol/cowswap/commit/c3b810435a6e64b12d28aac12cf785eef52f6531))
285
-
286
-
287
- ### Bug Fixes
288
-
289
- * connect wallet not working ([#3863](https://github.com/cowprotocol/cowswap/issues/3863)) ([b3e4eb7](https://github.com/cowprotocol/cowswap/commit/b3e4eb7b32ff946f529b08ac853da6ec094f6a19))
290
- * minimal widget-react changes to force release-please bump ([#3776](https://github.com/cowprotocol/cowswap/issues/3776)) ([8d3d9d6](https://github.com/cowprotocol/cowswap/commit/8d3d9d691232c7cba67dbcb6f22f4581e73d012a))
291
- * **widget:** solve issues arising when changing the provider ([#3825](https://github.com/cowprotocol/cowswap/issues/3825)) ([2f81380](https://github.com/cowprotocol/cowswap/commit/2f81380d3e2a49a63c9da4e5fedb11e378fb3c8c))
292
-
293
- ## [0.7.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.5.0...widget-react-v0.7.0) (2024-04-11)
294
-
295
- ### Features
296
-
297
- - make widget to use all space ([#4197](https://github.com/cowprotocol/cowswap/issues/4197)) ([3ab6cb9](https://github.com/cowprotocol/cowswap/commit/3ab6cb98f03e571670031248af9419f301bbdaf8))
298
-
299
- ## [0.5.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.4.0...widget-react-v0.5.0) (2024-03-22)
300
-
301
- ### Features
302
-
303
- - up widget-lib version ([#4085](https://github.com/cowprotocol/cowswap/issues/4085)) ([a64efee](https://github.com/cowprotocol/cowswap/commit/a64efeec97ef3309431c19653c3e35d085bc27ff))
304
-
305
- ## [0.4.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.3.0...widget-react-v0.4.0) (2024-02-22)
306
-
307
- ### Features
308
-
309
- - **widget:** add error handling for React widget ([#3823](https://github.com/cowprotocol/cowswap/issues/3823)) ([dfc3e4c](https://github.com/cowprotocol/cowswap/commit/dfc3e4c8848b8d47a3858f3415959cc80972baed))
310
- - **widget:** implement all listeners and fix types ([#3817](https://github.com/cowprotocol/cowswap/issues/3817)) ([11a7226](https://github.com/cowprotocol/cowswap/commit/11a7226a5d3811139e784fe668ee2eebf2167a38))
311
- - **widget:** misc to address issues and comments ([#3827](https://github.com/cowprotocol/cowswap/issues/3827)) ([ef83a5a](https://github.com/cowprotocol/cowswap/commit/ef83a5ad520d072ebf4f2cccde5fcfd0c1d88cd2))
312
- - **widget:** optimise widget updates ([#3822](https://github.com/cowprotocol/cowswap/issues/3822)) ([d1a1e7d](https://github.com/cowprotocol/cowswap/commit/d1a1e7d05a1fed94dece9afbbc65f43af1a4f748))
313
- - **widget:** subscribe to cow events (from iframe) ([#3816](https://github.com/cowprotocol/cowswap/issues/3816)) ([c3b8104](https://github.com/cowprotocol/cowswap/commit/c3b810435a6e64b12d28aac12cf785eef52f6531))
314
-
315
- ### Bug Fixes
316
-
317
- - connect wallet not working ([#3863](https://github.com/cowprotocol/cowswap/issues/3863)) ([b3e4eb7](https://github.com/cowprotocol/cowswap/commit/b3e4eb7b32ff946f529b08ac853da6ec094f6a19))
318
- - minimal widget-react changes to force release-please bump ([#3776](https://github.com/cowprotocol/cowswap/issues/3776)) ([8d3d9d6](https://github.com/cowprotocol/cowswap/commit/8d3d9d691232c7cba67dbcb6f22f4581e73d012a))
319
- - **widget:** solve issues arising when changing the provider ([#3825](https://github.com/cowprotocol/cowswap/issues/3825)) ([2f81380](https://github.com/cowprotocol/cowswap/commit/2f81380d3e2a49a63c9da4e5fedb11e378fb3c8c))
320
-
321
- ## [0.3.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.2.3...widget-react-v0.3.0) (2024-01-17)
322
-
323
- ### Features
324
-
325
- - **widget-react:** update widget-lib ([#3674](https://github.com/cowprotocol/cowswap/issues/3674)) ([26b4776](https://github.com/cowprotocol/cowswap/commit/26b477659a157e3c04ccac0e62907f95ad901559))
package/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from './lib/CowSwapWidget';
2
- export * from '@cowprotocol/widget-lib';
3
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/widget-react/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA"}
@@ -1,101 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useRef, useState } from 'react';
3
- import { createCowSwapWidget, } from '@cowprotocol/widget-lib';
4
- export function CowSwapWidget(props) {
5
- const { params, provider, listeners } = props;
6
- const [error, setError] = useState(null);
7
- const paramsRef = useRef(null);
8
- const providerRef = useRef(provider);
9
- const listenersRef = useRef(listeners);
10
- const containerRef = useRef(null);
11
- const widgetHandlerRef = useRef(null);
12
- // Error handling
13
- const tryOrHandleError = useCallback((action, actionThatMightFail) => {
14
- try {
15
- console.log(`[WIDGET] ${action}`);
16
- actionThatMightFail();
17
- }
18
- catch (error) {
19
- const errorMessage = `Error ${action.toLowerCase()}`;
20
- console.error(`[WIDGET] ${errorMessage}`, error);
21
- setError({ message: errorMessage, error });
22
- }
23
- }, []);
24
- // Cleanup widget on mount
25
- useEffect(() => {
26
- return () => {
27
- // Cleanup references
28
- paramsRef.current = null;
29
- providerRef.current = undefined;
30
- listenersRef.current = undefined;
31
- // Destroy widget
32
- const handler = widgetHandlerRef.current;
33
- if (handler) {
34
- tryOrHandleError('💥 Destroy widget', () => handler.destroy());
35
- widgetHandlerRef.current = null;
36
- }
37
- };
38
- // eslint-disable-next-line react-hooks/exhaustive-deps
39
- }, []);
40
- // Create/Update the widget if the parameters change
41
- useEffect(() => {
42
- if (!containerRef.current || JSON.stringify(paramsRef.current) === JSON.stringify(params)) {
43
- return;
44
- }
45
- const container = containerRef.current;
46
- const handler = widgetHandlerRef.current;
47
- paramsRef.current = params;
48
- if (handler === null) {
49
- tryOrHandleError('Creating a new widget', () => {
50
- widgetHandlerRef.current = createCowSwapWidget(container, { params, provider: providerRef.current, listeners });
51
- listenersRef.current = listeners;
52
- });
53
- }
54
- else {
55
- tryOrHandleError('Updating the widget', () => handler.updateParams(params));
56
- }
57
- // Trigger only on params changes
58
- // eslint-disable-next-line react-hooks/exhaustive-deps
59
- }, [params, tryOrHandleError]);
60
- // Update widget provider (if it changes)
61
- useEffect(() => {
62
- if (!widgetHandlerRef.current || providerRef.current === provider) {
63
- return;
64
- }
65
- // Update provider
66
- providerRef.current = provider;
67
- // TODO: Fix this https://github.com/cowprotocol/cowswap/issues/3810#issue-2127257473 (in meantime forcing full refresh as before)
68
- // const handler = widgetHandlerRef.current
69
- // tryOrHandleError('Updating the provider', () => {
70
- // handler.updateProvider(provider)
71
- // if (paramsRef.current) {
72
- // handler.updateWidget(paramsRef.current)
73
- // }
74
- // })
75
- const container = containerRef.current;
76
- if (container) {
77
- tryOrHandleError('Updating the provider', () => {
78
- // Destroy the old widget (if it exists)
79
- widgetHandlerRef.current?.destroy();
80
- // Re-create the widget
81
- widgetHandlerRef.current = createCowSwapWidget(container, { params, provider: providerRef.current, listeners });
82
- });
83
- }
84
- // Trigger only on provider changes
85
- // eslint-disable-next-line react-hooks/exhaustive-deps
86
- }, [provider, tryOrHandleError]);
87
- // Update widget listeners (if they change)
88
- useEffect(() => {
89
- if (!widgetHandlerRef.current || listenersRef.current === listeners)
90
- return;
91
- const handler = widgetHandlerRef.current;
92
- tryOrHandleError('Updating the listeners', () => handler.updateListeners(listeners));
93
- }, [listeners, tryOrHandleError]);
94
- // Handle errors
95
- if (error) {
96
- return (_jsxs("div", { style: { color: '#ff3a3a' }, children: [error.message, error.error.message && _jsx("pre", { style: { whiteSpace: 'pre-wrap', fontSize: '0.75em' }, children: error.error.message })] }));
97
- }
98
- // Render widget container
99
- return _jsx("div", { ref: containerRef, style: { width: '100%' } });
100
- }
101
- //# sourceMappingURL=CowSwapWidget.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CowSwapWidget.js","sourceRoot":"","sources":["../../../../../libs/widget-react/src/lib/CowSwapWidget.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAa,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAI3E,OAAO,EAKL,mBAAmB,GACpB,MAAM,yBAAyB,CAAA;AAEhC,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAA;IAC7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAA2C,IAAI,CAAC,CAAA;IAClF,MAAM,SAAS,GAAG,MAAM,CAA6B,IAAI,CAAC,CAAA;IAC1D,MAAM,WAAW,GAAG,MAAM,CAA+B,QAAQ,CAAC,CAAA;IAClE,MAAM,YAAY,GAAG,MAAM,CAAsC,SAAS,CAAC,CAAA;IAC3E,MAAM,YAAY,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAA;IACxD,MAAM,gBAAgB,GAAG,MAAM,CAA8B,IAAI,CAAC,CAAA;IAElE,iBAAiB;IACjB,MAAM,gBAAgB,GAAG,WAAW,CAAC,CAAC,MAAc,EAAE,mBAA4B,EAAE,EAAE;QACpF,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,YAAY,MAAM,EAAE,CAAC,CAAA;YACjC,mBAAmB,EAAE,CAAA;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,SAAS,MAAM,CAAC,WAAW,EAAE,EAAE,CAAA;YACpD,OAAO,CAAC,KAAK,CAAC,YAAY,YAAY,EAAE,EAAE,KAAK,CAAC,CAAA;YAChD,QAAQ,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CA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