@cowprotocol/widget-lib 0.1.1 → 0.1.3
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/JsonRpcManager.d.ts +25 -4
- package/README.md +11 -13
- package/cowSwapWidget.d.ts +12 -3
- package/index.iife.js +1 -0
- package/index.js +1 -1
- package/index.mjs +76 -58
- package/package.json +1 -1
- package/types.d.ts +97 -25
- package/urlUtils.d.ts +4 -4
package/JsonRpcManager.d.ts
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { EthereumProvider, JsonRpcRequest } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Manages JSON-RPC requests and interactions with an Ethereum provider.
|
|
4
|
+
*/
|
|
2
5
|
export declare class JsonRpcManager {
|
|
3
6
|
private contentWindow;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The Ethereum provider instance.
|
|
9
|
+
* When is null the JSON-RPC manager is disconnected from the Ethereum provider.
|
|
10
|
+
* */
|
|
11
|
+
private ethereumProvider;
|
|
12
|
+
/** Stored JSON-RPC requests. */
|
|
13
|
+
private requests;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of JsonRpcManager.
|
|
16
|
+
* @param contentWindow - The window for handling events.
|
|
17
|
+
*/
|
|
8
18
|
constructor(contentWindow: Window);
|
|
19
|
+
/**
|
|
20
|
+
* Disconnects the JSON-RPC manager from the Ethereum provider.
|
|
21
|
+
*/
|
|
9
22
|
disconnect(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
25
|
+
* @param ethereumProvider - The Ethereum provider to connect.
|
|
26
|
+
*/
|
|
10
27
|
onConnect(ethereumProvider: EthereumProvider): void;
|
|
28
|
+
/**
|
|
29
|
+
* Processes a JSON-RPC request and sends appropriate response or error via the content window.
|
|
30
|
+
* @param request - The JSON-RPC request to be processed.
|
|
31
|
+
*/
|
|
11
32
|
processRequest(request: JsonRpcRequest): void;
|
|
12
33
|
private processEvent;
|
|
13
34
|
private postMessage;
|
package/README.md
CHANGED
|
@@ -31,29 +31,27 @@ Create a container somewhere in your website, the widget will be rendered inside
|
|
|
31
31
|
Import the widget and initialise it:
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
|
-
import { cowSwapWidget } from '@cowprotocol/widget-lib'
|
|
34
|
+
import { cowSwapWidget, CowSwapWidgetParams } from '@cowprotocol/widget-lib'
|
|
35
35
|
|
|
36
36
|
// Initialise the widget
|
|
37
37
|
const widgetContainer = document.getElementById('cowswap-widget')
|
|
38
38
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
width: 600,
|
|
42
|
-
height: 640,
|
|
43
|
-
metaData: {
|
|
44
|
-
appKey: '<YOUR_APP_KEY>', // Just an unique identifier for your app,
|
|
45
|
-
appUrl: '<YOUR_APP_URL>'
|
|
46
|
-
},
|
|
47
|
-
// Optionally, you can provide some additional params to customise your widget
|
|
48
|
-
}, {
|
|
39
|
+
const params: CowSwapWidgetParams = {
|
|
40
|
+
appKey: '<YOUR_APP_KEY>', // Just an unique identifier for your app
|
|
49
41
|
sell: { asset: 'DAI' },
|
|
50
42
|
buy: { asset: 'USDC', amount: '0.1' },
|
|
51
43
|
// instantiate your own web3 provider
|
|
52
44
|
provider: window.ethereum
|
|
53
|
-
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const updateWidget = cowSwapWidget(
|
|
48
|
+
widgetContainer,
|
|
49
|
+
// Optionally, you can provide some additional params to customise your widget
|
|
50
|
+
params
|
|
51
|
+
)
|
|
54
52
|
|
|
55
53
|
// You also can change widget configuration on the fly
|
|
56
|
-
updateWidget({ tradeType: 'limit' })
|
|
54
|
+
updateWidget({ ...params, tradeType: 'limit' })
|
|
57
55
|
```
|
|
58
56
|
|
|
59
57
|
## Developers
|
package/cowSwapWidget.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import { CowSwapWidgetParams
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CowSwapWidgetParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Callback function signature for updating the CoW Swap Widget.
|
|
4
|
+
*/
|
|
5
|
+
export type UpdateWidgetCallback = (params: CowSwapWidgetParams) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Generates and injects a CoW Swap Widget into the provided container.
|
|
8
|
+
* @param container - The HTML element to inject the widget into.
|
|
9
|
+
* @param params - Parameters for configuring the widget.
|
|
10
|
+
* @returns A callback function to update the widget with new settings.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cowSwapWidget(container: HTMLElement, params?: CowSwapWidgetParams): UpdateWidgetCallback;
|
package/index.iife.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var cowSwapWidget=function(i){"use strict";const l="2.0",m="*",w=["connect","disconnect","close","chainChanged","accountsChanged"];class f{constructor(t){this.contentWindow=t,this.ethereumProvider=null,this.requests={},this.processEvent=e=>{e.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(e.data):this.requests[e.data.id]=e.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(t){this.ethereumProvider=t,Object.keys(this.requests).forEach(e=>{this.processRequest(this.requests[e])}),this.requests={},w.forEach(e=>{t.on(e,n=>{this.postMessage({method:e,params:[n]})})})}processRequest(t){if(!this.ethereumProvider)return;(t.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(t)).then(n=>{this.postMessage({id:t.id,result:n})}).catch(n=>{this.postMessage({id:t.id,error:n})})}postMessage(t){this.contentWindow.postMessage({jsonrpc:l,...t},m)}}function E(){return`https://swap-dev-git-${location.hostname.replace("widget-configurator-git-","").replace("-cowswap.vercel.app","")}-cowswap.vercel.app`}const d={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:E()};var c=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(c||{});function v(s){const t=d[s.env||"prod"],e=h(s),n=u(s);return t+"/#"+e+"?"+n}function h(s){const{chainId:t=1,tradeAssets:e,tradeType:n=c.SWAP}=s,o=e?[e.sell.asset,e.buy.asset].map(encodeURIComponent).join("/"):"";return`/${t}/widget/${n}/${o}`}function u(s){const{tradeAssets:t,theme:e}=s,n=new URLSearchParams;if(t){const{sell:o,buy:a}=t;o.amount&&n.append("sellAmount",o.amount),a.amount&&n.append("buyAmount",a.amount)}return e&&n.append("theme",e),n}const r="cowSwapWidget",p="640px",y="450px";function W(s,t={}){const{provider:e}=t,n=P(t);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return S(o,t.appKey),A(n,t.height),e&&new f(o).onConnect(e),n.addEventListener("load",()=>{g(t,o)}),a=>g(a,o)}function P(s){const{width:t=y,height:e=p}=s,n=document.createElement("iframe");return n.src=v(s),n.width=t,n.height=e,n.style.border="0",n}function g(s,t){const e=h(s),n=u(s).toString();t.postMessage({key:r,method:"update",urlParams:{pathname:e,search:n},appParams:{...s,provider:void 0}},"*")}function S(s,t){window.addEventListener("message",e=>{e.data.key!==r||e.data.method!=="activate"||s.postMessage({key:r,method:"metaData",metaData:t?{appKey:t}:void 0},"*")})}function A(s,t=p){window.addEventListener("message",e=>{e.data.key!==r||e.data.method!=="iframeHeight"||(s.style.height=e.data.height?`${e.data.height}px`:t)})}return i.COWSWAP_URLS=d,i.TradeType=c,i.cowSwapWidget=W,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i}({});
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="2.0",l="*",m=["connect","disconnect","close","chainChanged","accountsChanged"];class w{constructor(t){this.contentWindow=t,this.ethereumProvider=null,this.requests={},this.processEvent=e=>{e.data.jsonrpc==="2.0"&&(this.ethereumProvider?this.processRequest(e.data):this.requests[e.data.id]=e.data)},window.addEventListener("message",this.processEvent)}disconnect(){this.ethereumProvider=null,window.removeEventListener("message",this.processEvent)}onConnect(t){this.ethereumProvider=t,Object.keys(this.requests).forEach(e=>{this.processRequest(this.requests[e])}),this.requests={},m.forEach(e=>{t.on(e,n=>{this.postMessage({method:e,params:[n]})})})}processRequest(t){if(!this.ethereumProvider)return;(t.method==="enable"?this.ethereumProvider.enable():this.ethereumProvider.request(t)).then(n=>{this.postMessage({id:t.id,result:n})}).catch(n=>{this.postMessage({id:t.id,error:n})})}postMessage(t){this.contentWindow.postMessage({jsonrpc:g,...t},l)}}function f(){return`https://swap-dev-git-${location.hostname.replace("widget-configurator-git-","").replace("-cowswap.vercel.app","")}-cowswap.vercel.app`}const d={local:"http://localhost:3000",prod:"https://swap.cow.fi",dev:"https://dev.swap.cow.fi",pr:f()};var r=(s=>(s.SWAP="swap",s.LIMIT="limit",s.ADVANCED="advanced",s))(r||{});function E(s){const t=d[s.env||"prod"],e=h(s),n=u(s);return t+"/#"+e+"?"+n}function h(s){const{chainId:t=1,tradeAssets:e,tradeType:n=r.SWAP}=s,o=e?[e.sell.asset,e.buy.asset].map(encodeURIComponent).join("/"):"";return`/${t}/widget/${n}/${o}`}function u(s){const{tradeAssets:t,theme:e}=s,n=new URLSearchParams;if(t){const{sell:o,buy:i}=t;o.amount&&n.append("sellAmount",o.amount),i.amount&&n.append("buyAmount",i.amount)}return e&&n.append("theme",e),n}const a="cowSwapWidget",p="640px",v="450px";function y(s,t={}){const{provider:e}=t,n=P(t);s.innerHTML="",s.appendChild(n);const{contentWindow:o}=n;if(!o)throw new Error("Iframe does not contain a window!");return W(o,t.appKey),A(n,t.height),e&&new w(o).onConnect(e),n.addEventListener("load",()=>{c(t,o)}),i=>c(i,o)}function P(s){const{width:t=v,height:e=p}=s,n=document.createElement("iframe");return n.src=E(s),n.width=t,n.height=e,n.style.border="0",n}function c(s,t){const e=h(s),n=u(s).toString();t.postMessage({key:a,method:"update",urlParams:{pathname:e,search:n},appParams:{...s,provider:void 0}},"*")}function W(s,t){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="activate"||s.postMessage({key:a,method:"metaData",metaData:t?{appKey:t}:void 0},"*")})}function A(s,t=p){window.addEventListener("message",e=>{e.data.key!==a||e.data.method!=="iframeHeight"||(s.style.height=e.data.height?`${e.data.height}px`:t)})}exports.COWSWAP_URLS=d;exports.TradeType=r;exports.cowSwapWidget=y;
|
package/index.mjs
CHANGED
|
@@ -1,116 +1,134 @@
|
|
|
1
|
-
const
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const u = "2.0", m = "*", g = ["connect", "disconnect", "close", "chainChanged", "accountsChanged"];
|
|
2
|
+
class l {
|
|
3
|
+
/**
|
|
4
|
+
* Creates an instance of JsonRpcManager.
|
|
5
|
+
* @param contentWindow - The window for handling events.
|
|
6
|
+
*/
|
|
7
|
+
constructor(t) {
|
|
8
|
+
this.contentWindow = t, this.ethereumProvider = null, this.requests = {}, this.processEvent = (e) => {
|
|
5
9
|
e.data.jsonrpc === "2.0" && (this.ethereumProvider ? this.processRequest(e.data) : this.requests[e.data.id] = e.data);
|
|
6
10
|
}, window.addEventListener("message", this.processEvent);
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Disconnects the JSON-RPC manager from the Ethereum provider.
|
|
14
|
+
*/
|
|
8
15
|
disconnect() {
|
|
9
16
|
this.ethereumProvider = null, window.removeEventListener("message", this.processEvent);
|
|
10
17
|
}
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Handles the 'connect' event and sets up event listeners for Ethereum provider events.
|
|
20
|
+
* @param ethereumProvider - The Ethereum provider to connect.
|
|
21
|
+
*/
|
|
22
|
+
onConnect(t) {
|
|
23
|
+
this.ethereumProvider = t, Object.keys(this.requests).forEach((e) => {
|
|
13
24
|
this.processRequest(this.requests[e]);
|
|
14
|
-
}), this.requests = {},
|
|
15
|
-
|
|
25
|
+
}), this.requests = {}, g.forEach((e) => {
|
|
26
|
+
t.on(e, (n) => {
|
|
16
27
|
this.postMessage({ method: e, params: [n] });
|
|
17
28
|
});
|
|
18
29
|
});
|
|
19
30
|
}
|
|
20
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Processes a JSON-RPC request and sends appropriate response or error via the content window.
|
|
33
|
+
* @param request - The JSON-RPC request to be processed.
|
|
34
|
+
*/
|
|
35
|
+
processRequest(t) {
|
|
21
36
|
if (!this.ethereumProvider)
|
|
22
37
|
return;
|
|
23
|
-
(
|
|
24
|
-
this.postMessage({ id:
|
|
38
|
+
(t.method === "enable" ? this.ethereumProvider.enable() : this.ethereumProvider.request(t)).then((n) => {
|
|
39
|
+
this.postMessage({ id: t.id, result: n });
|
|
25
40
|
}).catch((n) => {
|
|
26
|
-
this.postMessage({ id:
|
|
41
|
+
this.postMessage({ id: t.id, error: n });
|
|
27
42
|
});
|
|
28
43
|
}
|
|
29
|
-
postMessage(
|
|
44
|
+
postMessage(t) {
|
|
30
45
|
this.contentWindow.postMessage(
|
|
31
46
|
{
|
|
32
|
-
jsonrpc:
|
|
33
|
-
...
|
|
47
|
+
jsonrpc: u,
|
|
48
|
+
...t
|
|
34
49
|
},
|
|
35
50
|
m
|
|
36
51
|
);
|
|
37
52
|
}
|
|
38
53
|
}
|
|
54
|
+
function w() {
|
|
55
|
+
return `https://swap-dev-git-${location.hostname.replace("widget-configurator-git-", "").replace("-cowswap.vercel.app", "")}-cowswap.vercel.app`;
|
|
56
|
+
}
|
|
39
57
|
const f = {
|
|
40
58
|
local: "http://localhost:3000",
|
|
41
59
|
prod: "https://swap.cow.fi",
|
|
42
60
|
dev: "https://dev.swap.cow.fi",
|
|
43
|
-
pr:
|
|
61
|
+
pr: w()
|
|
44
62
|
};
|
|
45
|
-
var
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
return
|
|
63
|
+
var c = /* @__PURE__ */ ((s) => (s.SWAP = "swap", s.LIMIT = "limit", s.ADVANCED = "advanced", s))(c || {});
|
|
64
|
+
function E(s) {
|
|
65
|
+
const t = f[s.env || "prod"], e = d(s), n = h(s);
|
|
66
|
+
return t + "/#" + e + "?" + n;
|
|
49
67
|
}
|
|
50
|
-
function
|
|
51
|
-
const { chainId:
|
|
52
|
-
return `/${
|
|
68
|
+
function d(s) {
|
|
69
|
+
const { chainId: t = 1, tradeAssets: e, tradeType: n = c.SWAP } = s, o = e ? [e.sell.asset, e.buy.asset].map(encodeURIComponent).join("/") : "";
|
|
70
|
+
return `/${t}/widget/${n}/${o}`;
|
|
53
71
|
}
|
|
54
|
-
function
|
|
55
|
-
const { tradeAssets:
|
|
56
|
-
if (
|
|
57
|
-
const { sell: o, buy:
|
|
58
|
-
o.amount && n.append("sellAmount", o.amount),
|
|
72
|
+
function h(s) {
|
|
73
|
+
const { tradeAssets: t, theme: e } = s, n = new URLSearchParams();
|
|
74
|
+
if (t) {
|
|
75
|
+
const { sell: o, buy: i } = t;
|
|
76
|
+
o.amount && n.append("sellAmount", o.amount), i.amount && n.append("buyAmount", i.amount);
|
|
59
77
|
}
|
|
60
78
|
return e && n.append("theme", e), n;
|
|
61
79
|
}
|
|
62
|
-
const
|
|
63
|
-
function
|
|
64
|
-
const {
|
|
65
|
-
|
|
66
|
-
const { contentWindow:
|
|
67
|
-
if (!
|
|
80
|
+
const a = "cowSwapWidget", p = "640px", v = "450px";
|
|
81
|
+
function A(s, t = {}) {
|
|
82
|
+
const { provider: e } = t, n = y(t);
|
|
83
|
+
s.innerHTML = "", s.appendChild(n);
|
|
84
|
+
const { contentWindow: o } = n;
|
|
85
|
+
if (!o)
|
|
68
86
|
throw new Error("Iframe does not contain a window!");
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
}), (
|
|
87
|
+
return P(o, t.appKey), W(n, t.height), e && new l(o).onConnect(e), n.addEventListener("load", () => {
|
|
88
|
+
r(t, o);
|
|
89
|
+
}), (i) => r(i, o);
|
|
72
90
|
}
|
|
73
|
-
function
|
|
74
|
-
const { width:
|
|
75
|
-
return
|
|
91
|
+
function y(s) {
|
|
92
|
+
const { width: t = v, height: e = p } = s, n = document.createElement("iframe");
|
|
93
|
+
return n.src = E(s), n.width = t, n.height = e, n.style.border = "0", n;
|
|
76
94
|
}
|
|
77
|
-
function
|
|
78
|
-
const
|
|
79
|
-
t.
|
|
95
|
+
function r(s, t) {
|
|
96
|
+
const e = d(s), n = h(s).toString();
|
|
97
|
+
t.postMessage(
|
|
80
98
|
{
|
|
81
|
-
key:
|
|
99
|
+
key: a,
|
|
82
100
|
method: "update",
|
|
83
101
|
urlParams: {
|
|
84
|
-
pathname:
|
|
85
|
-
search:
|
|
102
|
+
pathname: e,
|
|
103
|
+
search: n
|
|
86
104
|
},
|
|
87
|
-
appParams:
|
|
105
|
+
appParams: {
|
|
106
|
+
...s,
|
|
107
|
+
provider: void 0
|
|
108
|
+
}
|
|
88
109
|
},
|
|
89
110
|
"*"
|
|
90
111
|
);
|
|
91
112
|
}
|
|
92
|
-
function
|
|
113
|
+
function P(s, t) {
|
|
93
114
|
window.addEventListener("message", (e) => {
|
|
94
|
-
e.data.key !==
|
|
115
|
+
e.data.key !== a || e.data.method !== "activate" || s.postMessage(
|
|
95
116
|
{
|
|
96
|
-
key:
|
|
117
|
+
key: a,
|
|
97
118
|
method: "metaData",
|
|
98
|
-
metaData:
|
|
119
|
+
metaData: t ? { appKey: t } : void 0
|
|
99
120
|
},
|
|
100
121
|
"*"
|
|
101
122
|
);
|
|
102
123
|
});
|
|
103
124
|
}
|
|
104
|
-
function
|
|
125
|
+
function W(s, t = p) {
|
|
105
126
|
window.addEventListener("message", (e) => {
|
|
106
|
-
|
|
107
|
-
return;
|
|
108
|
-
const n = e.data.height || s;
|
|
109
|
-
t.style.height = `${n}px`;
|
|
127
|
+
e.data.key !== a || e.data.method !== "iframeHeight" || (s.style.height = e.data.height ? `${e.data.height}px` : t);
|
|
110
128
|
});
|
|
111
129
|
}
|
|
112
130
|
export {
|
|
113
131
|
f as COWSWAP_URLS,
|
|
114
|
-
|
|
115
|
-
|
|
132
|
+
c as TradeType,
|
|
133
|
+
A as cowSwapWidget
|
|
116
134
|
};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,19 +1,48 @@
|
|
|
1
|
+
import type { SupportedChainId } from '@cowprotocol/cow-sdk';
|
|
1
2
|
export interface JsonRpcRequest {
|
|
2
3
|
id: number;
|
|
3
4
|
method: string;
|
|
4
5
|
params: unknown[];
|
|
5
6
|
}
|
|
6
7
|
export interface EthereumProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Subscribes to Ethereum-related events.
|
|
10
|
+
* @param event - The event to subscribe to.
|
|
11
|
+
* @param args - Arguments for the event.
|
|
12
|
+
*/
|
|
7
13
|
on(event: string, args: unknown): void;
|
|
14
|
+
/**
|
|
15
|
+
* Sends a JSON-RPC request to the Ethereum provider and returns the response.
|
|
16
|
+
* @param params - JSON-RPC request parameters.
|
|
17
|
+
* @returns A promise that resolves with the response.
|
|
18
|
+
*/
|
|
8
19
|
request<T>(params: JsonRpcRequest): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Requests permission to connect to the Ethereum provider.
|
|
22
|
+
* @returns A promise that resolves once permission is granted.
|
|
23
|
+
*/
|
|
9
24
|
enable(): Promise<void>;
|
|
10
25
|
}
|
|
11
26
|
export type CowSwapWidgetEnv = 'local' | 'prod' | 'dev' | 'pr';
|
|
12
27
|
export type CowSwapTheme = 'dark' | 'light';
|
|
28
|
+
/**
|
|
29
|
+
*Trade asset parameters, for example:
|
|
30
|
+
* { asset: 'WBTC', amount: 12 }
|
|
31
|
+
* or
|
|
32
|
+
* { asset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' } // USDC
|
|
33
|
+
*/
|
|
13
34
|
interface TradeAsset {
|
|
35
|
+
/** The asset symbol or identifier. */
|
|
14
36
|
asset: string;
|
|
37
|
+
/**
|
|
38
|
+
* The amount of the asset (optional).
|
|
39
|
+
* If specified, represents the quantity or value of the asset.
|
|
40
|
+
*/
|
|
15
41
|
amount?: string;
|
|
16
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* A pair of assets to trade.
|
|
45
|
+
*/
|
|
17
46
|
export interface TradeAssets {
|
|
18
47
|
sell: TradeAsset;
|
|
19
48
|
buy: TradeAsset;
|
|
@@ -21,39 +50,82 @@ export interface TradeAssets {
|
|
|
21
50
|
export declare enum TradeType {
|
|
22
51
|
SWAP = "swap",
|
|
23
52
|
LIMIT = "limit",
|
|
53
|
+
/**
|
|
54
|
+
* Currently it means only TWAP orders.
|
|
55
|
+
* But in the future it can be extended to support other order types.
|
|
56
|
+
*/
|
|
24
57
|
ADVANCED = "advanced"
|
|
25
58
|
}
|
|
26
|
-
export interface CowSwapWidgetUrlParams {
|
|
27
|
-
chainId?: number;
|
|
28
|
-
tradeType?: TradeType;
|
|
29
|
-
env?: CowSwapWidgetEnv;
|
|
30
|
-
tradeAssets?: TradeAssets;
|
|
31
|
-
theme?: CowSwapTheme;
|
|
32
|
-
}
|
|
33
59
|
export interface CowSwapWidgetPalette {
|
|
34
60
|
primaryColor: string;
|
|
35
61
|
screenBackground: string;
|
|
36
62
|
widgetBackground: string;
|
|
37
63
|
textColor: string;
|
|
38
64
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
interface CowSwapWidgetConfig {
|
|
66
|
+
/**
|
|
67
|
+
* The width of the widget in pixels. Default: 400px
|
|
68
|
+
*/
|
|
69
|
+
width: string;
|
|
70
|
+
/**
|
|
71
|
+
* The height of the widget in pixels. Default: 600px
|
|
72
|
+
*/
|
|
73
|
+
height: string;
|
|
74
|
+
/**
|
|
75
|
+
* The unique identifier of the widget consumer.
|
|
76
|
+
* Please fill the for to let us know a little about you: <TODO-TYPEFORM>
|
|
77
|
+
*/
|
|
49
78
|
appKey: string;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
/**
|
|
80
|
+
* The widget might be connected to a custom Ethereum provider.
|
|
81
|
+
*/
|
|
82
|
+
provider: EthereumProvider;
|
|
83
|
+
/**
|
|
84
|
+
* Network ID.
|
|
85
|
+
*/
|
|
86
|
+
chainId: SupportedChainId;
|
|
87
|
+
/**
|
|
88
|
+
* Swap, Limit or Advanced (Twap).
|
|
89
|
+
*/
|
|
90
|
+
tradeType: TradeType;
|
|
91
|
+
/**
|
|
92
|
+
* The environment of the widget. Default: prod
|
|
93
|
+
*/
|
|
94
|
+
env: CowSwapWidgetEnv;
|
|
95
|
+
/**
|
|
96
|
+
* The assets to trade.
|
|
97
|
+
*/
|
|
98
|
+
tradeAssets: TradeAssets;
|
|
99
|
+
/**
|
|
100
|
+
* The theme of the widget UI.
|
|
101
|
+
*/
|
|
102
|
+
theme: CowSwapTheme;
|
|
103
|
+
/**
|
|
104
|
+
* Allows to set a custom logo for the widget.
|
|
105
|
+
*/
|
|
106
|
+
logoUrl: string;
|
|
107
|
+
/**
|
|
108
|
+
* Option to hide the logo in the widget.
|
|
109
|
+
*/
|
|
110
|
+
hideLogo: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Option to hide the network selector in the widget.
|
|
113
|
+
*/
|
|
114
|
+
hideNetworkSelector: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Enables the ability to switch between trade types in the widget.
|
|
117
|
+
*/
|
|
118
|
+
enabledTradeTypes: TradeType[];
|
|
119
|
+
/**
|
|
120
|
+
* Colors palette to customize the widget UI.
|
|
121
|
+
*/
|
|
122
|
+
palette: CowSwapWidgetPalette;
|
|
123
|
+
/**
|
|
124
|
+
* The partner fee in basis points.
|
|
125
|
+
* For example: 1.5% = 150 bips
|
|
126
|
+
* Please contact <TODO-TYPEFORM> to enable your partner fee.
|
|
127
|
+
*/
|
|
128
|
+
partnerFeeBips: string;
|
|
58
129
|
}
|
|
130
|
+
export type CowSwapWidgetParams = Partial<CowSwapWidgetConfig>;
|
|
59
131
|
export {};
|
package/urlUtils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function buildWidgetUrl(params:
|
|
3
|
-
export declare function buildWidgetPath(params:
|
|
4
|
-
export declare function buildTradeAmountsQuery(params:
|
|
1
|
+
import { CowSwapWidgetParams } from './types';
|
|
2
|
+
export declare function buildWidgetUrl(params: CowSwapWidgetParams): string;
|
|
3
|
+
export declare function buildWidgetPath(params: CowSwapWidgetParams): string;
|
|
4
|
+
export declare function buildTradeAmountsQuery(params: CowSwapWidgetParams): URLSearchParams;
|