@cowprotocol/widget-react 1.0.10 → 1.1.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 f=require("@cowprotocol/widget-lib"),y=require("react/jsx-runtime"),r=require("react");function m(o){const{params:c,provider:i,listeners:s}=o,[a,S]=r.useState(null),p=r.useRef(null),u=r.useRef(i),g=r.useRef(s),l=r.useRef(null),t=r.useRef(null),n=r.useCallback((e,d)=>{try{console.log(`[WIDGET] ${e}`),d()}catch(w){const h=`Error ${e.toLowerCase()}`,E=w instanceof Error?w:new Error("Unknown CowSwapWidget error",{cause:w});console.error(`[WIDGET] ${h}`,E),S({message:h,error:E})}},[]);return r.useEffect(()=>()=>{p.current=null,u.current=void 0,g.current=void 0;const e=t.current;e&&(n("💥 Destroy widget",()=>e.destroy()),t.current=null)},[]),r.useEffect(()=>{if(!l.current||JSON.stringify(p.current)===JSON.stringify(c))return;const e=l.current,d=t.current;p.current=c,d===null?n("Creating a new widget",()=>{t.current=f.createCowSwapWidget(e,{params:c,provider:u.current,listeners:s}),g.current=s}):n("Updating the widget",()=>d.updateParams(c))},[c,n]),r.useEffect(()=>{if(!t.current||u.current===i)return;u.current=i;const e=l.current;e&&n("Updating the provider",()=>{t.current?.destroy(),t.current=f.createCowSwapWidget(e,{params:c,provider:u.current,listeners:s})})},[i,n]),r.useEffect(()=>{if(!t.current||g.current===s)return;const e=t.current;n("Updating the listeners",()=>e.updateListeners(s))},[s,n]),a?y.jsxs("div",{style:{color:"#ff3a3a"},children:[a.message,a.error.message&&y.jsx("pre",{style:{whiteSpace:"pre-wrap",fontSize:"0.75em"},children:a.error.message})]}):y.jsx("div",{ref:l,style:{width:"100%"}})}exports.CowSwapWidget=m;Object.keys(f).forEach(o=>{o!=="default"&&!Object.prototype.hasOwnProperty.call(exports,o)&&Object.defineProperty(exports,o,{enumerable:!0,get:()=>f[o]})});
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from '@cowprotocol/widget-lib';
2
+ export * from './lib/CowSwapWidget';
package/index.js ADDED
@@ -0,0 +1,68 @@
1
+ import { createCowSwapWidget as h } from "@cowprotocol/widget-lib";
2
+ export * from "@cowprotocol/widget-lib";
3
+ import { jsxs as S, jsx as y } from "react/jsx-runtime";
4
+ import { useState as C, useRef as c, useCallback as R, useEffect as d } from "react";
5
+ function D(v) {
6
+ const {
7
+ params: o,
8
+ provider: i,
9
+ listeners: n
10
+ } = v, [u, E] = C(null), f = c(null), s = c(i), p = c(n), a = c(null), e = c(null), t = R((r, l) => {
11
+ try {
12
+ console.log(`[WIDGET] ${r}`), l();
13
+ } catch (g) {
14
+ const w = `Error ${r.toLowerCase()}`, m = g instanceof Error ? g : new Error("Unknown CowSwapWidget error", {
15
+ cause: g
16
+ });
17
+ console.error(`[WIDGET] ${w}`, m), E({
18
+ message: w,
19
+ error: m
20
+ });
21
+ }
22
+ }, []);
23
+ return d(() => () => {
24
+ f.current = null, s.current = void 0, p.current = void 0;
25
+ const r = e.current;
26
+ r && (t("💥 Destroy widget", () => r.destroy()), e.current = null);
27
+ }, []), d(() => {
28
+ if (!a.current || JSON.stringify(f.current) === JSON.stringify(o))
29
+ return;
30
+ const r = a.current, l = e.current;
31
+ f.current = o, l === null ? t("Creating a new widget", () => {
32
+ e.current = h(r, {
33
+ params: o,
34
+ provider: s.current,
35
+ listeners: n
36
+ }), p.current = n;
37
+ }) : t("Updating the widget", () => l.updateParams(o));
38
+ }, [o, t]), d(() => {
39
+ if (!e.current || s.current === i)
40
+ return;
41
+ s.current = i;
42
+ const r = a.current;
43
+ r && t("Updating the provider", () => {
44
+ e.current?.destroy(), e.current = h(r, {
45
+ params: o,
46
+ provider: s.current,
47
+ listeners: n
48
+ });
49
+ });
50
+ }, [i, t]), d(() => {
51
+ if (!e.current || p.current === n) return;
52
+ const r = e.current;
53
+ t("Updating the listeners", () => r.updateListeners(n));
54
+ }, [n, t]), u ? /* @__PURE__ */ S("div", { style: {
55
+ color: "#ff3a3a"
56
+ }, children: [
57
+ u.message,
58
+ u.error.message && /* @__PURE__ */ y("pre", { style: {
59
+ whiteSpace: "pre-wrap",
60
+ fontSize: "0.75em"
61
+ }, children: u.error.message })
62
+ ] }) : /* @__PURE__ */ y("div", { ref: a, style: {
63
+ width: "100%"
64
+ } });
65
+ }
66
+ export {
67
+ D as CowSwapWidget
68
+ };
@@ -0,0 +1,3 @@
1
+ import { JSX } from 'react';
2
+ import { CowSwapWidgetProps } from '@cowprotocol/widget-lib';
3
+ export declare function CowSwapWidget(props: CowSwapWidgetProps): JSX.Element;
package/package.json CHANGED
@@ -1,23 +1,35 @@
1
1
  {
2
2
  "name": "@cowprotocol/widget-react",
3
- "version": "1.0.10",
3
+ "version": "1.1.0",
4
4
  "description": "CoW Swap Widget Library. Allows you to easily embed a CoW Swap widget on your React application.",
5
- "type": "commonjs",
6
- "main": "./src/index.ts",
7
- "types": "./src/index.d.ts",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/cowprotocol/cowswap.git",
8
+ "directory": "libs/widget-react"
9
+ },
10
+ "type": "module",
11
+ "main": "./index.js",
12
+ "types": "./index.d.ts",
8
13
  "license": "ISC",
