@orderly.network/hooks 0.0.71 → 0.0.73

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,19 @@ 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
+ console.log("find first", asks[0], bids[0]);
681
+ const firstPrice = asks[0][0];
682
+ const index = bids.findIndex((item) => item[0] < firstPrice);
683
+ if (index > 0) {
684
+ bids.splice(0, index + 1);
685
+ }
686
+ }
684
687
  return {
685
- asks: mergeItems(data.asks, update.asks).sort(asksSortFn),
686
- bids: mergeItems(data.bids, update.bids).sort(bidsSortFn)
688
+ asks,
689
+ bids
687
690
  };
688
691
  };
689
692
  var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) => {
@@ -959,12 +962,10 @@ var useMarkPricesStream = () => {
959
962
  // return "markprices";
960
963
  // },
961
964
  onError: (error) => {
962
- console.log("error", error);
963
965
  }
964
966
  }
965
967
  );
966
968
  return () => {
967
- console.log("unsubscribe!!!!!!!");
968
969
  unsubscribe?.();
969
970
  };
970
971
  });
@@ -1014,7 +1015,6 @@ var usePositionStream = (symbol, options) => {
1014
1015
  ...options,
1015
1016
  formatter: (data2) => data2,
1016
1017
  onError: (err) => {
1017
- console.log("usePositionStream error", err);
1018
1018
  }
1019
1019
  });
1020
1020
  const { data: markPrices } = useMarkPricesStream();
