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

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-R3JJJMNQ.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,8 +4077,31 @@ 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
- window.sendMatchWalletMessage = (method, data) => {
4085
+ window.sendMatchWalletMessage = (method, data, retry = 5, times = 0) => {
4086
+ try {
4087
+ if (!iframeLoaded) {
4088
+ throw new Error("Wallet not ready");
4089
+ }
4090
+ if (!walletInited) {
4091
+ throw new Error("Wallet not inited");
4092
+ }
4093
+ if (!document.getElementById("match-wallet")) {
4094
+ throw new Error("Wallet not found");
4095
+ }
4096
+ } catch (error) {
4097
+ if (times < retry) {
4098
+ setTimeout(() => {
4099
+ window.sendMatchWalletMessage(method, data, retry, times + 1);
4100
+ }, 1e3);
4101
+ } else {
4102
+ throw error;
4103
+ }
4104
+ }
4072
4105
  const messageId = Date.now().toString() + Math.random().toString().slice(6);
4073
4106
  const message = {
4074
4107
  method,
@@ -4076,32 +4109,27 @@ function useWalletInit({
4076
4109
  messageId,
4077
4110
  source: "matchid"
4078
4111
  };
4079
- if (document.getElementById("match-wallet")) {
4080
- matchlog_default.log("matchid.sdk.sendMatchWalletMessage", message, endpoints.auth);
4081
- getWalletIframe()?.contentWindow?.postMessage(message, endpoints.auth);
4082
- return messageId;
4083
- }
4084
- console.error("not found iframe");
4085
- return false;
4112
+ matchlog_default.log("matchid.sdk.sendMatchWalletMessage", message, endpoints.auth);
4113
+ getWalletIframe()?.contentWindow?.postMessage(message, endpoints.auth);
4114
+ return messageId;
4086
4115
  };
4087
4116
  window.waitMatchUntilWalletMessage = async (method, data, timeout = 3e4) => {
4088
4117
  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;
4118
+ try {
4119
+ const messageId = window.sendMatchWalletMessage(method, data);
4120
+ window.matchWalletMessageIdMap[messageId] = { resolve, reject };
4121
+ window.matchWalletMessageIdMap[messageId].timeout = setTimeout(() => {
4122
+ console.error("Get wallet result timeout", {
4123
+ messageId,
4124
+ method,
4125
+ data
4126
+ });
4127
+ delete window.matchWalletMessageIdMap[messageId];
4128
+ reject(new Error("Get wallet result timeout"));
4129
+ }, timeout);
4130
+ } catch (error) {
4131
+ reject(error);
4094
4132
  }
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
4133
  });
4106
4134
  };
4107
4135
  } else {