@matchain/matchid-sdk-react 0.1.39 → 0.1.40-alpha.0

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.
@@ -4,7 +4,7 @@ import {
4
4
  useMatchEvents,
5
5
  useUserInfo,
6
6
  useWallet
7
- } from "../chunk-RVAWFV2B.mjs";
7
+ } from "../chunk-XMGJLSI2.mjs";
8
8
  import "../chunk-6PWH7WZI.mjs";
9
9
  import "../chunk-J5LGTIGS.mjs";
10
10
  export {
package/dist/index.js CHANGED
@@ -3874,6 +3874,9 @@ function CEXBindModal({
3874
3874
  const [key, setKey] = (0, import_react22.useState)("");
3875
3875
  const [secret, setSecret] = (0, import_react22.useState)("");
3876
3876
  const [error, setError] = (0, import_react22.useState)("");
3877
+ const needPassphrase = (0, import_react22.useMemo)(() => {
3878
+ return ["bitget", "okx"].includes(type.toLowerCase());
3879
+ }, [type]);
3877
3880
  (0, import_react22.useEffect)(() => {
3878
3881
  if (isOpen) {
3879
3882
  setSecret("");
@@ -3890,7 +3893,7 @@ function CEXBindModal({
3890
3893
  cex: type,
3891
3894
  api_key: key,
3892
3895
  api_secret: secret,
3893
- ...type ? { api_passphrase: APIPassphrase } : {}
3896
+ ...needPassphrase ? { api_passphrase: APIPassphrase } : {}
3894
3897
  });
3895
3898
  if (isSuccess(res)) {
3896
3899
  await refreshOverview();
@@ -3942,7 +3945,7 @@ function CEXBindModal({
3942
3945
  placeholder: "**** **** ****"
3943
3946
  }
3944
3947
  ) }),
3945
- type == "OKX" && /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(Field, { error, label: intl.formatMessage({
3948
+ needPassphrase && /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(Field, { error, label: intl.formatMessage({
3946
3949
  id: "CEXBindApiPassphrase"
3947
3950
  }), children: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
3948
3951
  Input,
@@ -4051,6 +4054,13 @@ function useWalletInit({
4051
4054
  const [walletInited, setWalletInited] = (0, import_react23.useState)(false);
4052
4055
  const { appid, token, overview } = useLocalStore_default();
4053
4056
  const { initWallet, generateWallet } = useWallet();
4057
+ const [iframeLoaded, setIframeLoaded] = (0, import_react23.useState)(false);
4058
+ (0, import_react23.useEffect)(() => {
4059
+ console.log("wallet status", {
4060
+ iframeLoaded,
4061
+ walletInited
4062
+ });
4063
+ }, [iframeLoaded, walletInited]);
4054
4064
  (0, import_react23.useEffect)(() => {
4055
4065
  if (endpoints.auth) {
4056
4066
  if (!window.matchWalletMessageIdMap) {
@@ -4067,6 +4077,10 @@ function useWalletInit({
4067
4077
  iframe.onerror = (e) => {
4068
4078
  console.error("iframe error", e);
4069
4079
  };
4080
+ iframe.addEventListener("load", () => {
4081
+ console.log("Iframe has loaded.");
4082
+ setIframeLoaded(true);
4083
+ });
4070
4084
  document.body.insertBefore(iframe, document.body.firstChild);
4071
4085
  window.sendMatchWalletMessage = (method, data) => {
4072
4086
  const messageId = Date.now().toString() + Math.random().toString().slice(6);
@@ -4076,32 +4090,36 @@ function useWalletInit({
4076
4090
  messageId,
4077
4091
  source: "matchid"
4078
4092
  };
4093
+ if (!iframeLoaded) {
4094
+ throw new Error("Wallet not ready");
4095
+ }
4096
+ if (!walletInited) {
4097
+ throw new Error("Wallet not inited");
4098
+ }
4079
4099
  if (document.getElementById("match-wallet")) {
4080
4100
  matchlog_default.log("matchid.sdk.sendMatchWalletMessage", message, endpoints.auth);
4081
4101
  getWalletIframe()?.contentWindow?.postMessage(message, endpoints.auth);
4082
4102
  return messageId;
4083
4103
  }
4084
- console.error("not found iframe");
4085
- return false;
4104
+ throw new Error("Wallet not found");
4086
4105
  };
4087
4106
  window.waitMatchUntilWalletMessage = async (method, data, timeout = 3e4) => {
4088
4107
  return new Promise((resolve, reject) => {
4089
- const messageId = window.sendMatchWalletMessage(method, data);
4090
- if (!messageId) {
4091
- console.error("Can't find wallet message");
4092
- reject(new Error("Can't find wallet message"));
4093
- return;
4108
+ try {
4109
+ const messageId = window.sendMatchWalletMessage(method, data);
4110
+ window.matchWalletMessageIdMap[messageId] = { resolve, reject };
4111
+ window.matchWalletMessageIdMap[messageId].timeout = setTimeout(() => {
4112
+ console.error("Get wallet result timeout", {
4113
+ messageId,
4114
+ method,
4115
+ data
4116
+ });
4117
+ delete window.matchWalletMessageIdMap[messageId];
4118
+ reject(new Error("Get wallet result timeout"));
4119
+ }, timeout);
4120
+ } catch (error) {
4121
+ reject(error);
4094
4122
  }
4095
- window.matchWalletMessageIdMap[messageId] = { resolve, reject };
4096
- window.matchWalletMessageIdMap[messageId].timeout = setTimeout(() => {
4097
- console.error("Get wallet result timeout", {
4098
- messageId,
4099
- method,
4100
- data
4101
- });
4102
- delete window.matchWalletMessageIdMap[messageId];
4103
- reject(new Error("Get wallet result timeout"));
4104
- }, timeout);
4105
4123
  });
4106
4124
  };
4107
4125
  } else {