@orderly.network/hooks 0.0.72 → 0.0.74

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.d.mts CHANGED
@@ -416,6 +416,7 @@ declare const useWooCrossSwapQuery: () => {
416
416
  srcToken: string;
417
417
  amount: bigint;
418
418
  slippage: number;
419
+ dstToken: string;
419
420
  crossChainRouteAddress: string;
420
421
  }) => Promise<any> | undefined;
421
422
  loading: boolean;
package/dist/index.d.ts CHANGED
@@ -416,6 +416,7 @@ declare const useWooCrossSwapQuery: () => {
416
416
  srcToken: string;
417
417
  amount: bigint;
418
418
  slippage: number;
419
+ dstToken: string;
419
420
  crossChainRouteAddress: string;
420
421
  }) => Promise<any> | undefined;
421
422
  loading: boolean;
package/dist/index.js CHANGED
@@ -60,7 +60,6 @@ var useLazyQuery = (query, options) => {
60
60
  return useSWRMutation__default.default(
61
61
  query,
62
62
  (url, options2) => {
63
- console.log(url, options2);
64
63
  url = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
65
64
  if (options2?.arg) {
66
65
  const queryString = Object.entries(options2.arg).map(
@@ -264,7 +263,6 @@ var usePrivateQuery = (query, options) => {
264
263
  ...swrOptions,
265
264
  use: [signatureMiddleware, ...middleware],
266
265
  onError: (err) => {
267
- console.log("usePrivateQuery error", err);
268
266
  }
269
267
  }
270
268
  );
@@ -334,7 +332,6 @@ function parseJSON(value) {
334
332
  try {
335
333
  return value === "undefined" ? void 0 : JSON.parse(value ?? "");
336
334
  } catch {
337
- console.log("parsing error on", { value });
338
335
  return void 0;
339
336
  }
340
337
  }
@@ -443,7 +440,6 @@ var useRunOnce = ({ fn, sessionKey }) => {
443
440
  };
444
441
  var DataSourceContext = React2.createContext({});
445
442
  var DataSourceProvider = (props) => {
446
- console.log("render DataSourceProvider");
447
443
  useAccountInstance();
448
444
  useConstant__default.default(() => {
449
445
  });
@@ -509,12 +505,11 @@ var useTickerStream = (symbol) => {
509
505
  // return "markprices";
510
506
  // },
511
507
  // onError: (error: any) => {
512
- // console.log("error", error);
508
+ //
513
509
  // },
514
510
  }
515
511
  );
516
512
  return () => {
517
- console.log("unsubscribe!!!!!!!");
518
513
  unsubscribe?.();
519
514
  };
520
515
  }
@@ -550,7 +545,6 @@ var useMarkPrice = (symbol) => {
550
545
  }
551
546
  });
552
547
  return () => {
553
- console.log("unsubscribe useMarkPrice !!!!!!!");
554
548
  unsubscribe?.();
555
549
  };
556
550
  });
@@ -671,7 +665,6 @@ var mergeItems = (data, update) => {
671
665
  } else {
672
666
  if (quantity === 0) {
673
667
  data.splice(index, 1);
674
- continue;
675
668
  } else {
676
669
  data[index] = item;
677
670
  }
@@ -681,9 +674,18 @@ var mergeItems = (data, update) => {
681
674
  return data;
682
675
  };
683
676
  var mergeOrderbook = (data, update) => {
677
+ const asks = mergeItems(data.asks, update.asks).sort(asksSortFn);
678
+ const bids = mergeItems(data.bids, update.bids).sort(bidsSortFn);
679
+ if (asks.length > 0) {
680
+ const firstPrice = asks[0][0];
681
+ const index = bids.findIndex((item) => item[0] < firstPrice);
682
+ if (index > 0) {
683
+ bids.splice(0, index + 1);
684
+ }
685
+ }
684
686
  return {
685
- asks: mergeItems(data.asks, update.asks).sort(asksSortFn),
686
- bids: mergeItems(data.bids, update.bids).sort(bidsSortFn)
687
+ asks,
688
+ bids
687
689
  };
688
690
  };
689
691
  var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) => {
@@ -959,12 +961,10 @@ var useMarkPricesStream = () => {
959
961
  // return "markprices";
960
962
  // },
961
963
  onError: (error) => {
962
- console.log("error", error);
963
964
  }
964
965
  }
965
966
  );
