@owney/sdk 0.7.26-beta.1 → 0.7.26-beta.2

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/index.cjs CHANGED
@@ -2208,7 +2208,21 @@ var CHAIN_NAMES = {
2208
2208
  function chainName(chainId) {
2209
2209
  return CHAIN_NAMES[chainId] ?? `chain ${chainId}`;
2210
2210
  }
2211
- async function ensureWalletOnChain(pub, wallet, expected) {
2211
+ var SETTLE_TIMEOUT_MS = 8e3;
2212
+ var POLL_INTERVAL_MS = 200;
2213
+ var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2214
+ async function readChainId(pub) {
2215
+ try {
2216
+ return await pub.getChainId();
2217
+ } catch {
2218
+ return void 0;
2219
+ }
2220
+ }
2221
+ async function ensureWalletOnChain(pub, wallet, expected, options = {}) {
2222
+ const {
2223
+ settleTimeoutMs = SETTLE_TIMEOUT_MS,
2224
+ pollIntervalMs = POLL_INTERVAL_MS
2225
+ } = options;
2212
2226
  const actual = await pub.getChainId();
2213
2227
  if (actual === expected) return;
2214
2228
  try {
@@ -2224,14 +2238,18 @@ async function ensureWalletOnChain(pub, wallet, expected) {
2224
2238
  }
2225
2239
  );
2226
2240
  }
2227
- const after = await pub.getChainId();
2228
- if (after !== expected) {
2229
- throw new OwneyError(
2230
- "CHAIN_MISMATCH",
2231
- `Your wallet is still on ${chainName(after)}. Switch it to ${chainName(expected)} and try again.`,
2232
- { expectedChainId: expected, actualChainId: after }
2233
- );
2234
- }
2241
+ const deadline = Date.now() + settleTimeoutMs;
2242
+ let after = await readChainId(pub);
2243
+ while (after !== expected && Date.now() < deadline) {
2244
+ await wait(pollIntervalMs);
2245
+ after = await readChainId(pub);
2246
+ }
2247
+ if (after === expected) return;
2248
+ throw new OwneyError(
2249
+ "CHAIN_MISMATCH",
2250
+ `Your wallet is still on ${chainName(after ?? actual)}. Switch it to ${chainName(expected)} and try again.`,
2251
+ { expectedChainId: expected, actualChainId: after ?? actual }
2252
+ );
2235
2253
  }
2236
2254
 
2237
2255
  // src/lib/swap/swap-api.ts
package/dist/index.js CHANGED
@@ -2174,7 +2174,21 @@ var CHAIN_NAMES = {
2174
2174
  function chainName(chainId) {
2175
2175
  return CHAIN_NAMES[chainId] ?? `chain ${chainId}`;
2176
2176
  }
2177
- async function ensureWalletOnChain(pub, wallet, expected) {
2177
+ var SETTLE_TIMEOUT_MS = 8e3;
2178
+ var POLL_INTERVAL_MS = 200;
2179
+ var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2180
+ async function readChainId(pub) {
2181
+ try {
2182
+ return await pub.getChainId();
2183
+ } catch {
2184
+ return void 0;
2185
+ }
2186
+ }
2187
+ async function ensureWalletOnChain(pub, wallet, expected, options = {}) {
2188
+ const {
2189
+ settleTimeoutMs = SETTLE_TIMEOUT_MS,
2190
+ pollIntervalMs = POLL_INTERVAL_MS
2191
+ } = options;
2178
2192
  const actual = await pub.getChainId();
2179
2193
  if (actual === expected) return;
2180
2194
  try {
@@ -2190,14 +2204,18 @@ async function ensureWalletOnChain(pub, wallet, expected) {
2190
2204
  }
2191
2205
  );
2192
2206
  }
2193
- const after = await pub.getChainId();
2194
- if (after !== expected) {
2195
- throw new OwneyError(
2196
- "CHAIN_MISMATCH",
2197
- `Your wallet is still on ${chainName(after)}. Switch it to ${chainName(expected)} and try again.`,
2198
- { expectedChainId: expected, actualChainId: after }
2199
- );
2200
- }
2207
+ const deadline = Date.now() + settleTimeoutMs;
2208
+ let after = await readChainId(pub);
2209
+ while (after !== expected && Date.now() < deadline) {
2210
+ await wait(pollIntervalMs);
2211
+ after = await readChainId(pub);
2212
+ }
2213
+ if (after === expected) return;
2214
+ throw new OwneyError(
2215
+ "CHAIN_MISMATCH",
2216
+ `Your wallet is still on ${chainName(after ?? actual)}. Switch it to ${chainName(expected)} and try again.`,
2217
+ { expectedChainId: expected, actualChainId: after ?? actual }
2218
+ );
2201
2219
  }
2202
2220
 
2203
2221
  // src/lib/swap/swap-api.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.26-beta.1",
3
+ "version": "0.7.26-beta.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",