@gardenfi/orderbook 2.1.6-beta.2 → 2.1.6-beta.4
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/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index6.cjs"),h=require("@gardenfi/utils"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index6.cjs"),h=require("@gardenfi/utils"),a=require("./index7.cjs");class O{constructor(s){this.Url=s}async createOrder(s,o){const e=await o.getAuthHeaders();if(e.error)return r.Err(e.error);try{const t=await r.Fetcher.post(this.Url.endpoint("/relayer").endpoint("create-order"),{body:JSON.stringify(s),headers:{...e.val,"Content-Type":"application/json"}});return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("CreateOrder: Unexpected error, result is undefined")}catch(t){return r.Err("CreateOrder:",String(t))}}async getOrder(s,o){const e=o?`/id/${s}/matched`:`/id/${s}/unmatched`,t=this.Url.endpoint("orders").endpoint(e);try{const n=await r.Fetcher.get(t);return n.error?r.Err(n.error):n.result?r.Ok(n.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(n){return r.Err("GetOrder:",String(n))}}async getMatchedOrders(s,o,e){const t=a.ConstructUrl(this.Url.endpoint("orders"),`/user/${s}/matched`,{...e,status:o});try{const n=await r.Fetcher.get(t);return n.error?r.Err(n.error):n.result?r.Ok(n.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(n){return r.Err("GetMatchedOrders:",String(n))}}async getUnMatchedOrders(s,o){const e=a.ConstructUrl(this.Url.endpoint("orders"),`/user/${s}/unmatched`,o);try{const t=await r.Fetcher.get(e);return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(t){return r.Err("GetUnMatchedOrders:",String(t))}}async getOrders(s,o,e,t){const n=s?"/matched":"/unmatched",d={};o&&(d.paginationConfig=o),e&&(d.address=e),t&&(d.tx_hash=t);const i=a.ConstructUrl(this.Url.endpoint("orders"),n,d);try{const c=await r.Fetcher.get(i);return c.error?r.Err(c.error):c.result?r.Ok(c.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(c){return r.Err("GetAllOrders:",String(c))}}async subscribeOrders(s,o,e,t,n="all",d){let i=!1;const c=async()=>{if(!i){i=!0;try{const u=o?await this.getMatchedOrders(s,n,d):await this.getUnMatchedOrders(s,d);u.ok?await t(u.val):console.error("Error fetching orders:",u.error)}catch(u){console.error("Error fetching orders:",u)}finally{i=!1}}};await c();const l=setInterval(c,e);return()=>{clearInterval(l)}}async getOrdersCount(s){const o=this.Url.endpoint("orders").endpoint(`/user/${s}/count`);try{const e=await r.Fetcher.get(o);return e.error?r.Err(e.error):e.status===h.ApiStatus.Ok&&e.result!==void 0?r.Ok(e.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrdersCount:",String(e))}}}exports.Orderbook=O;
|
package/dist/index2.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Err as
|
|
2
|
-
import { ApiStatus as
|
|
3
|
-
import { ConstructUrl as
|
|
1
|
+
import { Err as t, Fetcher as c, Ok as i } from "./index6.js";
|
|
2
|
+
import { ApiStatus as O } from "@gardenfi/utils";
|
|
3
|
+
import { ConstructUrl as h } from "./index7.js";
|
|
4
4
|
class m {
|
|
5
|
-
constructor(
|
|
6
|
-
this.Url =
|
|
5
|
+
constructor(s) {
|
|
6
|
+
this.Url = s;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Creates an order
|
|
@@ -11,110 +11,108 @@ class m {
|
|
|
11
11
|
* @param {IAuth} auth - The auth object.
|
|
12
12
|
* @returns {string} The create order ID.
|
|
13
13
|
*/
|
|
14
|
-
async createOrder(
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
14
|
+
async createOrder(s, o) {
|
|
15
|
+
const r = await o.getAuthHeaders();
|
|
16
|
+
if (r.error) return t(r.error);
|
|
17
17
|
try {
|
|
18
|
-
const
|
|
18
|
+
const e = await c.post(
|
|
19
19
|
this.Url.endpoint("/relayer").endpoint("create-order"),
|
|
20
20
|
{
|
|
21
|
-
body: JSON.stringify(
|
|
21
|
+
body: JSON.stringify(s),
|
|
22
22
|
headers: {
|
|
23
|
-
...
|
|
23
|
+
...r.val,
|
|
24
24
|
"Content-Type": "application/json"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
|
-
return
|
|
29
|
-
} catch (
|
|
30
|
-
return
|
|
28
|
+
return e.error ? t(e.error) : e.result ? i(e.result) : t("CreateOrder: Unexpected error, result is undefined");
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return t("CreateOrder:", String(e));
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
async getOrder(
|
|
34
|
-
const
|
|
33
|
+
async getOrder(s, o) {
|
|
34
|
+
const r = o ? `/id/${s}/matched` : `/id/${s}/unmatched`, e = this.Url.endpoint("orders").endpoint(r);
|
|
35
35
|
try {
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
} catch (
|
|
39
|
-
return
|
|
36
|
+
const n = await c.get(e);
|
|
37
|
+
return n.error ? t(n.error) : n.result ? i(n.result) : t("GetOrder: Unexpected error, result is undefined");
|
|
38
|
+
} catch (n) {
|
|
39
|
+
return t("GetOrder:", String(n));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
async getMatchedOrders(
|
|
43
|
-
const
|
|
42
|
+
async getMatchedOrders(s, o, r) {
|
|
43
|
+
const e = h(
|
|
44
44
|
this.Url.endpoint("orders"),
|
|
45
|
-
`/user/${
|
|
45
|
+
`/user/${s}/matched`,
|
|
46
46
|
{
|
|
47
|
-
...
|
|
47
|
+
...r,
|
|
48
48
|
status: o
|
|
49
49
|
}
|
|
50
50
|
);
|
|
51
51
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
52
|
+
const n = await c.get(
|
|
53
|
+
e
|
|
54
54
|
);
|
|
55
|
-
return
|
|
56
|
-
} catch (
|
|
57
|
-
return
|
|
55
|
+
return n.error ? t(n.error) : n.result ? i(n.result) : t("GetMatchedOrders: Unexpected error, result is undefined");
|
|
56
|
+
} catch (n) {
|
|
57
|
+
return t("GetMatchedOrders:", String(n));
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
async getUnMatchedOrders(
|
|
61
|
-
const
|
|
60
|
+
async getUnMatchedOrders(s, o) {
|
|
61
|
+
const r = h(
|
|
62
62
|
this.Url.endpoint("orders"),
|
|
63
|
-
`/user/${
|
|
63
|
+
`/user/${s}/unmatched`,
|
|
64
64
|
o
|
|
65
65
|
);
|
|
66
66
|
try {
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const e = await c.get(
|
|
68
|
+
r
|
|
69
69
|
);
|
|
70
|
-
return
|
|
71
|
-
} catch (
|
|
72
|
-
return
|
|
70
|
+
return e.error ? t(e.error) : e.result ? i(e.result) : t("GetUnMatchedOrders: Unexpected error, result is undefined");
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return t("GetUnMatchedOrders:", String(e));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
async getOrders(
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
o
|
|
80
|
-
);
|
|
75
|
+
async getOrders(s, o, r, e) {
|
|
76
|
+
const n = s ? "/matched" : "/unmatched", a = {};
|
|
77
|
+
o && (a.paginationConfig = o), r && (a.address = r), e && (a.tx_hash = e);
|
|
78
|
+
const u = h(this.Url.endpoint("orders"), n, a);
|
|
81
79
|
try {
|
|
82
|
-
const
|
|
83
|
-
return
|
|
84
|
-
} catch (
|
|
85
|
-
return
|
|
80
|
+
const d = await c.get(u);
|
|
81
|
+
return d.error ? t(d.error) : d.result ? i(d.result) : t("GetAllOrders: Unexpected error, result is undefined");
|
|
82
|
+
} catch (d) {
|
|
83
|
+
return t("GetAllOrders:", String(d));
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
|
-
async subscribeOrders(
|
|
89
|
-
let
|
|
90
|
-
const
|
|
91
|
-
if (!
|
|
92
|
-
|
|
86
|
+
async subscribeOrders(s, o, r, e, n = "all", a) {
|
|
87
|
+
let u = !1;
|
|
88
|
+
const d = async () => {
|
|
89
|
+
if (!u) {
|
|
90
|
+
u = !0;
|
|
93
91
|
try {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
) : console.error("Error fetching orders:",
|
|
98
|
-
} catch (
|
|
99
|
-
console.error("Error fetching orders:",
|
|
92
|
+
const l = o ? await this.getMatchedOrders(s, n, a) : await this.getUnMatchedOrders(s, a);
|
|
93
|
+
l.ok ? await e(
|
|
94
|
+
l.val
|
|
95
|
+
) : console.error("Error fetching orders:", l.error);
|
|
96
|
+
} catch (l) {
|
|
97
|
+
console.error("Error fetching orders:", l);
|
|
100
98
|
} finally {
|
|
101
|
-
|
|
99
|
+
u = !1;
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
};
|
|
105
|
-
await
|
|
106
|
-
const
|
|
103
|
+
await d();
|
|
104
|
+
const f = setInterval(d, r);
|
|
107
105
|
return () => {
|
|
108
|
-
clearInterval(
|
|
106
|
+
clearInterval(f);
|
|
109
107
|
};
|
|
110
108
|
}
|
|
111
|
-
async getOrdersCount(
|
|
112
|
-
const o = this.Url.endpoint("orders").endpoint(`/user/${
|
|
109
|
+
async getOrdersCount(s) {
|
|
110
|
+
const o = this.Url.endpoint("orders").endpoint(`/user/${s}/count`);
|
|
113
111
|
try {
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
} catch (
|
|
117
|
-
return
|
|
112
|
+
const r = await c.get(o);
|
|
113
|
+
return r.error ? t(r.error) : r.status === O.Ok && r.result !== void 0 ? i(r.result) : t("GetOrdersCount: Unexpected error, result is undefined");
|
|
114
|
+
} catch (r) {
|
|
115
|
+
return t("GetOrdersCount:", String(r));
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
}
|
|
@@ -20,7 +20,7 @@ export declare class Orderbook implements IOrderbook {
|
|
|
20
20
|
getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
|
|
21
21
|
getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
|
|
22
22
|
getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<CreateOrder>, string>;
|
|
23
|
-
getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
23
|
+
getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig, address?: string, tx_hash?: string): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
24
24
|
subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig): Promise<() => void>;
|
|
25
25
|
getOrdersCount(address: string): AsyncResult<number, string>;
|
|
26
26
|
}
|
|
@@ -116,9 +116,11 @@ export interface IOrderbook {
|
|
|
116
116
|
* Get all orders from the orderbook based on the match status.
|
|
117
117
|
* @param matched - If true, returns matched orders, else returns unmatched orders.
|
|
118
118
|
* @param paginationConfig - The configuration for the pagination.
|
|
119
|
+
* @param address - The address to get the orders for.
|
|
120
|
+
* @param tx_hash - The tx hash to get the orders for (initiate_tx_hash, redeem_tx_hash, refund_tx_hash).
|
|
119
121
|
* @returns {AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>} A promise that resolves to the orders.
|
|
120
122
|
*/
|
|
121
|
-
getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
123
|
+
getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig, address?: string, tx_hash?: string): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
122
124
|
/**
|
|
123
125
|
* Polls for every provided interval and returns matched and unmatched orders associated on the account.
|
|
124
126
|
* @param account The account to subscribe to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/orderbook",
|
|
3
|
-
"version": "2.1.6-beta.
|
|
3
|
+
"version": "2.1.6-beta.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@gardenfi/utils": "2.1.3
|
|
29
|
+
"@gardenfi/utils": "2.1.3",
|
|
30
30
|
"bufferutil": "^4.0.8",
|
|
31
31
|
"siwe": "^2.1.4",
|
|
32
32
|
"utf-8-validate": "^6.0.3",
|