@matchain/matchid-sdk-react 0.1.49 → 0.1.50

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.
Files changed (38) hide show
  1. package/dist/{chunk-IKSPEZ4F.mjs → chunk-6KB4RLTC.mjs} +2 -2
  2. package/dist/{chunk-5JHHHLG4.mjs → chunk-HLUFAIFV.mjs} +8 -4
  3. package/dist/chunk-HLUFAIFV.mjs.map +1 -0
  4. package/dist/{chunk-MXDPJRRH.mjs → chunk-JLQVDNWZ.mjs} +84 -9
  5. package/dist/chunk-JLQVDNWZ.mjs.map +1 -0
  6. package/dist/components/index.js +45 -7
  7. package/dist/components/index.js.map +1 -1
  8. package/dist/components/index.mjs +2 -2
  9. package/dist/hooks/api/index.js +47 -8
  10. package/dist/hooks/api/index.js.map +1 -1
  11. package/dist/hooks/api/index.mjs +3 -3
  12. package/dist/hooks/index.d.mts +1 -1
  13. package/dist/hooks/index.d.ts +1 -1
  14. package/dist/hooks/index.js +67 -29
  15. package/dist/hooks/index.js.map +1 -1
  16. package/dist/hooks/index.mjs +2 -2
  17. package/dist/{index-CNzG0MX7.d.mts → index-C_TiXUOB.d.mts} +1 -1
  18. package/dist/{index-Bg4rqEu2.d.ts → index-Cx2Lx_mh.d.ts} +1 -1
  19. package/dist/index.d.mts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +98 -21
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +9 -9
  24. package/dist/utils/index.d.mts +2 -1
  25. package/dist/utils/index.d.ts +2 -1
  26. package/dist/utils/index.js +7 -2
  27. package/dist/utils/index.js.map +1 -1
  28. package/dist/utils/index.mjs +3 -1
  29. package/example/package.json +2 -1
  30. package/example/src/App.tsx +19 -8
  31. package/example/src/main.tsx +2 -0
  32. package/example/src/pages/TgApp/index.tsx +44 -0
  33. package/example/src/pages/Wallet/index.tsx +1 -2
  34. package/example/yarn.lock +5 -0
  35. package/package.json +1 -1
  36. package/dist/chunk-5JHHHLG4.mjs.map +0 -1
  37. package/dist/chunk-MXDPJRRH.mjs.map +0 -1
  38. /package/dist/{chunk-IKSPEZ4F.mjs.map → chunk-6KB4RLTC.mjs.map} +0 -0
@@ -12,12 +12,12 @@ import {
12
12
  useTransaction,
13
13
  useUserInfo,
14
14
  useWallet
15
- } from "../chunk-MXDPJRRH.mjs";
15
+ } from "../chunk-JLQVDNWZ.mjs";
16
16
  import "../chunk-UA6XHZHX.mjs";
17
17
  import {
18
18
  useLayout_exports
19
19
  } from "../chunk-FB5MHLWX.mjs";
20
- import "../chunk-5JHHHLG4.mjs";
20
+ import "../chunk-HLUFAIFV.mjs";
21
21
  import "../chunk-LHNKZISB.mjs";
22
22
  import "../chunk-J5LGTIGS.mjs";