966
967
  return () => {
967
- console.log("unsubscribe!!!!!!!");
968
968
  unsubscribe?.();
969
969
  };
970
970
  });
@@ -1014,7 +1014,6 @@ var usePositionStream = (symbol, options) => {
1014
1014
  ...options,
1015
1015
  formatter: (data2) => data2,
1016
1016
  onError: (err) => {
1017
- console.log("usePositionStream error", err);
1018
1017
  }
1019
1018
  });
1020
1019
  const { data: markPrices } = useMarkPricesStream();
@@ -1542,7 +1541,6 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1542
1541
  };
1543
1542
  const calculate = React2.useCallback(
1544
1543
  (values, field, value) => {
1545
- console.log("calculate", values, field, value, markPrice);
1546
1544
  const fieldHandler = getCalculateHandler(field);
1547
1545
  const newValues = ramda.compose(
1548
1546
  ramda.head,
@@ -1651,12 +1649,11 @@ var useMarketsStream = () => {
1651
1649
  // return "markprices";
1652
1650
  // },
1653
1651
  // onError: (error: any) => {
1654
- // console.log("error", error);
1652
+ //
1655
1653
  // },
1656
1654
  }
1657
1655
  );
1658
1656
  return () => {
1659
- console.log("unsubscribe!!!!!!!");
1660
1657
  unsubscribe?.();
1661
1658
  };
1662
1659
  });
