@ecency/wallets 1.3.16 → 1.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -61,5 +61,12 @@ const { data: btcBalance } = useGetExternalWalletBalanceQuery(
|
|
|
61
61
|
EcencyWalletCurrency.BTC,
|
|
62
62
|
'1BitcoinAddress...'
|
|
63
63
|
);
|
|
64
|
+
|
|
65
|
+
// query with Chainstack priority before Bitquery and public APIs
|
|
66
|
+
const { data: btcBalanceChainstackFirst } = useGetExternalWalletBalanceQuery(
|
|
67
|
+
EcencyWalletCurrency.BTC,
|
|
68
|
+
'1BitcoinAddress...',
|
|
69
|
+
{ reverseProviderOrder: true }
|
|
70
|
+
);
|
|
64
71
|
```
|
|
65
72
|
|
package/dist/ecency-sdk.es.js
CHANGED
|
@@ -74,87 +74,92 @@ const A0 = {
|
|
|
74
74
|
scale: 1e8
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
function Op(i, c) {
|
|
77
|
+
function Op(i, c, b = {}) {
|
|
78
|
+
const { reverseProviderOrder: y = !1 } = b;
|
|
78
79
|
return Yt({
|
|
79
80
|
queryKey: ["ecency-wallets", "external-wallet-balance", i, c],
|
|
80
81
|
queryFn: async () => {
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
84
|
-
throw new Error(`Unsupported currency for ${
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
82
|
+
const s = async (p) => {
|
|
83
|
+
const f = A0[i];
|
|
84
|
+
if (!f)
|
|
85
|
+
throw new Error(`Unsupported currency for ${p}`);
|
|
86
|
+
const l = p === "bitquery" ? Ve.bitqueryApiUrl : Ve.chainstackApiUrl;
|
|
87
|
+
if (!l)
|
|
87
88
|
throw new Error(
|
|
88
|
-
|
|
89
|
+
p === "bitquery" ? "Bitquery API URL is not configured" : "Chainstack API URL is not configured"
|
|
89
90
|
);
|
|
90
|
-
const
|
|
91
|
+
const n = {
|
|
91
92
|
"Content-Type": "application/json"
|
|
92
93
|
};
|
|
93
|
-
|
|
94
|
-
const
|
|
94
|
+
p === "bitquery" ? n["X-API-KEY"] = Ve.bitqueryApiKey || "" : Ve.chainstackApiKey && (n["X-API-KEY"] = Ve.chainstackApiKey);
|
|
95
|
+
const r = await fetch(l, {
|
|
95
96
|
method: "POST",
|
|
96
|
-
headers:
|
|
97
|
-
body:
|
|
97
|
+
headers: n,
|
|
98
|
+
body: f.query(c)
|
|
98
99
|
});
|
|
99
|
-
if (!
|
|
100
|
+
if (!r.ok)
|
|
100
101
|
throw new Error(
|
|
101
|
-
|
|
102
|
+
p === "bitquery" ? "Bitquery request failed" : "Chainstack request failed"
|
|
102
103
|
);
|
|
103
|
-
const
|
|
104
|
-
if (typeof
|
|
104
|
+
const e = await r.json(), t = f.parse(e.data);
|
|
105
|
+
if (typeof t != "number")
|
|
105
106
|
throw new Error(
|
|
106
|
-
|
|
107
|
+
p === "bitquery" ? "Bitquery returned invalid balance" : "Chainstack returned invalid balance"
|
|
107
108
|
);
|
|
108
|
-
return
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
return t / f.scale;
|
|
110
|
+
}, a = async (p) => {
|
|
111
|
+
const f = y ? [
|
|
112
|
+
() => s("chainstack"),
|
|
113
|
+
() => s("bitquery"),
|
|
114
|
+
p
|
|
115
|
+
] : [
|
|
116
|
+
p,
|
|
117
|
+
() => s("bitquery"),
|
|
118
|
+
() => s("chainstack")
|
|
119
|
+
];
|
|
120
|
+
let l;
|
|
121
|
+
for (const n of f)
|
|
113
122
|
try {
|
|
114
|
-
return await
|
|
115
|
-
} catch (
|
|
116
|
-
|
|
117
|
-
return await b("chainstack");
|
|
118
|
-
} catch (f) {
|
|
119
|
-
throw f instanceof Error ? f : p instanceof Error ? p : a;
|
|
120
|
-
}
|
|
123
|
+
return await n();
|
|
124
|
+
} catch (r) {
|
|
125
|
+
l = r;
|
|
121
126
|
}
|
|
122
|
-
|
|
127
|
+
throw l instanceof Error ? l : new Error("Failed to fetch external wallet balance");
|
|
123
128
|
};
|
|
124
129
|
switch (i) {
|
|
125
130
|
case Oe.BTC:
|
|
126
|
-
return
|
|
127
|
-
const
|
|
131
|
+
return a(async () => {
|
|
132
|
+
const p = await fetch(
|
|
128
133
|
`https://mempool.space/api/address/${c}`
|
|
129
134
|
);
|
|
130
|
-
if (!
|
|
131
|
-
const
|
|
132
|
-
return (
|
|
135
|
+
if (!p.ok) throw new Error("Mempool API request failed");
|
|
136
|
+
const f = await p.json();
|
|
137
|
+
return (f.chain_stats.funded_txo_sum - f.chain_stats.spent_txo_sum) / 1e8;
|
|
133
138
|
});
|
|
134
139
|
case Oe.ETH:
|
|
135
|
-
return
|
|
136
|
-
const
|
|
140
|
+
return a(async () => {
|
|
141
|
+
const p = await fetch(
|
|
137
142
|
`https://api.ethplorer.io/getAddressInfo/${c}?apiKey=freekey`
|
|
138
143
|
);
|
|
139
|
-
if (!
|
|
144
|
+
if (!p.ok)
|
|
140
145
|
throw new Error("Ethplorer API request failed");
|
|
141
|
-
return +(await
|
|
146
|
+
return +(await p.json()).ETH.balance;
|
|
142
147
|
});
|
|
143
148
|
case Oe.BNB:
|
|
144
|
-
return
|
|
145
|
-
const
|
|
149
|
+
return a(async () => {
|
|
150
|
+
const p = await fetch(
|
|
146
151
|
`https://api.bscscan.com/api?module=account&action=balance&address=${c}&tag=latest&apikey=YourApiKeyToken`
|
|
147
152
|
);
|
|
148
|
-
if (!
|
|
153
|
+
if (!p.ok)
|
|
149
154
|
throw new Error("BscScan API request failed");
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
155
|
+
const f = await p.json();
|
|
156
|
+
if (f.status !== "1")
|
|
152
157
|
throw new Error("BscScan API returned an error");
|
|
153
|
-
return parseInt(
|
|
158
|
+
return parseInt(f.result, 10) / 1e18;
|
|
154
159
|
});
|
|
155
160
|
case Oe.SOL:
|
|
156
|
-
return
|
|
157
|
-
const
|
|
161
|
+
return a(async () => {
|
|
162
|
+
const p = await fetch(
|
|
158
163
|
`https://rpc.helius.xyz/?api-key=${Ve.heliusApiKey}`,
|
|
159
164
|
{
|
|
160
165
|
method: "POST",
|
|
@@ -169,36 +174,36 @@ function Op(i, c) {
|
|
|
169
174
|
}
|
|
170
175
|
}
|
|
171
176
|
);
|
|
172
|
-
if (!
|
|
173
|
-
return (await
|
|
177
|
+
if (!p.ok) throw new Error("Helius API request failed");
|
|
178
|
+
return (await p.json()).result.value / 1e9;
|
|
174
179
|
});
|
|
175
180
|
case Oe.TRON:
|
|
176
|
-
return
|
|
177
|
-
const
|
|
181
|
+
return a(async () => {
|
|
182
|
+
const p = await fetch(
|
|
178
183
|
`https://api.trongrid.io/v1/accounts/${c}`
|
|
179
184
|
);
|
|
180
|
-
if (!
|
|
185
|
+
if (!p.ok)
|
|
181
186
|
throw new Error("Trongrid API request failed");
|
|
182
|
-
return (await
|
|
187
|
+
return (await p.json()).data[0].balance / 1e6;
|
|
183
188
|
});
|
|
184
189
|
case Oe.TON:
|
|
185
|
-
return
|
|
186
|
-
const
|
|
190
|
+
return a(async () => {
|
|
191
|
+
const p = await fetch(
|
|
187
192
|
`https://tonapi.io/v1/blockchain/getAccount?account=${c}`
|
|
188
193
|
);
|
|
189
|
-
if (!
|
|
190
|
-
return (await
|
|
194
|
+
if (!p.ok) throw new Error("Ton API request failed");
|
|
195
|
+
return (await p.json()).balance / 1e9;
|
|
191
196
|
});
|
|
192
197
|
case Oe.APT:
|
|
193
|
-
return
|
|
194
|
-
const
|
|
198
|
+
return a(async () => {
|
|
199
|
+
const p = await fetch(
|
|
195
200
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${c}/resources`
|
|
196
201
|
);
|
|
197
|
-
if (!
|
|
198
|
-
const
|
|
199
|
-
(
|
|
202
|
+
if (!p.ok) throw new Error("Aptos API request failed");
|
|
203
|
+
const l = (await p.json()).find(
|
|
204
|
+
(n) => n.type.includes("coin::CoinStore")
|
|
200
205
|
);
|
|
201
|
-
return
|
|
206
|
+
return l ? parseInt(l.data.coin.value) / 1e8 : 0;
|
|
202
207
|
});
|
|
203
208
|
default:
|
|
204
209
|
throw new Error(`Unsupported currency ${i}`);
|
|
@@ -6,4 +6,11 @@ import { EcencyWalletCurrency } from '../enums';
|
|
|
6
6
|
* @param address
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
interface UseGetExternalWalletBalanceQueryOptions {
|
|
10
|
+
/**
|
|
11
|
+
* When true, Chainstack will be queried before Bitquery and public APIs.
|
|
12
|
+
*/
|
|
13
|
+
reverseProviderOrder?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function useGetExternalWalletBalanceQuery(currency: EcencyWalletCurrency, address: string, options?: UseGetExternalWalletBalanceQueryOptions): import('@tanstack/react-query').UseQueryResult<number, Error>;
|
|
16
|
+
export {};
|