@matchain/matchid-sdk-react 0.1.8 → 0.1.9
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 +116 -19
- package/dist/index.d.ts +116 -19
- package/dist/index.js +313 -157
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +325 -170
- package/dist/index.mjs.map +1 -1
- package/example/package-lock.json +1 -1
- package/example/package.json +1 -1
- package/example/src/App.tsx +2 -2
- package/example/src/pages/Home.tsx +1 -1
- package/example/src/pages/Login.tsx +102 -67
- package/example/vite.config.ts +1 -1
- package/example/yarn.lock +3 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -395,7 +395,7 @@ function ModalWithHeader({
|
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
// src/components/PasswordModal/index.tsx
|
|
398
|
-
import { useEffect as
|
|
398
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
399
399
|
|
|
400
400
|
// src/components/Input/index.tsx
|
|
401
401
|
import { useState } from "react";
|
|
@@ -596,6 +596,20 @@ var getToken = () => {
|
|
|
596
596
|
}
|
|
597
597
|
};
|
|
598
598
|
|
|
599
|
+
// src/utils/matchlog.ts
|
|
600
|
+
var matchDevExists = () => localStorage.getItem("matchid-sdk-react-debug") !== null;
|
|
601
|
+
var handler = {
|
|
602
|
+
get(target, prop) {
|
|
603
|
+
if (matchDevExists() && typeof target[prop] === "function") {
|
|
604
|
+
return target[prop].bind(console);
|
|
605
|
+
}
|
|
606
|
+
return () => {
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var matchlog = new Proxy(console, handler);
|
|
611
|
+
var matchlog_default = matchlog;
|
|
612
|
+
|
|
599
613
|
// src/api/request.ts
|
|
600
614
|
var SUCCESS_CODE = 0;
|
|
601
615
|
var isSuccess = (res) => {
|
|
@@ -617,7 +631,7 @@ var request = async (config) => {
|
|
|
617
631
|
instance.defaults.headers.common["Authorization"] = token;
|
|
618
632
|
}
|
|
619
633
|
const { data } = await instance.request(config);
|
|
620
|
-
|
|
634
|
+
matchlog_default.log("api", data);
|
|
621
635
|
if (data.code == 401001) {
|
|
622
636
|
localStore.getState().logout();
|
|
623
637
|
throw new Error("Your session has expired, please log in again");
|
|
@@ -673,6 +687,72 @@ var setUserNameApi = (data) => {
|
|
|
673
687
|
data
|
|
674
688
|
});
|
|
675
689
|
};
|
|
690
|
+
var getBindListApi = () => {
|
|
691
|
+
return request_default({
|
|
692
|
+
url: `/bind/list`,
|
|
693
|
+
method: "GET"
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
var getPohListApi = () => {
|
|
697
|
+
return request_default({
|
|
698
|
+
url: `/poh/list`,
|
|
699
|
+
method: "GET"
|
|
700
|
+
});
|
|
701
|
+
};
|
|
702
|
+
var getBindInfoApi = () => {
|
|
703
|
+
return request_default({
|
|
704
|
+
url: `/bind`,
|
|
705
|
+
method: "GET"
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
var bindCexApi = ({ cex, api_key, api_secret }) => {
|
|
709
|
+
return request_default({
|
|
710
|
+
url: `/cex/subscribe`,
|
|
711
|
+
method: "POST",
|
|
712
|
+
data: { cex, api_key, api_secret }
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
var unBindApi = ({ type }) => {
|
|
716
|
+
return request_default({
|
|
717
|
+
url: `/unbind`,
|
|
718
|
+
method: "POST",
|
|
719
|
+
data: { type }
|
|
720
|
+
});
|
|
721
|
+
};
|
|
722
|
+
var unBindWalletApi = ({ address }) => {
|
|
723
|
+
return request_default({
|
|
724
|
+
url: `/wallet/unbind`,
|
|
725
|
+
method: "POST",
|
|
726
|
+
data: { address }
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
var verifyPohApi = ({
|
|
730
|
+
taskId,
|
|
731
|
+
schemaId,
|
|
732
|
+
publicFields,
|
|
733
|
+
allocatorAddress,
|
|
734
|
+
publicFieldsHash,
|
|
735
|
+
allocatorSignature,
|
|
736
|
+
uHash,
|
|
737
|
+
validatorAddress,
|
|
738
|
+
validatorSignature
|
|
739
|
+
}) => {
|
|
740
|
+
return request_default({
|
|
741
|
+
url: `/poh/zkpass`,
|
|
742
|
+
method: "POST",
|
|
743
|
+
data: {
|
|
744
|
+
taskId,
|
|
745
|
+
schemaId,
|
|
746
|
+
publicFields,
|
|
747
|
+
allocatorAddress,
|
|
748
|
+
publicFieldsHash,
|
|
749
|
+
allocatorSignature,
|
|
750
|
+
uHash,
|
|
751
|
+
validatorAddress,
|
|
752
|
+
validatorSignature
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
};
|
|
676
756
|
|
|
677
757
|
// src/hooks/eventManager.ts
|
|
678
758
|
var EventManager = class {
|
|
@@ -754,7 +834,7 @@ function useUserInfo() {
|
|
|
754
834
|
};
|
|
755
835
|
const loginByMethod = (method) => {
|
|
756
836
|
const link = `${endpoints.back}auth/${method}?appid=${appid}&provider=${method}&redirect=${encodeURIComponent(endpoints.login + "login/" + method)}&authorization=${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
757
|
-
|
|
837
|
+
matchlog_default.log("link", link);
|
|
758
838
|
const authWindow = window.open(
|
|
759
839
|
link,
|
|
760
840
|
// Replace with the actual authorization URL
|
|
@@ -870,24 +950,21 @@ function useUserInfo() {
|
|
|
870
950
|
import { useEffect } from "react";
|
|
871
951
|
function useMatchEvents(handlers) {
|
|
872
952
|
useEffect(() => {
|
|
873
|
-
Object.entries(handlers).forEach(([event,
|
|
874
|
-
if (
|
|
875
|
-
eventManager_default.on(event,
|
|
953
|
+
Object.entries(handlers).forEach(([event, handler2]) => {
|
|
954
|
+
if (handler2) {
|
|
955
|
+
eventManager_default.on(event, handler2);
|
|
876
956
|
}
|
|
877
957
|
});
|
|
878
958
|
return () => {
|
|
879
|
-
Object.entries(handlers).forEach(([event,
|
|
880
|
-
if (
|
|
881
|
-
eventManager_default.off(event,
|
|
959
|
+
Object.entries(handlers).forEach(([event, handler2]) => {
|
|
960
|
+
if (handler2) {
|
|
961
|
+
eventManager_default.off(event, handler2);
|
|
882
962
|
}
|
|
883
963
|
});
|
|
884
964
|
};
|
|
885
965
|
}, [handlers]);
|
|
886
966
|
}
|
|
887
967
|
|
|
888
|
-
// src/hooks/useWallet.tsx
|
|
889
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
890
|
-
|
|
891
968
|
// src/store/useStore.ts
|
|
892
969
|
import { create as create2 } from "zustand";
|
|
893
970
|
var useStore = create2((set) => ({
|
|
@@ -941,7 +1018,7 @@ function useWallet() {
|
|
|
941
1018
|
const signMessage = async (message, type) => {
|
|
942
1019
|
return new Promise(async (resolve, reject) => {
|
|
943
1020
|
const res = await isRecovered();
|
|
944
|
-
|
|
1021
|
+
matchlog_default.log("isRecovered", res);
|
|
945
1022
|
const getSign = async () => {
|
|
946
1023
|
try {
|
|
947
1024
|
const recoverRes = await window.waitMatchUntilWalletMessage("signMessage", {
|
|
@@ -959,7 +1036,7 @@ function useWallet() {
|
|
|
959
1036
|
setRecoveryModal({
|
|
960
1037
|
open: true,
|
|
961
1038
|
success: async () => {
|
|
962
|
-
|
|
1039
|
+
matchlog_default.log("recover Success");
|
|
963
1040
|
await getSign();
|
|
964
1041
|
},
|
|
965
1042
|
close: async () => {
|
|
@@ -979,7 +1056,7 @@ function useWallet() {
|
|
|
979
1056
|
const signTransaction = async (transaction, type) => {
|
|
980
1057
|
return new Promise(async (resolve, reject) => {
|
|
981
1058
|
const res = await isRecovered();
|
|
982
|
-
|
|
1059
|
+
matchlog_default.log("isRecovered", res);
|
|
983
1060
|
const getSign = async () => {
|
|
984
1061
|
try {
|
|
985
1062
|
const recoverRes = await window.waitMatchUntilWalletMessage("signTransaction", {
|
|
@@ -997,7 +1074,7 @@ function useWallet() {
|
|
|
997
1074
|
setRecoveryModal({
|
|
998
1075
|
open: true,
|
|
999
1076
|
success: async () => {
|
|
1000
|
-
|
|
1077
|
+
matchlog_default.log("recover Success");
|
|
1001
1078
|
await getSign();
|
|
1002
1079
|
},
|
|
1003
1080
|
close: async () => {
|
|
@@ -1030,131 +1107,6 @@ function useWallet() {
|
|
|
1030
1107
|
isRecovered
|
|
1031
1108
|
};
|
|
1032
1109
|
}
|
|
1033
|
-
var useWalletInit = ({
|
|
1034
|
-
refreshOverview
|
|
1035
|
-
}) => {
|
|
1036
|
-
const { env } = useLocalStore_default();
|
|
1037
|
-
const getWalletIframe = () => {
|
|
1038
|
-
return document.getElementById("match-wallet");
|
|
1039
|
-
};
|
|
1040
|
-
const [walletInited, setWalletInited] = useState2(false);
|
|
1041
|
-
const { appid, token, overview } = useLocalStore_default();
|
|
1042
|
-
const { initWallet, generateWallet } = useWallet();
|
|
1043
|
-
useEffect2(() => {
|
|
1044
|
-
if (env) {
|
|
1045
|
-
if (!window.matchWalletMessageIdMap) {
|
|
1046
|
-
window.matchWalletMessageIdMap = {};
|
|
1047
|
-
}
|
|
1048
|
-
const config = env_default[env];
|
|
1049
|
-
const endpoints = config.endpoints;
|
|
1050
|
-
const existingIframe = getWalletIframe();
|
|
1051
|
-
if (!existingIframe) {
|
|
1052
|
-
const iframe = document.createElement("iframe");
|
|
1053
|
-
iframe.id = "match-wallet";
|
|
1054
|
-
iframe.src = endpoints.login + "wallet";
|
|
1055
|
-
iframe.style.display = "none";
|
|
1056
|
-
iframe.style.width = "0";
|
|
1057
|
-
iframe.style.height = "0";
|
|
1058
|
-
iframe.onload = () => {
|
|
1059
|
-
setWalletInited(true);
|
|
1060
|
-
};
|
|
1061
|
-
document.body.insertBefore(iframe, document.body.firstChild);
|
|
1062
|
-
window.sendMatchWalletMessage = (method, data) => {
|
|
1063
|
-
const messageId = Date.now().toString() + Math.random().toString().slice(6);
|
|
1064
|
-
const message = {
|
|
1065
|
-
method,
|
|
1066
|
-
data,
|
|
1067
|
-
messageId,
|
|
1068
|
-
source: "matchid"
|
|
1069
|
-
};
|
|
1070
|
-
if (document.getElementById("match-wallet")) {
|
|
1071
|
-
getWalletIframe()?.contentWindow?.postMessage(message, "*");
|
|
1072
|
-
return messageId;
|
|
1073
|
-
}
|
|
1074
|
-
console.error("not found iframe");
|
|
1075
|
-
return false;
|
|
1076
|
-
};
|
|
1077
|
-
window.waitMatchUntilWalletMessage = async (method, data, timeout = 5e3) => {
|
|
1078
|
-
return new Promise((resolve, reject) => {
|
|
1079
|
-
const messageId = window.sendMatchWalletMessage(method, data);
|
|
1080
|
-
if (!messageId) {
|
|
1081
|
-
console.error("Can't find wallet message");
|
|
1082
|
-
reject(new Error("Can't find wallet message"));
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1085
|
-
window.matchWalletMessageIdMap[messageId] = { resolve, reject };
|
|
1086
|
-
window.matchWalletMessageIdMap[messageId].timeout = setTimeout(() => {
|
|
1087
|
-
console.error("Get wallet result timeout", {
|
|
1088
|
-
messageId,
|
|
1089
|
-
method,
|
|
1090
|
-
data
|
|
1091
|
-
});
|
|
1092
|
-
delete window.matchWalletMessageIdMap[messageId];
|
|
1093
|
-
reject(new Error("Get wallet result timeout"));
|
|
1094
|
-
}, timeout);
|
|
1095
|
-
});
|
|
1096
|
-
};
|
|
1097
|
-
} else {
|
|
1098
|
-
if (existingIframe.src !== endpoints.login + "wallet") {
|
|
1099
|
-
existingIframe.src = endpoints.login + "wallet";
|
|
1100
|
-
}
|
|
1101
|
-
setWalletInited(true);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
}, [env]);
|
|
1105
|
-
useEffect2(() => {
|
|
1106
|
-
const messageHandle = async (e) => {
|
|
1107
|
-
const res = e.data;
|
|
1108
|
-
if (res.source != "match-wallet") {
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
const messageId = res.messageId;
|
|
1112
|
-
if (messageId && window.matchWalletMessageIdMap[messageId]) {
|
|
1113
|
-
const { resolve, reject, timeout } = window.matchWalletMessageIdMap[messageId];
|
|
1114
|
-
delete window.matchWalletMessageIdMap[messageId];
|
|
1115
|
-
clearTimeout(timeout);
|
|
1116
|
-
if (res.status == "success") {
|
|
1117
|
-
resolve(res.data);
|
|
1118
|
-
} else {
|
|
1119
|
-
console.error("qwe-waller-error", res);
|
|
1120
|
-
reject(new Error(res.data.message));
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
window.addEventListener("message", messageHandle);
|
|
1125
|
-
return () => {
|
|
1126
|
-
window.removeEventListener("message", messageHandle);
|
|
1127
|
-
};
|
|
1128
|
-
}, []);
|
|
1129
|
-
useEffect2(() => {
|
|
1130
|
-
if (token && overview && overview.did && walletInited) {
|
|
1131
|
-
const did = overview.did.split(":")[2];
|
|
1132
|
-
const newUserInit = async () => {
|
|
1133
|
-
await window.waitMatchUntilWalletMessage(
|
|
1134
|
-
"initCore",
|
|
1135
|
-
{
|
|
1136
|
-
AppId: appid,
|
|
1137
|
-
AppClientId,
|
|
1138
|
-
UserId: did,
|
|
1139
|
-
AccessToken: token,
|
|
1140
|
-
Address: ""
|
|
1141
|
-
}
|
|
1142
|
-
);
|
|
1143
|
-
};
|
|
1144
|
-
if (!overview.address) {
|
|
1145
|
-
newUserInit();
|
|
1146
|
-
} else {
|
|
1147
|
-
initWallet({
|
|
1148
|
-
address: overview.address,
|
|
1149
|
-
did
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
}, [overview, token, walletInited]);
|
|
1154
|
-
return {
|
|
1155
|
-
walletInited
|
|
1156
|
-
};
|
|
1157
|
-
};
|
|
1158
1110
|
|
|
1159
1111
|
// src/components/PasswordModal/index.tsx
|
|
1160
1112
|
import { jsx as jsx24, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
@@ -1166,27 +1118,27 @@ function PasswordModal({
|
|
|
1166
1118
|
}) {
|
|
1167
1119
|
const { refreshOverview } = useUserInfo();
|
|
1168
1120
|
const { isLogin, did } = useUserInfo();
|
|
1169
|
-
const [password, setPassword] =
|
|
1170
|
-
const [rePassword, setRePassword] =
|
|
1171
|
-
const [error, setError] =
|
|
1121
|
+
const [password, setPassword] = useState2("");
|
|
1122
|
+
const [rePassword, setRePassword] = useState2("");
|
|
1123
|
+
const [error, setError] = useState2("");
|
|
1172
1124
|
const { generateWallet } = useWallet();
|
|
1173
|
-
const passwordError =
|
|
1125
|
+
const passwordError = useMemo2(() => {
|
|
1174
1126
|
if (password.length < 6) return "Password must be at least 6 characters";
|
|
1175
1127
|
return "";
|
|
1176
1128
|
}, [password]);
|
|
1177
|
-
const rePasswordError =
|
|
1129
|
+
const rePasswordError = useMemo2(() => {
|
|
1178
1130
|
if (rePassword != password) {
|
|
1179
1131
|
return "The password you entered twice do not match";
|
|
1180
1132
|
}
|
|
1181
1133
|
return "";
|
|
1182
1134
|
}, [rePassword, password]);
|
|
1183
|
-
|
|
1135
|
+
useEffect2(() => {
|
|
1184
1136
|
if (isOpen) {
|
|
1185
1137
|
setPassword("");
|
|
1186
1138
|
setRePassword("");
|
|
1187
1139
|
}
|
|
1188
1140
|
}, [isOpen]);
|
|
1189
|
-
const [isSubmitting, setIsSubmitting] =
|
|
1141
|
+
const [isSubmitting, setIsSubmitting] = useState2(false);
|
|
1190
1142
|
const onContinue = async () => {
|
|
1191
1143
|
if (isSubmitting) return;
|
|
1192
1144
|
try {
|
|
@@ -1246,7 +1198,7 @@ function PasswordModal({
|
|
|
1246
1198
|
}
|
|
1247
1199
|
|
|
1248
1200
|
// src/components/RecoveryModal/index.tsx
|
|
1249
|
-
import { useEffect as
|
|
1201
|
+
import { useEffect as useEffect3, useMemo as useMemo3, useState as useState3 } from "react";
|
|
1250
1202
|
import { jsx as jsx25, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1251
1203
|
function RecoveryModal({
|
|
1252
1204
|
title,
|
|
@@ -1256,19 +1208,19 @@ function RecoveryModal({
|
|
|
1256
1208
|
}) {
|
|
1257
1209
|
const { refreshOverview } = useUserInfo();
|
|
1258
1210
|
const { isLogin } = useUserInfo();
|
|
1259
|
-
const [password, setPassword] =
|
|
1211
|
+
const [password, setPassword] = useState3("");
|
|
1260
1212
|
const { recoveryWallet } = useWallet();
|
|
1261
|
-
const [error, setError] =
|
|
1262
|
-
const passwordError =
|
|
1213
|
+
const [error, setError] = useState3("");
|
|
1214
|
+
const passwordError = useMemo3(() => {
|
|
1263
1215
|
if (password.length < 6) return "Password must be at least 6 characters";
|
|
1264
1216
|
return "";
|
|
1265
1217
|
}, [password]);
|
|
1266
|
-
|
|
1218
|
+
useEffect3(() => {
|
|
1267
1219
|
if (isOpen) {
|
|
1268
1220
|
setPassword("");
|
|
1269
1221
|
}
|
|
1270
1222
|
}, [isOpen]);
|
|
1271
|
-
const [isSubmitting, setIsSubmitting] =
|
|
1223
|
+
const [isSubmitting, setIsSubmitting] = useState3(false);
|
|
1272
1224
|
const onContinue = async () => {
|
|
1273
1225
|
if (isSubmitting) return;
|
|
1274
1226
|
try {
|
|
@@ -1342,8 +1294,146 @@ var Providers = ({ children }) => {
|
|
|
1342
1294
|
};
|
|
1343
1295
|
var context_default = Providers;
|
|
1344
1296
|
|
|
1297
|
+
// src/hooks/useWalletInit.ts
|
|
1298
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
1299
|
+
var AppClientId2 = "react-sdk-" + getVersion();
|
|
1300
|
+
function useWalletInit({
|
|
1301
|
+
refreshOverview
|
|
1302
|
+
}) {
|
|
1303
|
+
const { env } = useLocalStore_default();
|
|
1304
|
+
const getWalletIframe = () => {
|
|
1305
|
+
return document.getElementById("match-wallet");
|
|
1306
|
+
};
|
|
1307
|
+
const [walletInited, setWalletInited] = useState4(false);
|
|
1308
|
+
const { appid, token, overview } = useLocalStore_default();
|
|
1309
|
+
const { initWallet, generateWallet } = useWallet();
|
|
1310
|
+
useEffect4(() => {
|
|
1311
|
+
if (env) {
|
|
1312
|
+
if (!window.matchWalletMessageIdMap) {
|
|
1313
|
+
window.matchWalletMessageIdMap = {};
|
|
1314
|
+
}
|
|
1315
|
+
const config = env_default[env];
|
|
1316
|
+
const endpoints = config.endpoints;
|
|
1317
|
+
const existingIframe = getWalletIframe();
|
|
1318
|
+
if (!existingIframe) {
|
|
1319
|
+
const iframe = document.createElement("iframe");
|
|
1320
|
+
iframe.id = "match-wallet";
|
|
1321
|
+
iframe.src = endpoints.login + "wallet";
|
|
1322
|
+
iframe.style.display = "none";
|
|
1323
|
+
iframe.style.width = "0";
|
|
1324
|
+
iframe.style.height = "0";
|
|
1325
|
+
document.body.insertBefore(iframe, document.body.firstChild);
|
|
1326
|
+
window.sendMatchWalletMessage = (method, data) => {
|
|
1327
|
+
const messageId = Date.now().toString() + Math.random().toString().slice(6);
|
|
1328
|
+
const message = {
|
|
1329
|
+
method,
|
|
1330
|
+
data,
|
|
1331
|
+
messageId,
|
|
1332
|
+
source: "matchid"
|
|
1333
|
+
};
|
|
1334
|
+
if (document.getElementById("match-wallet")) {
|
|
1335
|
+
matchlog_default.log("matchid.sdk.sendMatchWalletMessage", message, endpoints.login);
|
|
1336
|
+
getWalletIframe()?.contentWindow?.postMessage(message, endpoints.login);
|
|
1337
|
+
return messageId;
|
|
1338
|
+
}
|
|
1339
|
+
console.error("not found iframe");
|
|
1340
|
+
return false;
|
|
1341
|
+
};
|
|
1342
|
+
window.waitMatchUntilWalletMessage = async (method, data, timeout = 1e4) => {
|
|
1343
|
+
return new Promise((resolve, reject) => {
|
|
1344
|
+
const messageId = window.sendMatchWalletMessage(method, data);
|
|
1345
|
+
if (!messageId) {
|
|
1346
|
+
console.error("Can't find wallet message");
|
|
1347
|
+
reject(new Error("Can't find wallet message"));
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
window.matchWalletMessageIdMap[messageId] = { resolve, reject };
|
|
1351
|
+
window.matchWalletMessageIdMap[messageId].timeout = setTimeout(() => {
|
|
1352
|
+
console.error("Get wallet result timeout", {
|
|
1353
|
+
messageId,
|
|
1354
|
+
method,
|
|
1355
|
+
data
|
|
1356
|
+
});
|
|
1357
|
+
delete window.matchWalletMessageIdMap[messageId];
|
|
1358
|
+
reject(new Error("Get wallet result timeout"));
|
|
1359
|
+
}, timeout);
|
|
1360
|
+
});
|
|
1361
|
+
};
|
|
1362
|
+
} else {
|
|
1363
|
+
if (existingIframe.src !== endpoints.login + "wallet") {
|
|
1364
|
+
setWalletInited(false);
|
|
1365
|
+
existingIframe.src = endpoints.login + "wallet";
|
|
1366
|
+
} else {
|
|
1367
|
+
setWalletInited(true);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}, [env]);
|
|
1372
|
+
useEffect4(() => {
|
|
1373
|
+
const messageHandle = async (e) => {
|
|
1374
|
+
if (e.origin !== env_default[env].endpoints.login.substring(0, env_default[env].endpoints.login.length - 1)) {
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
const res = e.data;
|
|
1378
|
+
if (res.source != "match-wallet") {
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
matchlog_default.log("sdk.wallet.receive", e);
|
|
1382
|
+
const messageId = res.messageId;
|
|
1383
|
+
if (messageId == "init") {
|
|
1384
|
+
matchlog_default.log("wallet init");
|
|
1385
|
+
setWalletInited(true);
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (messageId && window.matchWalletMessageIdMap[messageId]) {
|
|
1389
|
+
const { resolve, reject, timeout } = window.matchWalletMessageIdMap[messageId];
|
|
1390
|
+
delete window.matchWalletMessageIdMap[messageId];
|
|
1391
|
+
clearTimeout(timeout);
|
|
1392
|
+
if (res.status == "success") {
|
|
1393
|
+
resolve(res.data);
|
|
1394
|
+
} else {
|
|
1395
|
+
console.error("qwe-waller-error", res);
|
|
1396
|
+
reject(new Error(res.data.message));
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
window.addEventListener("message", messageHandle);
|
|
1401
|
+
return () => {
|
|
1402
|
+
window.removeEventListener("message", messageHandle);
|
|
1403
|
+
};
|
|
1404
|
+
}, []);
|
|
1405
|
+
useEffect4(() => {
|
|
1406
|
+
if (token && overview && overview.did && walletInited) {
|
|
1407
|
+
const did = overview.did.split(":")[2];
|
|
1408
|
+
const newUserInit = async () => {
|
|
1409
|
+
await window.waitMatchUntilWalletMessage(
|
|
1410
|
+
"initCore",
|
|
1411
|
+
{
|
|
1412
|
+
AppId: appid,
|
|
1413
|
+
AppClientId: AppClientId2,
|
|
1414
|
+
UserId: did,
|
|
1415
|
+
AccessToken: token,
|
|
1416
|
+
Address: ""
|
|
1417
|
+
}
|
|
1418
|
+
);
|
|
1419
|
+
};
|
|
1420
|
+
if (!overview.address) {
|
|
1421
|
+
newUserInit();
|
|
1422
|
+
} else {
|
|
1423
|
+
initWallet({
|
|
1424
|
+
address: overview.address,
|
|
1425
|
+
did
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}, [overview, token, walletInited]);
|
|
1430
|
+
return {
|
|
1431
|
+
walletInited
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1345
1435
|
// src/hooks/useInit.tsx
|
|
1346
|
-
import { useEffect as useEffect5, useRef
|
|
1436
|
+
import { useEffect as useEffect5, useRef } from "react";
|
|
1347
1437
|
function useInit({
|
|
1348
1438
|
theme,
|
|
1349
1439
|
appid,
|
|
@@ -1359,7 +1449,7 @@ function useInit({
|
|
|
1359
1449
|
setOverview,
|
|
1360
1450
|
setTheme
|
|
1361
1451
|
} = useLocalStore_default();
|
|
1362
|
-
const overviewLoadingRef =
|
|
1452
|
+
const overviewLoadingRef = useRef(false);
|
|
1363
1453
|
const searchParams = new URLSearchParams(window.location.search);
|
|
1364
1454
|
const matchToken = searchParams.get("matchToken");
|
|
1365
1455
|
const config = env_default[env];
|
|
@@ -1405,7 +1495,7 @@ function useInit({
|
|
|
1405
1495
|
};
|
|
1406
1496
|
}, []);
|
|
1407
1497
|
const loadOverview = async () => {
|
|
1408
|
-
|
|
1498
|
+
matchlog_default.log("loadOverview");
|
|
1409
1499
|
if (overviewLoadingRef.current) {
|
|
1410
1500
|
return;
|
|
1411
1501
|
}
|
|
@@ -1451,7 +1541,9 @@ function useInit({
|
|
|
1451
1541
|
}
|
|
1452
1542
|
|
|
1453
1543
|
// src/MatchContext.tsx
|
|
1544
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
1454
1545
|
import { jsx as jsx28 } from "react/jsx-runtime";
|
|
1546
|
+
var queryClient = new QueryClient();
|
|
1455
1547
|
var MatchContext = createContext(void 0);
|
|
1456
1548
|
var MatchProvider = ({ children, appid, env = "main", events, theme = "light" }) => {
|
|
1457
1549
|
const { loadOverview, login, config, endpoints } = useInit({
|
|
@@ -1463,7 +1555,7 @@ var MatchProvider = ({ children, appid, env = "main", events, theme = "light" })
|
|
|
1463
1555
|
useWalletInit({
|
|
1464
1556
|
refreshOverview: loadOverview
|
|
1465
1557
|
});
|
|
1466
|
-
return /* @__PURE__ */ jsx28(
|
|
1558
|
+
return /* @__PURE__ */ jsx28(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx28(
|
|
1467
1559
|
MatchContext.Provider,
|
|
1468
1560
|
{
|
|
1469
1561
|
value: {
|
|
@@ -1476,7 +1568,7 @@ var MatchProvider = ({ children, appid, env = "main", events, theme = "light" })
|
|
|
1476
1568
|
},
|
|
1477
1569
|
children: /* @__PURE__ */ jsx28(context_default, { children })
|
|
1478
1570
|
}
|
|
1479
|
-
);
|
|
1571
|
+
) });
|
|
1480
1572
|
};
|
|
1481
1573
|
var useMatch = () => {
|
|
1482
1574
|
const context = useContext(MatchContext);
|
|
@@ -1507,7 +1599,7 @@ __export(components_exports, {
|
|
|
1507
1599
|
import { useEffect as useEffect9, useState as useState8 } from "react";
|
|
1508
1600
|
|
|
1509
1601
|
// src/components/EmailModal/StepEmail.tsx
|
|
1510
|
-
import { useEffect as useEffect7, useMemo as
|
|
1602
|
+
import { useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
|
|
1511
1603
|
import { jsx as jsx29, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
1512
1604
|
function StepEmail(props) {
|
|
1513
1605
|
const [emailVal, setEmailVal] = useState6("");
|
|
@@ -1516,7 +1608,7 @@ function StepEmail(props) {
|
|
|
1516
1608
|
setEmailVal(props.email);
|
|
1517
1609
|
}
|
|
1518
1610
|
}, []);
|
|
1519
|
-
const canContinue =
|
|
1611
|
+
const canContinue = useMemo4(() => {
|
|
1520
1612
|
return isValidEmail(emailVal);
|
|
1521
1613
|
}, [emailVal]);
|
|
1522
1614
|
const onContinue = async () => {
|
|
@@ -1538,7 +1630,7 @@ function StepEmail(props) {
|
|
|
1538
1630
|
}
|
|
1539
1631
|
|
|
1540
1632
|
// src/components/EmailModal/StepVerify.tsx
|
|
1541
|
-
import { useEffect as useEffect8, useMemo as
|
|
1633
|
+
import { useEffect as useEffect8, useMemo as useMemo5, useRef as useRef3, useState as useState7 } from "react";
|
|
1542
1634
|
|
|
1543
1635
|
// src/config/index.tsx
|
|
1544
1636
|
var EMAIL_INTERVAL = 60;
|
|
@@ -1552,11 +1644,11 @@ function StepVerify(props) {
|
|
|
1552
1644
|
const [code, setCode] = useState7("");
|
|
1553
1645
|
const [sending, setSending] = useState7(false);
|
|
1554
1646
|
const [submitting, setSubmitting] = useState7(false);
|
|
1555
|
-
const sendTimeRef =
|
|
1647
|
+
const sendTimeRef = useRef3(0);
|
|
1556
1648
|
const [sendBtnText, setSendBtnText] = useState7("Send");
|
|
1557
1649
|
const intervalTime = EMAIL_INTERVAL;
|
|
1558
1650
|
const codeLength = EMAIL_CODE_LENGTH;
|
|
1559
|
-
const intervalRef =
|
|
1651
|
+
const intervalRef = useRef3(null);
|
|
1560
1652
|
const onSend = async () => {
|
|
1561
1653
|
if (sendTimeRef.current > 0) {
|
|
1562
1654
|
return;
|
|
@@ -1590,7 +1682,7 @@ function StepVerify(props) {
|
|
|
1590
1682
|
}
|
|
1591
1683
|
};
|
|
1592
1684
|
}, []);
|
|
1593
|
-
const canContinue =
|
|
1685
|
+
const canContinue = useMemo5(() => {
|
|
1594
1686
|
return code.length === codeLength;
|
|
1595
1687
|
}, [code]);
|
|
1596
1688
|
const onContinue = async () => {
|
|
@@ -1686,7 +1778,7 @@ function EmailModal({
|
|
|
1686
1778
|
}
|
|
1687
1779
|
|
|
1688
1780
|
// src/components/LoginBox/index.tsx
|
|
1689
|
-
import { useMemo as
|
|
1781
|
+
import { useMemo as useMemo6, useState as useState9 } from "react";
|
|
1690
1782
|
import { Fragment as Fragment3, jsx as jsx32, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
1691
1783
|
function LoginBox({
|
|
1692
1784
|
methods,
|
|
@@ -1701,7 +1793,7 @@ function LoginBox({
|
|
|
1701
1793
|
"telegram",
|
|
1702
1794
|
"X"
|
|
1703
1795
|
];
|
|
1704
|
-
const methodList =
|
|
1796
|
+
const methodList = useMemo6(() => {
|
|
1705
1797
|
return methods || defaultMethods;
|
|
1706
1798
|
}, [methods]);
|
|
1707
1799
|
const LoginItem = ({
|
|
@@ -1840,7 +1932,7 @@ function LoginButton({
|
|
|
1840
1932
|
}
|
|
1841
1933
|
|
|
1842
1934
|
// src/components/UsernameModal/index.tsx
|
|
1843
|
-
import { useEffect as useEffect10, useMemo as
|
|
1935
|
+
import { useEffect as useEffect10, useMemo as useMemo7, useState as useState11 } from "react";
|
|
1844
1936
|
|
|
1845
1937
|
// src/assets/icon/InfoRoundIcon.tsx
|
|
1846
1938
|
import { jsx as jsx36, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
@@ -1890,10 +1982,10 @@ function UsernameModal({
|
|
|
1890
1982
|
setError("");
|
|
1891
1983
|
}
|
|
1892
1984
|
}, [isOpen]);
|
|
1893
|
-
const isValid =
|
|
1985
|
+
const isValid = useMemo7(() => {
|
|
1894
1986
|
return isValidUsername(val);
|
|
1895
1987
|
}, [val]);
|
|
1896
|
-
const isLength =
|
|
1988
|
+
const isLength = useMemo7(() => {
|
|
1897
1989
|
return val.length >= 2 && val.length <= 32;
|
|
1898
1990
|
}, [val]);
|
|
1899
1991
|
const isSafe = isValid && isLength;
|
|
@@ -1947,7 +2039,70 @@ function UsernameModal({
|
|
|
1947
2039
|
}, onClick: props.onClose, size: "lg", block: true, children: "Next Time" })
|
|
1948
2040
|
] }) });
|
|
1949
2041
|
}
|
|
2042
|
+
|
|
2043
|
+
// src/hooks/api/index.ts
|
|
2044
|
+
var api_exports = {};
|
|
2045
|
+
__export(api_exports, {
|
|
2046
|
+
bind: () => bind_exports,
|
|
2047
|
+
poh: () => poh_exports
|
|
2048
|
+
});
|
|
2049
|
+
|
|
2050
|
+
// src/hooks/api/bind.ts
|
|
2051
|
+
var bind_exports = {};
|
|
2052
|
+
__export(bind_exports, {
|
|
2053
|
+
bindCexApi: () => bindCexApi,
|
|
2054
|
+
unBindApi: () => unBindApi,
|
|
2055
|
+
unBindWalletApi: () => unBindWalletApi,
|
|
2056
|
+
useBindInfo: () => useBindInfo,
|
|
2057
|
+
useBindList: () => useBindList
|
|
2058
|
+
});
|
|
2059
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2060
|
+
function useBindList(options) {
|
|
2061
|
+
const { isLogin } = useUserInfo();
|
|
2062
|
+
return useQuery({
|
|
2063
|
+
queryKey: ["bindList"],
|
|
2064
|
+
enabled: isLogin,
|
|
2065
|
+
queryFn: async () => {
|
|
2066
|
+
let res = await getBindListApi();
|
|
2067
|
+
return res.data;
|
|
2068
|
+
},
|
|
2069
|
+
...options
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
function useBindInfo(options) {
|
|
2073
|
+
const { isLogin } = useUserInfo();
|
|
2074
|
+
return useQuery({
|
|
2075
|
+
queryKey: ["bindInfo"],
|
|
2076
|
+
enabled: isLogin,
|
|
2077
|
+
queryFn: async () => {
|
|
2078
|
+
let res = await getBindInfoApi();
|
|
2079
|
+
return res.data;
|
|
2080
|
+
},
|
|
2081
|
+
...options
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
// src/hooks/api/poh.ts
|
|
2086
|
+
var poh_exports = {};
|
|
2087
|
+
__export(poh_exports, {
|
|
2088
|
+
usePohList: () => usePohList,
|
|
2089
|
+
verifyPohApi: () => verifyPohApi
|
|
2090
|
+
});
|
|
2091
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
2092
|
+
function usePohList(options) {
|
|
2093
|
+
const { isLogin } = useUserInfo();
|
|
2094
|
+
return useQuery2({
|
|
2095
|
+
queryKey: ["pohList"],
|
|
2096
|
+
enabled: isLogin,
|
|
2097
|
+
queryFn: async () => {
|
|
2098
|
+
let res = await getPohListApi();
|
|
2099
|
+
return res.data;
|
|
2100
|
+
},
|
|
2101
|
+
...options
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
1950
2104
|
export {
|
|
2105
|
+
api_exports as Api,
|
|
1951
2106
|
components_exports as Components,
|
|
1952
2107
|
hooks_exports as Hooks,
|
|
1953
2108
|
MatchProvider,
|