@@ -3128,7 +3125,6 @@ var useWithdraw = () => {
3128
3125
  const withdraw = React2.useCallback(
3129
3126
  (inputs) => {
3130
3127
  return account5.assetsManager.withdraw(inputs).then((res) => {
3131
- console.log("---------- withdraw -------", res);
3132
3128
  return res;
3133
3129
  });
3134
3130
  },
@@ -3155,6 +3151,7 @@ var useDeposit = (options) => {
3155
3151
  const [allowance, setAllowance] = React2.useState("0");
3156
3152
  const { account: account5, state } = useAccount();
3157
3153
  const prevAddress = React2.useRef();
3154
+ const getBalanceListener = React2.useRef();
3158
3155
  const dst = React2.useMemo(() => {
3159
3156
  const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3160
3157
  const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
@@ -3197,7 +3194,6 @@ var useDeposit = (options) => {
3197
3194
  return;
3198
3195
  setBalanceRevalidating(true);
3199
3196
  const balance2 = await fetchBalanceHandler(address, decimals);
3200
- console.log("----- refresh balance -----", balance2);
3201
3197
  setBalance(() => balance2);
3202
3198
  setBalanceRevalidating(false);
3203
3199
  } catch (e) {
@@ -3210,15 +3206,13 @@ var useDeposit = (options) => {
3210
3206
  );
3211
3207
  const fetchBalances = React2.useCallback(async (tokens) => {
3212
3208
  const tasks = [];
3213
- console.log("fetch balances ---->>>>", tokens);
3214
3209
  for (const token of tokens) {
3215
3210
  if (isNativeTokenChecker(token.address)) {
3216
3211
  continue;
3217
3212
  }
3218
3213
  tasks.push(account5.assetsManager.getBalanceByAddress(token.address));
3219
3214
  }
3220
- const balances = await Promise.all(tasks);
3221
- console.log("----- get balances from tokens -----", balances);
3215
+ await Promise.all(tasks);
3222
3216
  }, []);
3223
3217
  const getAllowance = async (address, vaultAddress) => {
3224
3218
  const key = `${address}-${vaultAddress}`;
@@ -3243,10 +3237,6 @@ var useDeposit = (options) => {
3243
3237
  return;
3244
3238
  prevAddress.current = address;
3245
3239
  const allowance2 = await account5.assetsManager.getAllowance(address);
3246
- console.log(
3247
- "----- refresh allowance only orderly -----",
3248
- { allowance: allowance2 }
3249
- );
3250
3240
  setAllowance(() => allowance2);
3251
3241
  };
3252
3242
  const getVaultAddress = React2.useCallback(() => {
@@ -3306,6 +3296,26 @@ var useDeposit = (options) => {
3306
3296
  },
3307
3297
  [account5, fetchBalance, getAllowance]
3308
3298
  );
3299
+ const loopGetBalance = async () => {
3300
+ getBalanceListener.current && clearTimeout(getBalanceListener.current);
3301
+ getBalanceListener.current = setTimeout(async () => {
3302
+ const balance2 = await fetchBalanceHandler(
3303
+ options?.address,
3304
+ options?.decimals
3305
+ );
3306
+ setBalance(balance2);
3307
+ loopGetBalance();
3308
+ }, 3e3);
3309
+ };
3310
+ React2.useEffect(() => {
3311
+ if (!options?.address) {
3312
+ return;
3313
+ }
3314
+ loopGetBalance();
3315
+ return () => {
3316
+ getBalanceListener.current && clearTimeout(getBalanceListener.current);
3317
+ };
3318
+ }, [options?.address, options?.decimals]);
3309
3319
  return {
3310
3320
  dst,
3311
3321
  balance,
@@ -3344,7 +3354,6 @@ var useBalance = () => {
3344
3354
  const { data } = useSWRSubscription__default.default("balance", (_, { next }) => {
3345
3355
  const unsubscribe = ws.privateSubscribe("balance", {
3346
3356
  onMessage: (data2) => {
3347
- console.log(data2);
3348
3357
  }
3349
3358
  });
3350
3359
  return () => unsubscribe();
@@ -3384,7 +3393,6 @@ var usePrivateDataObserver = () => {
3384
3393
  }
3385
3394
  return orders;
3386
3395
  }).catch((error) => {
3387
- console.log("error", error, error.stack);
3388
3396
  });
3389
3397
  });
3390
3398
  ee.emit("orders:changed");
@@ -3393,7 +3401,6 @@ var usePrivateDataObserver = () => {
3393
3401
  return () => unsubscribe?.();
3394
3402
  }, [state.accountId]);
3395
3403
  React2.useEffect(() => {
3396
- console.log("subscribe: position: %s", state.accountId);
3397
3404
  if (!state.accountId)
3398
3405
  return;
3399
3406
  const key = ["/v1/positions", state.accountId];
@@ -3438,7 +3445,6 @@ var usePrivateDataObserver = () => {
3438
3445
  }
3439
3446
  });
3440
3447
  return () => {
3441
- console.log("unsubscribe: private subscription position");
3442
3448
  unsubscribe?.();
3443
3449
  };
3444
3450
  }, [state.accountId]);
@@ -3448,7 +3454,6 @@ var useExecutionReport = () => {
3448
3454
  const { data } = useSWRSubscription__default.default("executionreport", (_, { next }) => {
3449
3455
  const unsubscribe = ws.privateSubscribe("executionreport", {
3450
3456
  onMessage: (data2) => {
3451
- console.log(data2);
3452
3457
  }
3453
3458
  });
3454
3459
  return () => unsubscribe();
@@ -3489,7 +3494,6 @@ var useWooSwapQuery = () => {
3489
3494
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3490
3495
  const query = React2.useCallback(
3491
3496
  (inputs) => {
3492
- console.log("inputs", inputs);
3493
3497
  if (loading)
3494
3498
  return;
3495
3499
  start();
@@ -3497,7 +3501,7 @@ var useWooSwapQuery = () => {
3497
3501
  // src_network: inputs.srcNetwork,
3498
3502
  network: "arbitrum",
3499
3503
  from_token: inputs.srcToken,
3500
- to_token: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
3504
+ to_token: inputs.dstToken,
3501
3505
  //account.assetsManager.usdcAddress,
3502
3506
  from_amount: inputs.amount,
3503
3507
  //inputs.amount,
@@ -3563,10 +3567,10 @@ var useWooCrossSwapQuery = () => {
3563
3567
  start();
3564
3568
  const params = {
3565
3569
  // src_network: inputs.srcNetwork,
3566
- src_network: "base",
3570
+ src_network: inputs.srcNetwork.toLowerCase(),
3567
3571
  dst_network: "arbitrum",
3568
3572
  src_token: inputs.srcToken,
3569
- dst_token: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
3573
+ dst_token: inputs.dstToken,
3570
3574
  //account.assetsManager.usdcAddress,
3571
3575
  src_amount: inputs.amount,
3572
3576
  //inputs.amount,
@@ -3598,7 +3602,6 @@ var useWooCrossSwapQuery = () => {
3598
3602
  minToAmount: BigInt(swapInfo.dst_infos.min_to_amount),
3599
3603
  orderlyNativeFees: 0n
3600
3604
  }).then((data) => {
3601
- console.log("res::::", data);
3602
3605
  return {
3603
3606
  ...swapInfo,
3604
3607
  dst_infos: {
@@ -3621,6 +3624,7 @@ var useCrossSwap = () => {
3621
3624
  const [layerStatus, setLayerStatus] = React2.useState(
3622
3625
  "WAITTING" /* INITIALIZING */
3623
3626
  );
3627
+ const ee = useEventEmitter();
3624
3628
  const [bridgeMessage, setBridgeMessage] = React2.useState();
3625
3629
  const [status, setStatus] = React2.useState(
3626
3630
  types.WS_WalletStatusEnum.NO
@@ -3630,18 +3634,21 @@ var useCrossSwap = () => {
3630
3634
  const { networkId, configStore } = React2.useContext(OrderlyContext);
3631
3635
  const client = React2.useRef(scanClient.createClient(networkId)).current;
3632
3636
  const timer = React2.useRef();
3633
- useWalletSubscription({
3634
- onMessage: (message) => {
3635
- const { side, transStatus, trxId } = message;
3637
+ React2.useEffect(() => {
3638
+ const handler = (data) => {
3639
+ const { side, transStatus, trxId } = data;
3636
3640
  if (side === "DEPOSIT" && trxId === txHashFromBridge.current) {
3637
3641
  setStatus(transStatus);
3638
3642
  }
3639
- }
3640
- });
3643
+ };
3644
+ ee.on("wallet:changed", handler);
3645
+ return () => {
3646
+ ee.off("wallet:changed", handler);
3647
+ };
3648
+ }, [txHashFromBridge.current]);
3641
3649
  const checkLayerStatus = React2.useCallback((txHash) => {
3642
3650
  const check = async (txHash2) => {
3643
3651
  const { messages } = await client.getMessagesBySrcTxHash(txHash2);
3644
- console.log("messages:", messages);
3645
3652
  if (messages.length > 0) {
3646
3653
  const { status: status2 } = messages[0];
3647
3654
  if (status2 === "INFLIGHT" /* INFLIGHT */) {
@@ -3716,7 +3723,6 @@ var useCrossSwap = () => {
3716
3723
  checkLayerStatus(result.hash);
3717
3724
  return ramda.pick(["from", "to", "hash", "value"], result);
3718
3725
  } catch (e) {
3719
- console.log("swap error:", e);
3720
3726
  stop();
3721
3727
  throw new Error(e.errorCode);
3722
3728
  }
@@ -4011,14 +4017,19 @@ var useSwap = () => {
4011
4017
  types.WS_WalletStatusEnum.NO
4012
4018
  );
4013
4019
  const txHash = React2.useRef();
4014
- useWalletSubscription({
4015
- onMessage: (message) => {
4016
- const { side, transStatus, trxId } = message;
4020
+ const ee = useEventEmitter();
4021
+ React2.useEffect(() => {
4022
+ const handler = (data) => {
4023
+ const { side, transStatus, trxId } = data;
4017
4024
  if (side === "DEPOSIT" && trxId === txHash.current) {
4018
4025
  setStatus(transStatus);
4019
4026
  }
4020
- }
4021
- });
4027
+ };
4028
+ ee.on("wallet:changed", handler);
4029
+ return () => {
4030
+ ee.off("wallet:changed", handler);
4031
+ };
4032
+ }, [txHash.current]);
4022
4033
  const dstValutDeposit = React2.useCallback(() => {
4023
4034
  const brokerId = configStore.get("brokerId");
4024
4035
  return {
@@ -4054,11 +4065,9 @@ var useSwap = () => {
4054
4065
  }
4055
4066
  );
4056
4067
  stop();
4057
- console.log("single swap result", result);
4058
4068
  txHash.current = result.hash;
4059
4069
  return ramda.pick(["from", "to", "hash", "value"], result);
4060
4070
  } catch (e) {
4061
- console.log("\u8C03\u7528\u5408\u7EA6\u62A5\u9519\uFF1A", e);
4062
4071
  throw new Error(e.errorCode);
4063
4072
  }
4064
4073
  },