@matchain/matchid-sdk-react 0.1.12 → 0.1.13
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 +21 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +90 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -89
- package/dist/index.mjs.map +1 -1
- package/example/src/App.tsx +16 -12
- package/example/src/pages/User.tsx +13 -0
- package/example/src/pages/Wallet.tsx +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -486,7 +486,6 @@ var persistedState = persist(
|
|
|
486
486
|
appid: "",
|
|
487
487
|
token: "",
|
|
488
488
|
did: "",
|
|
489
|
-
env: "main",
|
|
490
489
|
mid: "",
|
|
491
490
|
overview: null,
|
|
492
491
|
theme: "light",
|
|
@@ -496,13 +495,17 @@ var persistedState = persist(
|
|
|
496
495
|
did: overview.did,
|
|
497
496
|
mid: overview.mid
|
|
498
497
|
}),
|
|
499
|
-
|
|
498
|
+
endpoints: {
|
|
499
|
+
back: "https://api.matchid.ai/",
|
|
500
|
+
auth: "https://auth.matchid.ai/"
|
|
501
|
+
},
|
|
500
502
|
setDid: (did) => set({ did }),
|
|
501
503
|
setToken: (token) => set({ token }),
|
|
502
504
|
setAppid: (appid) => set({ appid }),
|
|
503
505
|
setMid: (mid) => set({ mid }),
|
|
504
506
|
logout: () => set({ token: "", did: "", mid: "", address: "", overview: null }),
|
|
505
507
|
setTheme: (theme) => set({ theme }),
|
|
508
|
+
setEndpoints: (endpoints) => set({ endpoints }),
|
|
506
509
|
address: "",
|
|
507
510
|
setAddress: (address) => set({ address })
|
|
508
511
|
}),
|
|
@@ -518,57 +521,28 @@ import { useMemo } from "react";
|
|
|
518
521
|
// src/api/request.ts
|
|
519
522
|
import axios from "axios";
|
|
520
523
|
|
|
521
|
-
// src/config/env/main.ts
|
|
522
|
-
var main_default = {
|
|
523
|
-
endpoints: {
|
|
524
|
-
back: "https://api.matchid.ai/api/v1/",
|
|
525
|
-
login: "https://auth.matchid.ai/"
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
// src/config/env/dev.ts
|
|
530
|
-
var dev_default = {
|
|
531
|
-
endpoints: {
|
|
532
|
-
back: "https://mid-test-api.matchain.io/mid/api/v1/",
|
|
533
|
-
login: "https://calm-hare-roughly.ngrok-free.app/"
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
// src/config/env/test.ts
|
|
538
|
-
var test_default = {
|
|
539
|
-
endpoints: {
|
|
540
|
-
back: "https://mid-test-api.matchain.io/mid/api/v1/",
|
|
541
|
-
login: "https://mid-sso-test.vercel.app/"
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
|
|
545
524
|
// src/config/env/index.ts
|
|
546
525
|
var env_default = {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
526
|
+
endpoints: {
|
|
527
|
+
back: "https://api.matchid.ai/",
|
|
528
|
+
auth: "https://auth.matchid.ai/"
|
|
529
|
+
}
|
|
550
530
|
};
|
|
551
531
|
|
|
552
532
|
// src/store/index.ts
|
|
553
|
-
var
|
|
533
|
+
var getEndpoints = () => {
|
|
554
534
|
try {
|
|
555
535
|
const store = localStore.getState();
|
|
556
|
-
const env = store?.
|
|
536
|
+
const env = store?.endpoints;
|
|
557
537
|
if (env) {
|
|
558
538
|
return env;
|
|
559
539
|
} else {
|
|
560
|
-
return
|
|
540
|
+
return env_default.endpoints;
|
|
561
541
|
}
|
|
562
542
|
} catch (e) {
|
|
563
|
-
return
|
|
543
|
+
return env_default.endpoints;
|
|
564
544
|
}
|
|
565
545
|
};
|
|
566
|
-
var getEnvConfig = () => {
|
|
567
|
-
return env_default[getEnv()];
|
|
568
|
-
};
|
|
569
|
-
var getEndpoints = () => {
|
|
570
|
-
return getEnvConfig().endpoints;
|
|
571
|
-
};
|
|
572
546
|
var getAppid = () => {
|
|
573
547
|
try {
|
|
574
548
|
const store = localStore.getState();
|
|
@@ -656,72 +630,72 @@ var request_default = request;
|
|
|
656
630
|
// src/api/index.ts
|
|
657
631
|
var getEmailCodeApi = (email) => {
|
|
658
632
|
return request_default({
|
|
659
|
-
url: `/email/code`,
|
|
633
|
+
url: `/api/v1/email/code`,
|
|
660
634
|
method: "POST",
|
|
661
635
|
data: { email }
|
|
662
636
|
});
|
|
663
637
|
};
|
|
664
638
|
var verifyEmailCodeApi = ({ email, verification_key, verification_code }) => {
|
|
665
639
|
return request_default({
|
|
666
|
-
url: `/user/email/login`,
|
|
640
|
+
url: `/api/v1/user/email/login`,
|
|
667
641
|
method: "POST",
|
|
668
642
|
data: { email, verification_key, verification_code }
|
|
669
643
|
});
|
|
670
644
|
};
|
|
671
645
|
var getOverviewInfoApi = () => {
|
|
672
646
|
return request_default({
|
|
673
|
-
url: `/user/overview`,
|
|
647
|
+
url: `/api/v1/user/overview`,
|
|
674
648
|
method: "GET"
|
|
675
649
|
});
|
|
676
650
|
};
|
|
677
651
|
var toLogoutApi = () => {
|
|
678
652
|
return request_default({
|
|
679
|
-
url: `/user/logout`,
|
|
653
|
+
url: `/api/v1/user/logout`,
|
|
680
654
|
method: "POST"
|
|
681
655
|
});
|
|
682
656
|
};
|
|
683
657
|
var setUserNameApi = (data) => {
|
|
684
658
|
return request_default({
|
|
685
|
-
url: `/user/name`,
|
|
659
|
+
url: `/api/v1/user/name`,
|
|
686
660
|
method: "POSt",
|
|
687
661
|
data
|
|
688
662
|
});
|
|
689
663
|
};
|
|
690
664
|
var getBindListApi = () => {
|
|
691
665
|
return request_default({
|
|
692
|
-
url: `/bind/list`,
|
|
666
|
+
url: `/api/v1/bind/list`,
|
|
693
667
|
method: "GET"
|
|
694
668
|
});
|
|
695
669
|
};
|
|
696
670
|
var getPohListApi = () => {
|
|
697
671
|
return request_default({
|
|
698
|
-
url: `/poh/list`,
|
|
672
|
+
url: `/api/v1/poh/list`,
|
|
699
673
|
method: "GET"
|
|
700
674
|
});
|
|
701
675
|
};
|
|
702
676
|
var getBindInfoApi = () => {
|
|
703
677
|
return request_default({
|
|
704
|
-
url: `/bind`,
|
|
678
|
+
url: `/api/v1/bind`,
|
|
705
679
|
method: "GET"
|
|
706
680
|
});
|
|
707
681
|
};
|
|
708
682
|
var bindCexApi = ({ cex, api_key, api_secret }) => {
|
|
709
683
|
return request_default({
|
|
710
|
-
url: `/cex/subscribe`,
|
|
684
|
+
url: `/api/v1/cex/subscribe`,
|
|
711
685
|
method: "POST",
|
|
712
686
|
data: { cex, api_key, api_secret }
|
|
713
687
|
});
|
|
714
688
|
};
|
|
715
689
|
var unBindApi = ({ type }) => {
|
|
716
690
|
return request_default({
|
|
717
|
-
url: `/unbind`,
|
|
691
|
+
url: `/api/v1/unbind`,
|
|
718
692
|
method: "POST",
|
|
719
693
|
data: { type }
|
|
720
694
|
});
|
|
721
695
|
};
|
|
722
696
|
var unBindWalletApi = ({ address }) => {
|
|
723
697
|
return request_default({
|
|
724
|
-
url: `/wallet/unbind`,
|
|
698
|
+
url: `/api/v1/wallet/unbind`,
|
|
725
699
|
method: "POST",
|
|
726
700
|
data: { address }
|
|
727
701
|
});
|
|
@@ -738,7 +712,7 @@ var verifyPohApi = ({
|
|
|
738
712
|
validatorSignature
|
|
739
713
|
}) => {
|
|
740
714
|
return request_default({
|
|
741
|
-
url: `/poh/zkpass`,
|
|
715
|
+
url: `/api/v1/poh/zkpass`,
|
|
742
716
|
method: "POST",
|
|
743
717
|
data: {
|
|
744
718
|
taskId,
|
|
@@ -753,6 +727,25 @@ var verifyPohApi = ({
|
|
|
753
727
|
}
|
|
754
728
|
});
|
|
755
729
|
};
|
|
730
|
+
var chooseIdentityApi = ({ identity }) => {
|
|
731
|
+
return request_default({
|
|
732
|
+
url: `/api/v1/user/choose/identity`,
|
|
733
|
+
method: "POST",
|
|
734
|
+
data: { identity }
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
var mintPassportNftApi = () => {
|
|
738
|
+
return request_default({
|
|
739
|
+
url: `/api/v1/mint/passport/nft`,
|
|
740
|
+
method: "POST"
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
var getAuthInfoApi = () => {
|
|
744
|
+
return request_default({
|
|
745
|
+
url: `/api/v1/user/auth`,
|
|
746
|
+
method: "GET"
|
|
747
|
+
});
|
|
748
|
+
};
|
|
756
749
|
|
|
757
750
|
// src/hooks/eventManager.ts
|
|
758
751
|
var EventManager = class {
|
|
@@ -811,16 +804,13 @@ function useUserInfo() {
|
|
|
811
804
|
token,
|
|
812
805
|
mid,
|
|
813
806
|
did,
|
|
814
|
-
env,
|
|
815
807
|
logout: logoutStore,
|
|
816
808
|
setOverview,
|
|
817
809
|
overview,
|
|
818
|
-
address
|
|
810
|
+
address,
|
|
811
|
+
endpoints
|
|
819
812
|
} = useLocalStore_default();
|
|
820
813
|
const { events, login } = useMatch();
|
|
821
|
-
const endpoints = useMemo(() => {
|
|
822
|
-
return getEndpoints();
|
|
823
|
-
}, [env]);
|
|
824
814
|
const isLogin = useMemo(() => !!token, [token]);
|
|
825
815
|
const logout = async () => {
|
|
826
816
|
try {
|
|
@@ -833,7 +823,7 @@ function useUserInfo() {
|
|
|
833
823
|
eventManager_default.emit("onLogout");
|
|
834
824
|
};
|
|
835
825
|
const loginByMethod = (method) => {
|
|
836
|
-
const link = `${endpoints.back}auth/${method}?appid=${appid}&provider=${method}&redirect=${encodeURIComponent(endpoints.
|
|
826
|
+
const link = `${endpoints.back}auth/${method}?appid=${appid}&provider=${method}&redirect=${encodeURIComponent(endpoints.auth + "login/" + method)}&authorization=${(/* @__PURE__ */ new Date()).getTime()}`;
|
|
837
827
|
matchlog_default.log("link", link);
|
|
838
828
|
const authWindow = window.open(
|
|
839
829
|
link,
|
|
@@ -884,7 +874,7 @@ function useUserInfo() {
|
|
|
884
874
|
};
|
|
885
875
|
const loginByWallet = () => {
|
|
886
876
|
const authWindow = window.open(
|
|
887
|
-
`${endpoints.
|
|
877
|
+
`${endpoints.auth}login/wallet?appid=${appid}`,
|
|
888
878
|
// Replace with the actual authorization URL
|
|
889
879
|
"_blank"
|
|
890
880
|
// 'width=800,height=600'
|
|
@@ -892,7 +882,7 @@ function useUserInfo() {
|
|
|
892
882
|
};
|
|
893
883
|
const loginByTelegram = () => {
|
|
894
884
|
const authWindow = window.open(
|
|
895
|
-
`${endpoints.
|
|
885
|
+
`${endpoints.auth}login/telegram?appid=${appid}`,
|
|
896
886
|
// Replace with the actual authorization URL
|
|
897
887
|
"authWindow",
|
|
898
888
|
"width=800,height=600"
|
|
@@ -909,7 +899,7 @@ function useUserInfo() {
|
|
|
909
899
|
throw new Error("You must login first");
|
|
910
900
|
}
|
|
911
901
|
const authWindow = window.open(
|
|
912
|
-
`${endpoints.
|
|
902
|
+
`${endpoints.auth}bind/wallet?appid=${appid}&st=` + encodeURIComponent(encodeBase64(token)),
|
|
913
903
|
// Replace with the actual authorization URL
|
|
914
904
|
"_blank"
|
|
915
905
|
);
|
|
@@ -919,12 +909,19 @@ function useUserInfo() {
|
|
|
919
909
|
throw new Error("You must login first");
|
|
920
910
|
}
|
|
921
911
|
const authWindow = window.open(
|
|
922
|
-
`${endpoints.
|
|
912
|
+
`${endpoints.auth}bind/telegram?appid=${appid}&st=` + encodeURIComponent(encodeBase64(token)),
|
|
923
913
|
// Replace with the actual authorization URL
|
|
924
914
|
"authWindow",
|
|
925
915
|
"width=800,height=600"
|
|
926
916
|
);
|
|
927
917
|
};
|
|
918
|
+
const auth = async () => {
|
|
919
|
+
const res = await getAuthInfoApi();
|
|
920
|
+
if (isSuccess(res)) {
|
|
921
|
+
return res.data;
|
|
922
|
+
}
|
|
923
|
+
throw new Error(res.message);
|
|
924
|
+
};
|
|
928
925
|
return {
|
|
929
926
|
loginByTelegram,
|
|
930
927
|
loginByTwitter,
|
|
@@ -942,7 +939,8 @@ function useUserInfo() {
|
|
|
942
939
|
overview,
|
|
943
940
|
bindWallet,
|
|
944
941
|
bindTelegram,
|
|
945
|
-
username: overview?.username || ""
|
|
942
|
+
username: overview?.username || "",
|
|
943
|
+
auth
|
|
946
944
|
};
|
|
947
945
|
}
|
|
948
946
|
|
|
@@ -1303,7 +1301,7 @@ var AppClientId2 = "react-sdk-" + getVersion();
|
|
|
1303
1301
|
function useWalletInit({
|
|
1304
1302
|
refreshOverview
|
|
1305
1303
|
}) {
|
|
1306
|
-
const {
|
|
1304
|
+
const { endpoints } = useLocalStore_default();
|
|
1307
1305
|
const getWalletIframe = () => {
|
|
1308
1306
|
return document.getElementById("match-wallet");
|
|
1309
1307
|
};
|
|
@@ -1311,17 +1309,15 @@ function useWalletInit({
|
|
|
1311
1309
|
const { appid, token, overview } = useLocalStore_default();
|
|
1312
1310
|
const { initWallet, generateWallet } = useWallet();
|
|
1313
1311
|
useEffect4(() => {
|
|
1314
|
-
if (
|
|
1312
|
+
if (endpoints.auth) {
|
|
1315
1313
|
if (!window.matchWalletMessageIdMap) {
|
|
1316
1314
|
window.matchWalletMessageIdMap = {};
|
|
1317
1315
|
}
|
|
1318
|
-
const config = env_default[env];
|
|
1319
|
-
const endpoints = config.endpoints;
|
|
1320
1316
|
const existingIframe = getWalletIframe();
|
|
1321
1317
|
if (!existingIframe) {
|
|
1322
1318
|
const iframe = document.createElement("iframe");
|
|
1323
1319
|
iframe.id = "match-wallet";
|
|
1324
|
-
iframe.src = endpoints.
|
|
1320
|
+
iframe.src = endpoints.auth + "wallet";
|
|
1325
1321
|
iframe.style.display = "none";
|
|
1326
1322
|
iframe.style.width = "0";
|
|
1327
1323
|
iframe.style.height = "0";
|
|
@@ -1335,8 +1331,8 @@ function useWalletInit({
|
|
|
1335
1331
|
source: "matchid"
|
|
1336
1332
|
};
|
|
1337
1333
|
if (document.getElementById("match-wallet")) {
|
|
1338
|
-
matchlog_default.log("matchid.sdk.sendMatchWalletMessage", message, endpoints.
|
|
1339
|
-
getWalletIframe()?.contentWindow?.postMessage(message, endpoints.
|
|
1334
|
+
matchlog_default.log("matchid.sdk.sendMatchWalletMessage", message, endpoints.auth);
|
|
1335
|
+
getWalletIframe()?.contentWindow?.postMessage(message, endpoints.auth);
|
|
1340
1336
|
return messageId;
|
|
1341
1337
|
}
|
|
1342
1338
|
console.error("not found iframe");
|
|
@@ -1363,16 +1359,16 @@ function useWalletInit({
|
|
|
1363
1359
|
});
|
|
1364
1360
|
};
|
|
1365
1361
|
} else {
|
|
1366
|
-
if (existingIframe.src !== endpoints.
|
|
1362
|
+
if (existingIframe.src !== endpoints.auth + "wallet") {
|
|
1367
1363
|
setWalletInited(false);
|
|
1368
|
-
existingIframe.src = endpoints.
|
|
1364
|
+
existingIframe.src = endpoints.auth + "wallet";
|
|
1369
1365
|
}
|
|
1370
1366
|
}
|
|
1371
1367
|
}
|
|
1372
|
-
}, [
|
|
1368
|
+
}, [endpoints.auth]);
|
|
1373
1369
|
useEffect4(() => {
|
|
1374
1370
|
const messageHandle = async (e) => {
|
|
1375
|
-
if (e.origin !==
|
|
1371
|
+
if (e.origin !== endpoints.auth.substring(0, endpoints.auth.length - 1)) {
|
|
1376
1372
|
return;
|
|
1377
1373
|
}
|
|
1378
1374
|
const res = e.data;
|
|
@@ -1438,12 +1434,12 @@ import { useEffect as useEffect5, useRef } from "react";
|
|
|
1438
1434
|
function useInit({
|
|
1439
1435
|
theme,
|
|
1440
1436
|
appid,
|
|
1441
|
-
|
|
1442
|
-
|
|
1437
|
+
events,
|
|
1438
|
+
endpoints
|
|
1443
1439
|
}) {
|
|
1444
1440
|
const {
|
|
1445
1441
|
setAppid,
|
|
1446
|
-
|
|
1442
|
+
setEndpoints,
|
|
1447
1443
|
setToken,
|
|
1448
1444
|
setMid,
|
|
1449
1445
|
token,
|
|
@@ -1453,8 +1449,7 @@ function useInit({
|
|
|
1453
1449
|
const overviewLoadingRef = useRef(false);
|
|
1454
1450
|
const searchParams = new URLSearchParams(window.location.search);
|
|
1455
1451
|
const matchToken = searchParams.get("matchToken");
|
|
1456
|
-
const
|
|
1457
|
-
const endpoints = config.endpoints;
|
|
1452
|
+
const realEndpoints = endpoints || env_default.endpoints;
|
|
1458
1453
|
useEffect5(() => {
|
|
1459
1454
|
setTheme(theme);
|
|
1460
1455
|
}, [theme]);
|
|
@@ -1462,8 +1457,8 @@ function useInit({
|
|
|
1462
1457
|
setAppid(appid);
|
|
1463
1458
|
}, [appid]);
|
|
1464
1459
|
useEffect5(() => {
|
|
1465
|
-
|
|
1466
|
-
}, [
|
|
1460
|
+
setEndpoints(realEndpoints);
|
|
1461
|
+
}, [realEndpoints]);
|
|
1467
1462
|
useEffect5(() => {
|
|
1468
1463
|
if (matchToken) {
|
|
1469
1464
|
const tokenData = JSON.parse(atob(matchToken));
|
|
@@ -1536,8 +1531,7 @@ function useInit({
|
|
|
1536
1531
|
return {
|
|
1537
1532
|
loadOverview,
|
|
1538
1533
|
login,
|
|
1539
|
-
|
|
1540
|
-
endpoints
|
|
1534
|
+
endpoints: realEndpoints
|
|
1541
1535
|
};
|
|
1542
1536
|
}
|
|
1543
1537
|
|
|
@@ -1546,12 +1540,12 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
|
1546
1540
|
import { jsx as jsx28 } from "react/jsx-runtime";
|
|
1547
1541
|
var queryClient = new QueryClient();
|
|
1548
1542
|
var MatchContext = createContext(void 0);
|
|
1549
|
-
var MatchProvider = ({ children, appid,
|
|
1550
|
-
const { loadOverview, login,
|
|
1543
|
+
var MatchProvider = ({ children, appid, events, theme = "light", endpoints }) => {
|
|
1544
|
+
const { loadOverview, login, endpoints: realEndPoints } = useInit({
|
|
1551
1545
|
theme,
|
|
1552
1546
|
appid,
|
|
1553
|
-
|
|
1554
|
-
|
|
1547
|
+
events,
|
|
1548
|
+
endpoints
|
|
1555
1549
|
});
|
|
1556
1550
|
useWalletInit({
|
|
1557
1551
|
refreshOverview: loadOverview
|
|
@@ -1561,8 +1555,7 @@ var MatchProvider = ({ children, appid, env = "main", events, theme = "light" })
|
|
|
1561
1555
|
{
|
|
1562
1556
|
value: {
|
|
1563
1557
|
appid,
|
|
1564
|
-
|
|
1565
|
-
endpoints,
|
|
1558
|
+
endpoints: realEndPoints,
|
|
1566
1559
|
events,
|
|
1567
1560
|
login,
|
|
1568
1561
|
theme
|
|
@@ -2045,7 +2038,8 @@ function UsernameModal({
|
|
|
2045
2038
|
var api_exports = {};
|
|
2046
2039
|
__export(api_exports, {
|
|
2047
2040
|
bind: () => bind_exports,
|
|
2048
|
-
poh: () => poh_exports
|
|
2041
|
+
poh: () => poh_exports,
|
|
2042
|
+
user: () => user_exports
|
|
2049
2043
|
});
|
|
2050
2044
|
|
|
2051
2045
|
// src/hooks/api/bind.ts
|
|
@@ -2103,6 +2097,13 @@ function usePohList(options) {
|
|
|
2103
2097
|
});
|
|
2104
2098
|
}
|
|
2105
2099
|
|
|
2100
|
+
// src/hooks/api/user.ts
|
|
2101
|
+
var user_exports = {};
|
|
2102
|
+
__export(user_exports, {
|
|
2103
|
+
chooseIdentityApi: () => chooseIdentityApi,
|
|
2104
|
+
mintPassportNftApi: () => mintPassportNftApi
|
|
2105
|
+
});
|
|
2106
|
+
|
|
2106
2107
|
// src/config/chains/index.ts
|
|
2107
2108
|
var chains_exports = {};
|
|
2108
2109
|
__export(chains_exports, {
|