@@ -1386,9 +1386,9 @@ var BaseOrderCreator = class {
1386
1386
  if (totalNumber.lt(quote_min)) {
1387
1387
  errors.total = {
1388
1388
  type: "min",
1389
- message: `Quantity should be greater or equal than ${new utils.Decimal(
1390
- quote_min
1391
- ).todp(quote_dp)}`
1389
+ message: `Quantity must be at least ${new utils.Decimal(quote_min).todp(
1390
+ quote_dp
1391
+ )}`
1392
1392
  };
1393
1393
  } else if (totalNumber.gt(quote_max)) {
1394
1394
  errors.total = {
@@ -1542,7 +1542,6 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1542
1542
  };
1543
1543
  const calculate = React2.useCallback(
1544
1544
  (values, field, value) => {
1545
- console.log("calculate", values, field, value, markPrice);
1546
1545
  const fieldHandler = getCalculateHandler(field);
1547
1546
  const newValues = ramda.compose(
1548
1547
  ramda.head,
@@ -1651,12 +1650,11 @@ var useMarketsStream = () => {
1651
1650
  // return "markprices";
1652
1651
  // },
1653
1652
  // onError: (error: any) => {
1654
- // console.log("error", error);
1653
+ //
1655
1654
  // },
1656
1655
  }
1657
1656
  );
1658
1657
  return () => {
1659
- console.log("unsubscribe!!!!!!!");
1660
1658
  unsubscribe?.();
1661
1659
  };
1662
1660
  });
@@ -3128,7 +3126,6 @@ var useWithdraw = () => {
3128
3126
  const withdraw = React2.useCallback(
3129
3127
  (inputs) => {
3130
3128
  return account5.assetsManager.withdraw(inputs).then((res) => {
3131
- console.log("---------- withdraw -------", res);
3132
3129
  return res;
3133
3130
  });
3134
3131
  },
@@ -3155,6 +3152,7 @@ var useDeposit = (options) => {
3155
3152
  const [allowance, setAllowance] = React2.useState("0");
3156
3153
  const { account: account5, state } = useAccount();
3157
3154
  const prevAddress = React2.useRef();
3155
+ const getBalanceListener = React2.useRef();
3158
3156
  const dst = React2.useMemo(() => {
3159
3157
  const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3160
3158
  const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
@@ -3197,7 +3195,6 @@ var useDeposit = (options) => {
3197
3195
  return;
3198
3196
  setBalanceRevalidating(true);
3199
3197
  const balance2 = await fetchBalanceHandler(address, decimals);
3200
- console.log("----- refresh balance -----", balance2);
3201
3198
  setBalance(() => balance2);
3202
3199
  setBalanceRevalidating(false);
3203
3200
  } catch (e) {
@@ -3210,15 +3207,13 @@ var useDeposit = (options) => {
3210
3207
  );
3211
3208
  const fetchBalances = React2.useCallback(async (tokens) => {
3212
3209
  const tasks = [];
3213
- console.log("fetch balances ---->>>>", tokens);
3214
3210
  for (const token of tokens) {
3215
3211
  if (isNativeTokenChecker(token.address)) {
3216
3212
  continue;
3217
3213
  }
3218
3214
  tasks.push(account5.assetsManager.getBalanceByAddress(token.address));
3219
3215
  }
3220
- const balances = await Promise.all(tasks);
3221
- console.log("----- get balances from tokens -----", balances);
3216
+ await Promise.all(tasks);
3222
3217
  }, []);
3223
3218
  const getAllowance = async (address, vaultAddress) => {
3224
3219
  const key = `${address}-${vaultAddress}`;
@@ -3243,10 +3238,6 @@ var useDeposit = (options) => {
3243
3238
  return;
3244
3239
  prevAddress.current = address;
3245
3240
  const allowance2 = await account5.assetsManager.getAllowance(address);
3246
- console.log(
3247
- "----- refresh allowance only orderly -----",
3248
- { allowance: allowance2 }
3249
- );
3250
3241
  setAllowance(() => allowance2);
3251
3242
  };
3252
3243
  const getVaultAddress = React2.useCallback(() => {
@@ -3306,6 +3297,26 @@ var useDeposit = (options) => {
3306
3297
  },
3307
3298
  [account5, fetchBalance, getAllowance]
3308
3299
  );
3300
+ const loopGetBalance = async () => {
3301
+ getBalanceListener.current && clearTimeout(getBalanceListener.current);
3302
+ getBalanceListener.current = setTimeout(async () => {
3303
+ const balance2 = await fetchBalanceHandler(
3304
+ options?.address,
3305
+ options?.decimals
3306
+ );
3307
+ setBalance(balance2);
3308
+ loopGetBalance();
3309
+ }, 3e3);
3310
+ };
3311
+ React2.useEffect(() => {
3312
+ if (!options?.address) {
3313
+ return;
3314
+ }
3315
+ loopGetBalance();
3316
+ return () => {
3317
+ getBalanceListener.current && clearTimeout(getBalanceListener.current);
3318
+ };
3319
+ }, [options?.address, options?.decimals]);
3309
3320
  return {
3310
3321
  dst,
3311
3322
  balance,
@@ -3344,7 +3355,6 @@ var useBalance = () => {
3344
3355
  const { data } = useSWRSubscription__default.default("balance", (_, { next }) => {
3345
3356
  const unsubscribe = ws.privateSubscribe("balance", {
3346
3357
  onMessage: (data2) => {
3347
- console.log(data2);
3348
3358
  }
3349
3359
  });
3350
3360
  return () => unsubscribe();
@@ -3384,7 +3394,6 @@ var usePrivateDataObserver = () => {
3384
3394
  }
3385
3395
  return orders;
3386
3396
  }).catch((error) => {
3387
- console.log("error", error, error.stack);
3388
3397
  });
3389
3398
  });
3390
3399
  ee.emit("orders:changed");
@@ -3393,7 +3402,6 @@ var usePrivateDataObserver = () => {
3393
3402
  return () => unsubscribe?.();
3394
3403
  }, [state.accountId]);
3395
3404
  React2.useEffect(() => {
3396
- console.log("subscribe: position: %s", state.accountId);
3397
3405
  if (!state.accountId)
3398
3406
  return;
3399
3407
  const key = ["/v1/positions", state.accountId];
@@ -3438,7 +3446,6 @@ var usePrivateDataObserver = () => {
3438
3446
  }
3439
3447
  });
3440
3448
  return () => {
3441
- console.log("unsubscribe: private subscription position");
3442
3449
  unsubscribe?.();
3443
3450
  };
3444
3451
  }, [state.accountId]);
@@ -3448,7 +3455,6 @@ var useExecutionReport = () => {
3448
3455
  const { data } = useSWRSubscription__default.default("executionreport", (_, { next }) => {
3449
3456
  const unsubscribe = ws.privateSubscribe("executionreport", {
3450
3457
  onMessage: (data2) => {
3451
- console.log(data2);
3452
3458
  }
3453
3459
  });
3454
3460
  return () => unsubscribe();
@@ -3489,7 +3495,6 @@ var useWooSwapQuery = () => {
3489
3495
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3490
3496
  const query = React2.useCallback(
3491
3497
  (inputs) => {
3492
- console.log("inputs", inputs);
3493
3498
  if (loading)
3494
3499
  return;
3495
3500
  start();
@@ -3497,7 +3502,7 @@ var useWooSwapQuery = () => {
3497
3502
  // src_network: inputs.srcNetwork,
3498
3503
  network: "arbitrum",
3499
3504
  from_token: inputs.srcToken,
3500
- to_token: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
3505
+ to_token: inputs.dstToken,
3501
3506
  //account.assetsManager.usdcAddress,
3502
3507
  from_amount: inputs.amount,
3503
3508
  //inputs.amount,
@@ -3563,10 +3568,10 @@ var useWooCrossSwapQuery = () => {
3563
3568
  start();
3564
3569
  const params = {
3565
3570
  // src_network: inputs.srcNetwork,
3566
- src_network: "base",
3571
+ src_network: inputs.srcNetwork.toLowerCase(),
3567
3572
  dst_network: "arbitrum",
3568
3573
  src_token: inputs.srcToken,
3569
- dst_token: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
3574
+ dst_token: inputs.dstToken,
3570
3575
  //account.assetsManager.usdcAddress,
3571
3576
  src_amount: inputs.amount,
3572
3577
  //inputs.amount,
@@ -3598,7 +3603,6 @@ var useWooCrossSwapQuery = () => {
3598
3603
  minToAmount: BigInt(swapInfo.dst_infos.min_to_amount),
3599
3604
  orderlyNativeFees: 0n
3600
3605
  }).then((data) => {
3601
- console.log("res::::", data);
3602
3606
  return {
3603
3607
  ...swapInfo,
3604
3608
  dst_infos: {
@@ -3621,6 +3625,7 @@ var useCrossSwap = () => {
3621
3625
  const [layerStatus, setLayerStatus] = React2.useState(
3622
3626
  "WAITTING" /* INITIALIZING */
3623
3627
  );
3628
+ const ee = useEventEmitter();
3624
3629
  const [bridgeMessage, setBridgeMessage] = React2.useState();
3625
3630
  const [status, setStatus] = React2.useState(
3626
3631
  types.WS_WalletStatusEnum.NO
@@ -3630,18 +3635,21 @@ var useCrossSwap = () => {
3630
3635
  const { networkId, configStore } = React2.useContext(OrderlyContext);
3631
3636
  const client = React2.useRef(scanClient.createClient(networkId)).current;
3632
3637
  const timer = React2.useRef();
3633
- useWalletSubscription({
3634
- onMessage: (message) => {
3635
- const { side, transStatus, trxId } = message;
3638
+ React2.useEffect(() => {
3639
+ const handler = (data) => {
3640
+ const { side, transStatus, trxId } = data;
3636
3641
  if (side === "DEPOSIT" && trxId === txHashFromBridge.current) {
3637
3642
  setStatus(transStatus);
3638
3643
  }
3639
- }
3640
- });
3644
+ };
3645
+ ee.on("wallet:changed", handler);
3646
+ return () => {
3647
+ ee.off("wallet:changed", handler);
3648
+ };
3649
+ }, [txHashFromBridge.current]);
3641
3650
  const checkLayerStatus = React2.useCallback((txHash) => {
3642
3651
  const check = async (txHash2) => {
3643
3652
  const { messages } = await client.getMessagesBySrcTxHash(txHash2);
3644
- console.log("messages:", messages);
3645
3653
  if (messages.length > 0) {
3646
3654
  const { status: status2 } = messages[0];
3647
3655
  if (status2 === "INFLIGHT" /* INFLIGHT */) {
@@ -3716,7 +3724,6 @@ var useCrossSwap = () => {
3716
3724
  checkLayerStatus(result.hash);
3717
3725
  return ramda.pick(["from", "to", "hash", "value"], result);
3718
3726
  } catch (e) {
3719
- console.log("swap error:", e);
3720
3727
  stop();
3721
3728
  throw new Error(e.errorCode);
3722
3729
  }
@@ -4011,16 +4018,21 @@ var useSwap = () => {
4011
4018
  types.WS_WalletStatusEnum.NO
4012
4019
  );
4013
4020
  const txHash = React2.useRef();
4014
- useWalletSubscription({
4015
- onMessage: (message) => {
4016
- const { side, transStatus, trxId } = message;
4021
+ const ee = useEventEmitter();
4022
+ React2.useEffect(() => {
4023
+ const handler = (data) => {
4024
+ const { side, transStatus, trxId } = data;
4017
4025
  if (side === "DEPOSIT" && trxId === txHash.current) {
4018
4026
  setStatus(transStatus);
4019
4027
  }
4020
- }
4021
- });
4028
+ };
4029
+ ee.on("wallet:changed", handler);
4030
+ return () => {
4031
+ ee.off("wallet:changed", handler);
4032
+ };
4033
+ }, [txHash.current]);
4022
4034
  const dstValutDeposit = React2.useCallback(() => {
4023
- const brokerId = configStore.get("onlyTestnet") ? "woofi_dex" : "woofi_pro";
4035
+ const brokerId = configStore.get("brokerId");
4024
4036
  return {
4025
4037
  accountId: account5.accountIdHashStr,
4026
4038
  brokerHash: core.utils.parseBrokerHash(brokerId),
@@ -4054,11 +4066,9 @@ var useSwap = () => {
4054
4066
  }
4055
4067
  );
4056
4068
  stop();
4057
- console.log("single swap result", result);
4058
4069
  txHash.current = result.hash;
4059
4070
  return ramda.pick(["from", "to", "hash", "value"], result);
4060
4071
  } catch (e) {
4061
- console.log("\u8C03\u7528\u5408\u7EA6\u62A5\u9519\uFF1A", e);
4062
4072
  throw new Error(e.errorCode);
4063
4073
  }
4064
4074
  },