23
23
  export {
@@ -62,7 +62,7 @@ declare const LOGIN_METHOD_MAP: {
62
62
 
63
63
  declare function useUserInfo(): {
64
64
  loginByMethod: (method: ISocialLoginMethod) => Promise<Window | null>;
65
- loginByTelegram: () => Promise<Window | null>;
65
+ loginByTelegram: () => Promise<Window | null | undefined>;
66
66
  loginByTwitter: () => Promise<Window | null>;
67
67
  loginByGoogle: () => Promise<Window | null>;
68
68
  loginByWallet: () => Promise<Window | null>;
@@ -62,7 +62,7 @@ declare const LOGIN_METHOD_MAP: {
62
62
 
63
63
  declare function useUserInfo(): {
64
64
  loginByMethod: (method: ISocialLoginMethod) => Promise<Window | null>;
65
- loginByTelegram: () => Promise<Window | null>;
65
+ loginByTelegram: () => Promise<Window | null | undefined>;
66
66
  loginByTwitter: () => Promise<Window | null>;
67
67
  loginByGoogle: () => Promise<Window | null>;
68
68
  loginByWallet: () => Promise<Window | null>;
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { I as IMatchEvents, a as IEnvConfigType, L as LocaleType, W as WalletConfigType } from './types-DzVVzMYU.mjs';
3
- export { i as Hooks, M as ModalProvider, T as ToastProvider } from './index-CNzG0MX7.mjs';
3
+ export { i as Hooks, M as ModalProvider, T as ToastProvider } from './index-C_TiXUOB.mjs';
4
4
  export { i as Components } from './index-C9qYyRgt.mjs';
5
5
  export { i as UI } from './index-C9F6f2iz.mjs';
6
6
  export { i as Api } from './index-D4ju2J_e.mjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { I as IMatchEvents, a as IEnvConfigType, L as LocaleType, W as WalletConfigType } from './types-DzVVzMYU.js';
3
- export { i as Hooks, M as ModalProvider, T as ToastProvider } from './index-Bg4rqEu2.js';
3
+ export { i as Hooks, M as ModalProvider, T as ToastProvider } from './index-Cx2Lx_mh.js';
4
4
  export { i as Components } from './index-Bvc8cjpN.js';
5
5
  export { i as UI } from './index-BMsj8hJv.js';
6
6
  export { i as Api } from './index-Cy3K-Yao.js';
package/dist/index.js CHANGED
@@ -466,6 +466,19 @@ var getWalletNftListApi = (data) => {
466
466
  data
467
467
  });
468
468
  };
469
+ var tgAppLoginInitApi = () => {
470
+ return retryRequest({
471
+ url: `/api/v1/tgapp/login/init`,
472
+ method: "GET"
473
+ });
474
+ };
475
+ var getTgAppLoginStatus = (data) => {
476
+ return retryRequest({
477
+ url: `/api/v1/tgapp/login/status`,
478
+ method: "POST",
479
+ data
480
+ });
481
+ };
469
482
 
470
483
  // src/store/useLocalStore.ts
471
484
  var persistedState = (0, import_middleware.persist)(
@@ -620,7 +633,7 @@ var NumberFormatter = ({
620
633
  }
621
634
  }
622
635
  if (zeroCount < tFixNum) {
623
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
636
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className, children: [
624
637
  prefix && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: prefixClassName, children: prefix }),
625
638
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: intClassName, children: intFormat }),
626
639
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: decimalClassName, children: [
@@ -630,7 +643,7 @@ var NumberFormatter = ({
630
643
  suffix
631
644
  ] });
632
645
  }
633
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
646
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className, children: [
634
647
  prefix && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: prefixClassName, children: prefix }),
635
648
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: intClassName, children: intFormat }),
636
649
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: decimalClassName, children: [
@@ -656,6 +669,9 @@ var formatDate = (value, formatString = "YYYY-MM-DD HH:mm:ss") => {
656
669
  }
657
670
  return "--";
658
671
  };
672
+ var isInTgApp = () => {
673
+ return !!window.TelegramWebviewProxy;
674
+ };
659
675
 
660
676
  // src/store/useModalStore.ts
661
677
  var import_zustand2 = require("zustand");
@@ -1909,6 +1925,16 @@ var useWalletModalStore = (0, import_zustand2.create)((set) => ({
1909
1925
  close: () => set({ isOpen: false })
1910
1926
  }));
1911
1927
 
1928
+ // src/store/useStore.ts
1929
+ var import_zustand3 = require("zustand");
1930
+ var useStore = (0, import_zustand3.create)((set) => ({
1931
+ walletReady: false,
1932
+ setWalletReady: (inited) => set({ walletReady: inited }),
1933
+ tgAppAuthCode: "",
1934
+ setTgAppAuthCode: (code) => set({ tgAppAuthCode: code })
1935
+ }));
1936
+ var useStore_default = useStore;
1937
+
1912
1938
  // src/hooks/useUserInfo.tsx