9
14
  "publishConfig": {
10
15
  "access": "public"
11
16
  },
12
17
  "dependencies": {
13
- "@cowprotocol/events": "4.0.0",
14
- "@cowprotocol/types": "4.0.0",
15
- "@cowprotocol/widget-lib": "2.0.0"
18
+ "@cowprotocol/events": "^4.0.2",
19
+ "@cowprotocol/types": "^4.1.0",
20
+ "@cowprotocol/widget-lib": "^2.0.2"
16
21
  },
17
22
  "devDependencies": {
18
23
  "@types/react": "19.1.3"
19
24
  },
20
25
  "peerDependencies": {
21
26
  "react": "19.1.2"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./index.d.ts",
31
+ "import": "./index.js",
32
+ "require": "./index.cjs"
33
+ }
22
34
  }
23
35
  }
package/CHANGELOG.md DELETED
@@ -1,309 +0,0 @@
1
- # Changelog
2
-
3
- ## [1.0.10](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.9...widget-react-v1.0.10) (2026-03-11)
4
-
5
-
6
- ### Dependencies
7
-
8
- * The following workspace dependencies were updated
9
- * dependencies
10
- * @cowprotocol/events bumped to 4.0.0
11
- * @cowprotocol/types bumped to 4.0.0
12
- * @cowprotocol/widget-lib bumped to 2.0.0
13
-
14
- ## [1.0.9](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.8...widget-react-v1.0.9) (2026-03-10)
15
-
16
-
17
- ### Dependencies
18
-
19
- * The following workspace dependencies were updated
20
- * dependencies
21
- * @cowprotocol/events bumped to 3.4.0
22
- * @cowprotocol/types bumped to 3.4.0
23
- * @cowprotocol/widget-lib bumped to 1.3.0
24
-
25
- ## [1.0.8](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.7...widget-react-v1.0.8) (2026-02-25)
26
-
27
-
28
- ### 🔧 Miscellaneous
29
-
30
- * main -> dev ([9c6611e](https://github.com/cowprotocol/cowswap/commit/9c6611e90a4b23e23f6aaadc513de3c6d7f3b562))
31
-
32
-
33
- ### Dependencies
34
-
35
- * The following workspace dependencies were updated
36
- * dependencies
37
- * @cowprotocol/events bumped to 3.3.2
38
- * @cowprotocol/types bumped to 3.3.2
39
- * @cowprotocol/widget-lib bumped to 1.2.2
40
-
41
- ## [1.0.7](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.6...widget-react-v1.0.7) (2026-02-24)
42
-
43
-
44
- ### 🔧 Miscellaneous
45
-
46
- * merge main into dev 23 02 ([#7062](https://github.com/cowprotocol/cowswap/issues/7062)) ([ac48c9c](https://github.com/cowprotocol/cowswap/commit/ac48c9c83284c6228ba71392edc1c1e0483b53ff))
47
- * release 23-02 ([bab3bf6](https://github.com/cowprotocol/cowswap/commit/bab3bf640c5b0eacc7ead017ea68ab1eb1687aab))
48
-
49
-
50
- ### Dependencies
51
-
52
- * The following workspace dependencies were updated
53
- * dependencies
54
- * @cowprotocol/events bumped to 3.3.1
55
- * @cowprotocol/types bumped to 3.3.1
56
- * @cowprotocol/widget-lib bumped to 1.2.1
57
-
58
- ## [1.0.6](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.5...widget-react-v1.0.6) (2026-02-20)
59
-
60
-
61
- ### Dependencies
62
-
63
- * The following workspace dependencies were updated
64
- * dependencies
65
- * @cowprotocol/events bumped to 3.3.0
66
- * @cowprotocol/types bumped to 3.3.0
67
- * @cowprotocol/widget-lib bumped to 1.2.0
68
-
69
- ## [1.0.5](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.4...widget-react-v1.0.5) (2026-02-13)
70
-
71
-
72
- ### Dependencies
73
-
74
- * The following workspace dependencies were updated
75
- * dependencies
76
- * @cowprotocol/events bumped to 3.2.0
77
- * @cowprotocol/types bumped to 3.2.0
78
- * @cowprotocol/widget-lib bumped to 1.1.2
79
-
80
- ## [1.0.4](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.3...widget-react-v1.0.4) (2026-02-10)
81
-
82
-
83
- ### Dependencies
84
-
85
- * The following workspace dependencies were updated
86
- * dependencies
87
- * @cowprotocol/widget-lib bumped to 1.1.1
88
-
89
- ## [1.0.3](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.2...widget-react-v1.0.3) (2026-02-09)
90
-
91
-
92
- ### 🐛 Bug Fixes
93
-
94
- * clean up widget-react lib code ([#6982](https://github.com/cowprotocol/cowswap/issues/6982)) ([2283aba](https://github.com/cowprotocol/cowswap/commit/2283aba8ea22ba219d7ddd8059478a524e50915e))
95
-
96
- ## [1.0.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.1...widget-react-v1.0.2) (2026-02-05)
97
-
98
-
99
- ### Dependencies
100
-
101
- * The following workspace dependencies were updated
102
- * dependencies
103
- * @cowprotocol/events bumped to 3.1.0
104
- * @cowprotocol/types bumped to 3.1.0
105
- * @cowprotocol/widget-lib bumped to 1.1.0
106
-
107
- ## [1.0.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v1.0.0...widget-react-v1.0.1) (2026-02-02)
108
-
109
-
110
- ### Dependencies
111
-
112
- * The following workspace dependencies were updated
113
- * dependencies
114
- * @cowprotocol/events bumped to 3.0.1
115
- * @cowprotocol/types bumped to 3.0.1
116
- * @cowprotocol/widget-lib bumped to 1.0.1
117
-
118
- ## [1.0.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.6...widget-react-v1.0.0) (2026-01-28)
119
-
120
-
121
- ### ⚠ BREAKING CHANGES
122
-
123
- * migrate from yarn to pnpm ([#6847](https://github.com/cowprotocol/cowswap/issues/6847))
124
-
125
- ### Features
126
-
127
- * migrate from yarn to pnpm ([#6847](https://github.com/cowprotocol/cowswap/issues/6847)) ([1c5d115](https://github.com/cowprotocol/cowswap/commit/1c5d11516d0ddb997b0ebbb4eee4adcb491204a4))
128
-
129
-
130
- ### Dependencies
131
-
132
- * The following workspace dependencies were updated
133
- * dependencies
134
- * @cowprotocol/events bumped to 3.0.0
135
- * @cowprotocol/types bumped to 3.0.0
136
- * @cowprotocol/widget-lib bumped to 1.0.0
137
-
138
- ## [0.14.6](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.5...widget-react-v0.14.6) (2026-01-26)
139
-
140
-
141
- ### Dependencies
142
-
143
- * The following workspace dependencies were updated
144
- * dependencies
145
- * @cowprotocol/widget-lib bumped from ^0.22.2 to ^0.22.3
146
-
147
- ## [0.14.5](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.4...widget-react-v0.14.5) (2026-01-26)
148
-
149
-
150
- ### Dependencies
151
-
152
- * The following workspace dependencies were updated
153
- * dependencies
154
- * @cowprotocol/widget-lib bumped from ^0.22.1 to ^0.22.2
155
-
156
- ## [0.14.4](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.3...widget-react-v0.14.4) (2025-12-24)
157
-
158
-
159
- ### Dependencies
160
-
161
- * The following workspace dependencies were updated
162
- * dependencies
163
- * @cowprotocol/widget-lib bumped from ^0.22.0 to ^0.22.1
164
-
165
- ## [0.14.3](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.2...widget-react-v0.14.3) (2025-12-22)
166
-
167
-
168
- ### Dependencies
169
-
170
- * The following workspace dependencies were updated
171
- * dependencies
172
- * @cowprotocol/widget-lib bumped from ^0.21.1 to ^0.22.0
173
-
174
- ## [0.14.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.14.1...widget-react-v0.14.2) (2025-12-16)
175
-
176
-
177
- ### Dependencies
178
-
179
- * The following workspace dependencies were updated
180
- * dependencies
181
- * @cowprotocol/widget-lib bumped from ^0.21.0 to ^0.21.1
182
-
183
- ## [0.14.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.11.2...widget-react-v0.14.1) (2025-11-24)
184
-
185
-
186
- ### Dependencies
187
-
188
- * The following workspace dependencies were updated
189
- * dependencies
190
- * @cowprotocol/widget-lib bumped from ^0.20.0 to ^0.21.0
191
-
192
- ## [0.11.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.11.1...widget-react-v0.11.2) (2025-06-18)
193
-
194
-
195
- ### Bug Fixes
196
-
197
- * make order progress bar UI more stable ([#5834](https://github.com/cowprotocol/cowswap/issues/5834)) ([80cebd1](https://github.com/cowprotocol/cowswap/commit/80cebd1104a0a2e30e12ce8a4b3d62c212559cec))
198
-
199
- ## [0.11.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.11.0...widget-react-v0.11.1) (2025-05-19)
200
-
201
-
202
- ### Bug Fixes
203
-
204
- * **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))
205
-
206
- ## [0.11.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.10.2...widget-react-v0.11.0) (2024-09-30)
207
-
208
-
209
- ### Features
210
-
211
- * **hooks-store:** support iframe hook-dapps ([#4885](https://github.com/cowprotocol/cowswap/issues/4885)) ([5116f29](https://github.com/cowprotocol/cowswap/commit/5116f296a0e4866d0a51a806b7abe55e809d26e9))
212
-
213
- ## [0.10.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.10.1...widget-react-v0.10.2) (2024-09-17)
214
-
215
-
216
- ### Bug Fixes
217
-
218
- * **libs:** fix import error on multiple libs ([#4869](https://github.com/cowprotocol/cowswap/issues/4869)) ([8cfd70b](https://github.com/cowprotocol/cowswap/commit/8cfd70b6000a1a021b76ad1f924829cb42cb2bcd))
219
-
220
- ## [0.10.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.10.0...widget-react-v0.10.1) (2024-09-05)
221
-
222
-
223
- ### Bug Fixes
224
-
225
- * **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))
226
-
227
- ## [0.10.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.9.0...widget-react-v0.10.0) (2024-08-28)
228
-
229
-
230
- ### Features
231
-
232
- * **widget-react:** bump widget-lib version to 0.14.0 ([468e780](https://github.com/cowprotocol/cowswap/commit/468e78047acaf577b66a22798bcf2298d5ed426a))
233
-
234
- ## [0.9.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.8.2...widget-react-v0.9.0) (2024-05-01)
235
-
236
-
237
- ### Features
238
-
239
- * 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))
240
-
241
- ## [0.8.2](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.8.1...widget-react-v0.8.2) (2024-04-23)
242
-
243
-
244
- ### Bug Fixes
245
-
246
- * update widget-lib version ([#4294](https://github.com/cowprotocol/cowswap/issues/4294)) ([84e5d41](https://github.com/cowprotocol/cowswap/commit/84e5d41f40475d108e53975290c571631b430f02))
247
-
248
- ## [0.8.1](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.8.0...widget-react-v0.8.1) (2024-04-18)
249
-
250
-
251
- ### Bug Fixes
252
-
253
- * rearrange widget imports ([b297608](https://github.com/cowprotocol/cowswap/commit/b297608ff3005295322cbd58a19d3fb7c00f5653))
254
- * cleanup widget to prevent memory leaks ([#4262][https://github.com/cowprotocol/cowswap/pull/4262])
255
-
256
- ## [0.8.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.7.0...widget-react-v0.8.0) (2024-04-15)
257
-
258
-
259
- ### Features
260
-
261
- * make widget to use all space ([#4197](https://github.com/cowprotocol/cowswap/issues/4197)) ([3ab6cb9](https://github.com/cowprotocol/cowswap/commit/3ab6cb98f03e571670031248af9419f301bbdaf8))
262
- * up widget-lib version ([#4085](https://github.com/cowprotocol/cowswap/issues/4085)) ([a64efee](https://github.com/cowprotocol/cowswap/commit/a64efeec97ef3309431c19653c3e35d085bc27ff))
263
- * **widget-react:** update widget-lib ([#3674](https://github.com/cowprotocol/cowswap/issues/3674)) ([26b4776](https://github.com/cowprotocol/cowswap/commit/26b477659a157e3c04ccac0e62907f95ad901559))
264
- * **widget:** add error handling for React widget ([#3823](https://github.com/cowprotocol/cowswap/issues/3823)) ([dfc3e4c](https://github.com/cowprotocol/cowswap/commit/dfc3e4c8848b8d47a3858f3415959cc80972baed))
265
- * **widget:** implement all listeners and fix types ([#3817](https://github.com/cowprotocol/cowswap/issues/3817)) ([11a7226](https://github.com/cowprotocol/cowswap/commit/11a7226a5d3811139e784fe668ee2eebf2167a38))
266
- * **widget:** misc to address issues and comments ([#3827](https://github.com/cowprotocol/cowswap/issues/3827)) ([ef83a5a](https://github.com/cowprotocol/cowswap/commit/ef83a5ad520d072ebf4f2cccde5fcfd0c1d88cd2))
267
- * **widget:** optimise widget updates ([#3822](https://github.com/cowprotocol/cowswap/issues/3822)) ([d1a1e7d](https://github.com/cowprotocol/cowswap/commit/d1a1e7d05a1fed94dece9afbbc65f43af1a4f748))
268
- * **widget:** subscribe to cow events (from iframe) ([#3816](https://github.com/cowprotocol/cowswap/issues/3816)) ([c3b8104](https://github.com/cowprotocol/cowswap/commit/c3b810435a6e64b12d28aac12cf785eef52f6531))
269
-
270
-
271
- ### Bug Fixes
272
-
273
- * connect wallet not working ([#3863](https://github.com/cowprotocol/cowswap/issues/3863)) ([b3e4eb7](https://github.com/cowprotocol/cowswap/commit/b3e4eb7b32ff946f529b08ac853da6ec094f6a19))
274
- * 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))
275
- * **widget:** solve issues arising when changing the provider ([#3825](https://github.com/cowprotocol/cowswap/issues/3825)) ([2f81380](https://github.com/cowprotocol/cowswap/commit/2f81380d3e2a49a63c9da4e5fedb11e378fb3c8c))
276
-
277
- ## [0.7.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.5.0...widget-react-v0.7.0) (2024-04-11)
278
-
279
- ### Features
280
-
281
- - make widget to use all space ([#4197](https://github.com/cowprotocol/cowswap/issues/4197)) ([3ab6cb9](https://github.com/cowprotocol/cowswap/commit/3ab6cb98f03e571670031248af9419f301bbdaf8))
282
-
283
- ## [0.5.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.4.0...widget-react-v0.5.0) (2024-03-22)
284
-
285
- ### Features
286
-
287
- - up widget-lib version ([#4085](https://github.com/cowprotocol/cowswap/issues/4085)) ([a64efee](https://github.com/cowprotocol/cowswap/commit/a64efeec97ef3309431c19653c3e35d085bc27ff))
288
-
289
- ## [0.4.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.3.0...widget-react-v0.4.0) (2024-02-22)
290
-
291
- ### Features
292
-
293
- - **widget:** add error handling for React widget ([#3823](https://github.com/cowprotocol/cowswap/issues/3823)) ([dfc3e4c](https://github.com/cowprotocol/cowswap/commit/dfc3e4c8848b8d47a3858f3415959cc80972baed))
294
- - **widget:** implement all listeners and fix types ([#3817](https://github.com/cowprotocol/cowswap/issues/3817)) ([11a7226](https://github.com/cowprotocol/cowswap/commit/11a7226a5d3811139e784fe668ee2eebf2167a38))
295
- - **widget:** misc to address issues and comments ([#3827](https://github.com/cowprotocol/cowswap/issues/3827)) ([ef83a5a](https://github.com/cowprotocol/cowswap/commit/ef83a5ad520d072ebf4f2cccde5fcfd0c1d88cd2))
296
- - **widget:** optimise widget updates ([#3822](https://github.com/cowprotocol/cowswap/issues/3822)) ([d1a1e7d](https://github.com/cowprotocol/cowswap/commit/d1a1e7d05a1fed94dece9afbbc65f43af1a4f748))
297
- - **widget:** subscribe to cow events (from iframe) ([#3816](https://github.com/cowprotocol/cowswap/issues/3816)) ([c3b8104](https://github.com/cowprotocol/cowswap/commit/c3b810435a6e64b12d28aac12cf785eef52f6531))
298
-
299
- ### Bug Fixes
300
-
301
- - connect wallet not working ([#3863](https://github.com/cowprotocol/cowswap/issues/3863)) ([b3e4eb7](https://github.com/cowprotocol/cowswap/commit/b3e4eb7b32ff946f529b08ac853da6ec094f6a19))
302
- - 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))
303
- - **widget:** solve issues arising when changing the provider ([#3825](https://github.com/cowprotocol/cowswap/issues/3825)) ([2f81380](https://github.com/cowprotocol/cowswap/commit/2f81380d3e2a49a63c9da4e5fedb11e378fb3c8c))
304
-
305
- ## [0.3.0](https://github.com/cowprotocol/cowswap/compare/widget-react-v0.2.3...widget-react-v0.3.0) (2024-01-17)
306
-
307
- ### Features
308
-
309
- - **widget-react:** update widget-lib ([#3674](https://github.com/cowprotocol/cowswap/issues/3674)) ([26b4776](https://github.com/cowprotocol/cowswap/commit/26b477659a157e3c04ccac0e62907f95ad901559))
package/jest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- export default {
2
- displayName: 'widget-react',
3
- preset: '../../jest.preset.js',
4
- transform: {
5
- '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
6
- '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
7
- },
8
- setupFilesAfterEnv: ['../../jest.setup.ts'],
9
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
10
- coverageDirectory: '../../../coverage/libs/widget-react',
11
- }
package/project.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "name": "widget-react",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/widget-react/src",
5
- "projectType": "library",
6
- "tags": [],
7
- "targets": {
8
- "lint": {
9
- "executor": "@nx/eslint:lint",
10
- "outputs": ["{options.outputFile}"],
11
- "options": {
12
- "lintFilePatterns": ["libs/widget-react/**/*.{ts,tsx,js,jsx}"]
13
- }
14
- },
15
- "build": {
16
- "executor": "@nx/js:tsc",
17
- "outputs": ["{options.outputPath}"],
18
- "options": {
19
- "outputPath": "dist/libs/widget-react",
20
- "main": "libs/widget-react/src/index.ts",
21
- "tsConfig": "libs/widget-react/tsconfig.lib.json",
22
- "assets": ["libs/widget-react/*.md"],
23
- "updateBuildableProjectDepsInPackageJson": true,
24
- "buildableProjectDepsInPackageJsonType": "dependencies"
25
- }
26
- },
27
- "test": {
28
- "executor": "@nx/jest:jest",
29
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
30
- "options": {
31
- "jestConfig": "libs/widget-react/jest.config.ts",
32
- "passWithNoTests": true
33
- },
34
- "configurations": {
35
- "ci": {
36
- "ci": true,
37
- "codeCoverage": true
38
- }
39
- }
40
- }
41
- }
42
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/CowSwapWidget'
2
- export * from '@cowprotocol/widget-lib'
@@ -1,7 +0,0 @@
1
- import { CowSwapWidget } from './CowSwapWidget'
2
-
3
- describe('CowSwapWidget', () => {
4
- it('should render successfully', () => {
5
- expect(CowSwapWidget).toBeTruthy()
6
- })
7
- })
@@ -1,125 +0,0 @@
1
- import { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
2
-
3
- import type { CowWidgetEventListeners } from '@cowprotocol/events'
4
- import type { Command } from '@cowprotocol/types'
5
- import {
6
- CowSwapWidgetHandler,
7
- CowSwapWidgetParams,
8
- CowSwapWidgetProps,
9
- EthereumProvider,
10
- createCowSwapWidget,
11
- } from '@cowprotocol/widget-lib'
12
-
13
- export function CowSwapWidget(props: CowSwapWidgetProps): ReactNode {
14
- const { params, provider, listeners } = props
15
- const [error, setError] = useState<{ error: Error; message: string } | null>(null)
16
- const paramsRef = useRef<CowSwapWidgetParams | null>(null)
17
- const providerRef = useRef<EthereumProvider | undefined>(provider)
18
- const listenersRef = useRef<CowWidgetEventListeners | undefined>(listeners)
19
- const containerRef = useRef<HTMLDivElement | null>(null)
20
- const widgetHandlerRef = useRef<CowSwapWidgetHandler | null>(null)
21
-
22
- // Error handling
23
- const tryOrHandleError = useCallback((action: string, actionThatMightFail: Command) => {
24
- try {
25
- console.log(`[WIDGET] ${action}`)
26
- actionThatMightFail()
27
- } catch (error) {
28
- const errorMessage = `Error ${action.toLowerCase()}`
29
- console.error(`[WIDGET] ${errorMessage}`, error)
30
- setError({ message: errorMessage, error })
31
- }
32
- }, [])
33
-
34
- // Cleanup widget on mount
35
- useEffect(() => {
36
- return () => {
37
- // Cleanup references
38
- paramsRef.current = null
39
- providerRef.current = undefined
40
- listenersRef.current = undefined
41
-
42
- // Destroy widget
43
- const handler = widgetHandlerRef.current
44
- if (handler) {
45
- tryOrHandleError('💥 Destroy widget', () => handler.destroy())
46
- widgetHandlerRef.current = null
47
- }
48
- }
49
- // eslint-disable-next-line react-hooks/exhaustive-deps
50
- }, [])
51
-
52
- // Create/Update the widget if the parameters change
53
- useEffect(() => {
54
- if (!containerRef.current || JSON.stringify(paramsRef.current) === JSON.stringify(params)) {
55
- return
56
- }
57
-
58
- const container = containerRef.current
59
- const handler = widgetHandlerRef.current
60
- paramsRef.current = params
61
-
62
- if (handler === null) {
63
- tryOrHandleError('Creating a new widget', () => {
64
- widgetHandlerRef.current = createCowSwapWidget(container, { params, provider: providerRef.current, listeners })
65
- listenersRef.current = listeners
66
- })
67
- } else {
68
- tryOrHandleError('Updating the widget', () => handler.updateParams(params))
69
- }
70
- // Trigger only on params changes
71
- // eslint-disable-next-line react-hooks/exhaustive-deps
72
- }, [params, tryOrHandleError])
73
-
74
- // Update widget provider (if it changes)
75
- useEffect(() => {
76
- if (!widgetHandlerRef.current || providerRef.current === provider) {
77
- return
78
- }
79
-
80
- // Update provider
81
- providerRef.current = provider
82
-
83
- // TODO: Fix this https://github.com/cowprotocol/cowswap/issues/3810#issue-2127257473 (in meantime forcing full refresh as before)
84
- // const handler = widgetHandlerRef.current
85
- // tryOrHandleError('Updating the provider', () => {
86
- // handler.updateProvider(provider)
87
- // if (paramsRef.current) {
88
- // handler.updateWidget(paramsRef.current)
89
- // }
90
- // })
91
- const container = containerRef.current
92
- if (container) {
93
- tryOrHandleError('Updating the provider', () => {
94
- // Destroy the old widget (if it exists)
95
- widgetHandlerRef.current?.destroy()
96
-
97
- // Re-create the widget
98
- widgetHandlerRef.current = createCowSwapWidget(container, { params, provider: providerRef.current, listeners })
99
- })
100
- }
101
- // Trigger only on provider changes
102
- // eslint-disable-next-line react-hooks/exhaustive-deps
103
- }, [provider, tryOrHandleError])
104
-
105
- // Update widget listeners (if they change)
106
- useEffect(() => {
107
- if (!widgetHandlerRef.current || listenersRef.current === listeners) return
108
-
109
- const handler = widgetHandlerRef.current
110
- tryOrHandleError('Updating the listeners', () => handler.updateListeners(listeners))
111
- }, [listeners, tryOrHandleError])
112
-
113
- // Handle errors
114
- if (error) {
115
- return (
116
- <div style={{ color: '#ff3a3a' }}>
117
- {error.message}
118
- {error.error.message && <pre style={{ whiteSpace: 'pre-wrap', fontSize: '0.75em' }}>{error.error.message}</pre>}
119
- </div>
120
- )
121
- }
122
-
123
- // Render widget container
124
- return <div ref={containerRef} style={{ width: '100%' }}></div>
125
- }
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "jsx": "react-jsx",
5
- "allowJs": false,
6
- "esModuleInterop": false,
7
- "allowSyntheticDefaultImports": true,
8
- "strict": true,
9
- "types": ["vite/client"]
10
- },
11
- "files": [],
12
- "include": [],
13
- "references": [
14
- {
15
- "path": "./tsconfig.lib.json"
16
- },
17
- {
18
- "path": "./tsconfig.spec.json"
19
- }
20
- ]
21
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts", "src/**/*.tsx"],
9
- "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx"]
10
- }
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "src/**/*.test.ts",
11
- "src/**/*.spec.ts",
12
- "src/**/*.test.tsx",
13
- "src/**/*.spec.tsx",
14
- "src/**/*.test.js",
15
- "src/**/*.spec.js",
16
- "src/**/*.test.jsx",
17
- "src/**/*.spec.jsx",
18
- "src/**/*.d.ts"
19
- ]
20
- }