1913
1939
  function useUserInfo() {
1914
1940
  const {
@@ -1924,6 +1950,7 @@ function useUserInfo() {
1924
1950
  locale,
1925
1951
  refreshOverview
1926
1952
  } = useLocalStore_default();
1953
+ const { setTgAppAuthCode } = useStore_default();
1927
1954
  const { events, login } = useMatch();
1928
1955
  const { open: SOLOpen } = useSOLModalStore();
1929
1956
  const { open: TRONOpen } = useTRONModalStore();
@@ -1962,6 +1989,31 @@ function useUserInfo() {
1962
1989
  return window.open(`${endpoints.auth}login/wallet?appid=${appid}&locale=${locale}`);
1963
1990
  };
1964
1991
  const loginByTelegram = async () => {
1992
+ if (isInTgApp()) {
1993
+ try {
1994
+ const res = await tgAppLoginInitApi();
1995
+ if (!isSuccess(res)) {
1996
+ throw new Error(res.message);
1997
+ }
1998
+ setTgAppAuthCode(res.data.code);
1999
+ const link = res.data.login_url + `?startapp=${res.data.code}_${appid}_${locale}`;
2000
+ console.log("tgAppLoginInitLink", link);
2001
+ if (window.TelegramWebviewProxy) {
2002
+ console.log("in telegram webview");
2003
+ if (!window.Telegram) {
2004
+ throw new Error("Please import telegram-web-app.js first");
2005
+ }
2006
+ window.Telegram.WebApp.openTelegramLink(link);
2007
+ return;
2008
+ }
2009
+ console.log("not in telegram webview");
2010
+ window.open(link);
2011
+ return;
2012
+ } catch (e) {
2013
+ console.error("tgAppLoginInitApi", e);
2014
+ throw e;
2015
+ }
2016
+ }
1965
2017
  return window.open(
1966
2018
  `${endpoints.auth}login/telegram?appid=${appid}&locale=${locale}`,
1967
2019
  // Replace with the actual authorization URL
@@ -2184,14 +2236,6 @@ function useMatchEvents(handlers) {
2184
2236
  // src/hooks/useWallet.tsx
2185
2237
  var import_viem2 = require("viem");
2186
2238
 
2187
- // src/store/useStore.ts
2188
- var import_zustand3 = require("zustand");
2189
- var useStore = (0, import_zustand3.create)((set) => ({
2190
- walletReady: false,
2191
- setWalletReady: (inited) => set({ walletReady: inited })
2192
- }));
2193
- var useStore_default = useStore;
2194
-
2195
2239
  // src/types/mpc.ts
2196
2240
  var ChainType = /* @__PURE__ */ ((ChainType2) => {
2197
2241
  ChainType2["Ethereum"] = "ethereum";
@@ -6807,6 +6851,7 @@ function CEXBindModal({
6807
6851
  }
6808
6852
 
6809
6853
  // src/context/BusinessProvider.tsx
6854
+ var import_react_query9 = require("@tanstack/react-query");
6810
6855
  var import_jsx_runtime92 = require("react/jsx-runtime");
6811
6856
  function BusinessProvider({ children }) {
6812
6857
  const { overview, token } = useUserInfo();
@@ -6816,10 +6861,31 @@ function BusinessProvider({ children }) {
6816
6861
  const { type: BTCType, isOpen: BTCIsOpen, close: BTCClose } = useBTCModalStore();
6817
6862
  const { type: CEXType, isOpen: CEXIsOpen, close: CEXClose } = useCEXBindModalStore();
6818
6863
  const WalletModalStore = useWalletModalStore();
6864
+ const { tgAppAuthCode, setTgAppAuthCode } = useStore_default();
6865
+ const { login } = useMatch();
6819
6866
  const walletModalClose = (func) => {
6820
6867
  WalletModalStore.close();
6821
6868
  func();
6822
6869
  };
6870
+ (0, import_react_query9.useQuery)({
6871
+ queryKey: ["matchid-tgapp-login", tgAppAuthCode],
6872
+ queryFn: async () => {
6873
+ const res = await getTgAppLoginStatus({
6874
+ code: tgAppAuthCode
6875
+ });
6876
+ if (isSuccess(res)) {
6877
+ setTgAppAuthCode("");
6878
+ await login({
6879
+ mid: "",
6880
+ token: `${res.data.token_type} ${res.data.access_token}`
6881
+ });
6882
+ return true;
6883
+ }
6884
+ return false;
6885
+ },
6886
+ enabled: !!tgAppAuthCode,
6887
+ refetchInterval: 1e3 * 5
6888
+ });
6823
6889
  return /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(import_jsx_runtime92.Fragment, { children: [
6824
6890
  /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6825
6891
  SOLModal,
@@ -6923,7 +6989,7 @@ var AppClientId2 = getAppClientId();
6923
6989
  function useWalletInit({
6924
6990
  config
6925
6991
  }) {
6926
- const { endpoints, token, overview, setWallet, wallet, appid, locale, refreshOverview } = useLocalStore_default();
6992
+ const { endpoints, token, setWallet, appid, refreshOverview } = useLocalStore_default();
6927
6993
  const { setWalletReady, walletReady } = useStore_default();
6928
6994
  const iframeReadyRef = (0, import_react38.useRef)(walletReady);
6929
6995
  (0, import_react38.useEffect)(() => {
@@ -6958,7 +7024,6 @@ function useWalletInit({
6958
7024
  const existingIframe = getWalletIframe();
6959
7025
  const query = {
6960
7026
  appid,
6961
- locale,
6962
7027
  appClientId: AppClientId2,
6963
7028
  initParams: encodeBase64(JSON.stringify({
6964
7029
  access_token: token,
@@ -6997,7 +7062,8 @@ function useWalletInit({
6997
7062
  data,
6998
7063
  messageId,
6999
7064
  source: "matchid",
7000
- version: 1
7065
+ version: 1,
7066
+ locale: getLocale()
7001
7067
  };
7002
7068
  try {
7003
7069
  matchlog_default.log("sdk.mpc.send", message, endpoints.auth);
@@ -7242,7 +7308,7 @@ function useInit({
7242
7308
  }
7243
7309
 
7244
7310
  // src/MatchContext.tsx
7245
- var import_react_query9 = require("@tanstack/react-query");
7311
+ var import_react_query10 = require("@tanstack/react-query");
7246
7312
  var import_react_intl21 = require("react-intl");
7247
7313
 
7248
7314
  // src/i18n/en.json
@@ -7980,7 +8046,7 @@ var messages = {
7980
8046
 
7981
8047
  // src/MatchContext.tsx
7982
8048
  var import_jsx_runtime94 = require("react/jsx-runtime");
7983
- var queryClient = new import_react_query9.QueryClient();
8049
+ var queryClient = new import_react_query10.QueryClient();
7984
8050
  var MatchContext = (0, import_react40.createContext)(void 0);
7985
8051
  var MatchProvider = ({
7986
8052
  children,
@@ -8001,7 +8067,18 @@ var MatchProvider = ({
8001
8067
  useWalletInit({
8002
8068
  config: wallet
8003
8069
  });
8004
- return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_intl21.IntlProvider, { locale: realLocale, messages: messages[realLocale], children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_query9.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
8070
+ (0, import_react40.useEffect)(() => {
8071
+ if (!window.Telegram) {
8072
+ const script = document.createElement("script");
8073
+ script.src = "https://telegram.org/js/telegram-web-app.js?56";
8074
+ script.async = true;
8075
+ document.body.appendChild(script);
8076
+ return () => {
8077
+ document.body.removeChild(script);
8078
+ };
8079
+ }
8080
+ }, []);
8081
+ return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_intl21.IntlProvider, { locale: realLocale, messages: messages[realLocale], children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_query10.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
8005
8082
  MatchContext.Provider,
8006
8083
  {
8007
8084
  value: {
@@ -8043,10 +8120,10 @@ __export(bind_exports, {
8043
8120
  useBindInfo: () => useBindInfo,
8044
8121
  useBindList: () => useBindList
8045
8122
  });
8046
- var import_react_query10 = require("@tanstack/react-query");
8123
+ var import_react_query11 = require("@tanstack/react-query");
8047
8124
  function useBindList(options) {
8048
8125
  const { isLogin } = useUserInfo();
8049
- return (0, import_react_query10.useQuery)({
8126
+ return (0, import_react_query11.useQuery)({
8050
8127
  queryKey: ["bindList"],
8051
8128
  enabled: isLogin,
8052
8129
  queryFn: async () => {
@@ -8058,7 +8135,7 @@ function useBindList(options) {
8058
8135
  }
8059
8136
  function useBindInfo(options) {
8060
8137
  const { isLogin } = useUserInfo();
8061
- return (0, import_react_query10.useQuery)({
8138
+ return (0, import_react_query11.useQuery)({
8062
8139
  queryKey: ["bindInfo"],
8063
8140
  enabled: isLogin,
8064
8141
  queryFn: async () => {
@@ -8075,10 +8152,10 @@ __export(poh_exports, {
8075
8152
  usePohList: () => usePohList,
8076
8153
  verifyPohApi: () => verifyPohApi
8077
8154
  });
8078
- var import_react_query11 = require("@tanstack/react-query");
8155
+ var import_react_query12 = require("@tanstack/react-query");
8079
8156
  function usePohList(options) {
8080
8157
  const { isLogin } = useUserInfo();
8081
- return (0, import_react_query11.useQuery)({
8158
+ return (0, import_react_query12.useQuery)({
8082
8159
  queryKey: ["pohList"],
8083
8160
  enabled: isLogin,
8084
8161
  queryFn: async () => {