@moon-x/react-native-sdk 0.26.0 → 0.28.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.
package/dist/index.js CHANGED
@@ -33,42 +33,42 @@ __export(index_exports, {
33
33
  MOONPAY_CONSUMER_SESSION_ERROR_CODES: () => import_sdk12.MOONPAY_CONSUMER_SESSION_ERROR_CODES,
34
34
  MoonKeyProvider: () => MoonXProvider,
35
35
  MoonXProvider: () => MoonXProvider,
36
- PostMessageMethod: () => import_utils11.PostMessageMethod,
37
- PostMessageType: () => import_utils11.PostMessageType,
36
+ PostMessageMethod: () => import_utils10.PostMessageMethod,
37
+ PostMessageType: () => import_utils10.PostMessageType,
38
38
  connectWalletConnect: () => connectWalletConnect,
39
39
  listWalletConnectSessions: () => listWalletConnectSessions,
40
40
  registerPresenceOtpCodeProvider: () => import_sdk13.registerPresenceOtpCodeProvider,
41
41
  restoreWalletConnectSession: () => restoreWalletConnectSession,
42
- useAddPasskey: () => import_react9.useAddPasskey,
42
+ useAddPasskey: () => import_react10.useAddPasskey,
43
43
  useAppConfig: () => useAppConfig,
44
44
  useAttachOAuth: () => useAttachOAuth,
45
- useBulkImport: () => import_react9.useBulkImport,
46
- useChangeEmail: () => import_react9.useChangeEmail,
47
- useCreateWallet: () => import_react9.useCreateWallet,
45
+ useBulkImport: () => import_react10.useBulkImport,
46
+ useChangeEmail: () => import_react10.useChangeEmail,
47
+ useCreateWallet: () => import_react10.useCreateWallet,
48
48
  useDetachOAuth: () => useDetachOAuth,
49
- useEphemeralSigner: () => import_react9.useEphemeralSigner,
49
+ useEphemeralSigner: () => import_react10.useEphemeralSigner,
50
50
  useExportKey: () => useExportKey,
51
51
  useExternalWallets: () => useExternalWallets,
52
52
  useFundWallet: () => useFundWallet,
53
- useImportKey: () => import_react9.useImportKey,
54
- useLinkEmail: () => import_react9.useLinkEmail,
53
+ useImportKey: () => import_react10.useImportKey,
54
+ useLinkEmail: () => import_react10.useLinkEmail,
55
55
  useLoginWithEmail: () => useLoginWithEmail,
56
56
  useLoginWithOAuth: () => useLoginWithOAuth,
57
- useLogout: () => import_react9.useLogout,
57
+ useLogout: () => import_react10.useLogout,
58
58
  useMoonKey: () => useMoonX,
59
59
  useMoonX: () => useMoonX,
60
60
  useMoonXContext: () => useMoonXContext,
61
- usePasskeyStatus: () => import_react9.usePasskeyStatus,
62
- useRegisterPasskey: () => import_react9.useRegisterPasskey,
63
- useRemovePasskey: () => import_react9.useRemovePasskey,
64
- useUser: () => import_react9.useUser,
65
- useWallets: () => import_react9.useWallets
61
+ usePasskeyStatus: () => import_react10.usePasskeyStatus,
62
+ useRegisterPasskey: () => import_react10.useRegisterPasskey,
63
+ useRemovePasskey: () => import_react10.useRemovePasskey,
64
+ useUser: () => import_react10.useUser,
65
+ useWallets: () => import_react10.useWallets
66
66
  });
67
67
  module.exports = __toCommonJS(index_exports);
68
68
 
69
69
  // src/provider.tsx
70
- var import_react2 = require("react");
71
- var import_react_native2 = require("react-native");
70
+ var import_react3 = require("react");
71
+ var import_react_native3 = require("react-native");
72
72
  var import_react_native_webview = require("react-native-webview");
73
73
 
74
74
  // src/sdk/create-sdk-instance.ts
@@ -546,6 +546,24 @@ function getSessionMethods(bridge, publishableKey, relyingPartyOrigin, session,
546
546
  await refreshUser();
547
547
  return result;
548
548
  },
549
+ // Redeems the provider's token for a link (useAttachOAuth). The user
550
+ // stays the same account, so unlike verifyOAuth this isn't a login: a
551
+ // failed link leaves the session-resume binding and the published user
552
+ // alone, and a successful one refreshes the user like linkEmailWithCode.
553
+ verifyOAuthLink: async (params) => {
554
+ const refreshUser = session.captureUserRefresh();
555
+ await auth().verifyOAuthLink(params);
556
+ await refreshUser();
557
+ },
558
+ // linked_accounts changed, so the published user is read again, the same
559
+ // as after a link. (Core's own refresh needs a raw setUser, which the
560
+ // session-managed provider doesn't hand it.)
561
+ detachOAuth: async (idpUserId) => {
562
+ const refreshUser = session.captureUserRefresh();
563
+ const result = await general().detachOAuth(idpUserId);
564
+ await refreshUser();
565
+ return result;
566
+ },
549
567
  // The account's email changes, so the provider's user is read again
550
568
  // before the change resolves, the same as a link.
551
569
  confirmEmailChangeNewCode: async (params) => {
@@ -622,12 +640,39 @@ var createSdkInstance = ({
622
640
  });
623
641
 
624
642
  // src/provider.tsx
625
- var import_utils5 = require("@moon-x/core/utils");
643
+ var import_utils6 = require("@moon-x/core/utils");
626
644
 
627
645
  // src/components/presence-otp-prompt.tsx
646
+ var import_react2 = __toESM(require("react"));
647
+ var import_react_native2 = require("react-native");
648
+ var import_sdk9 = require("@moon-x/core/sdk");
649
+
650
+ // src/components/use-reduce-motion.ts
628
651
  var import_react = require("react");
629
652
  var import_react_native = require("react-native");
630
- var import_sdk9 = require("@moon-x/core/sdk");
653
+ var lastKnown;
654
+ var useReduceMotion = () => {
655
+ const [state, setState] = (0, import_react.useState)(() => ({
656
+ reduceMotion: lastKnown ?? true,
657
+ settled: lastKnown !== void 0
658
+ }));
659
+ (0, import_react.useEffect)(() => {
660
+ let live = true;
661
+ const update = (enabled) => {
662
+ lastKnown = enabled;
663
+ if (live) setState({ reduceMotion: enabled, settled: true });
664
+ };
665
+ import_react_native.AccessibilityInfo.isReduceMotionEnabled().then(update).catch(() => {
666
+ if (live) setState((current) => ({ ...current, settled: true }));
667
+ });
668
+ const subscription = import_react_native.AccessibilityInfo.addEventListener("reduceMotionChanged", update);
669
+ return () => {
670
+ live = false;
671
+ subscription.remove();
672
+ };
673
+ }, []);
674
+ return state;
675
+ };
631
676
 
632
677
  // src/components/presence-otp-gate.ts
633
678
  var createPresenceOtpGate = () => {
@@ -739,42 +784,160 @@ var createPresenceOtpController = (onChange) => {
739
784
  };
740
785
  };
741
786
 
742
- // src/components/presence-otp-prompt.tsx
743
- var import_jsx_runtime = require("react/jsx-runtime");
744
- var DEFAULT_COPY = {
745
- title: "Check your email",
746
- description: "Enter the verification code we sent to confirm this wallet action.",
747
- hint: "Didn't get it? Check spam, or cancel and try again in a minute.",
748
- verify: "Verify",
749
- verifying: "Verifying...",
750
- cancel: "Cancel",
751
- invalidCode: "That code was incorrect. Try again.",
752
- incompleteCode: "Enter the 6-digit code."
787
+ // src/components/presence-otp-strings.ts
788
+ var import_utils3 = require("@moon-x/core/utils");
789
+ var PROMPT_LANGUAGES = ["en", "de", "es", "fr", "it", "pt"];
790
+ var COPY = {
791
+ en: {
792
+ title: "Check your email",
793
+ description: "Enter the code we sent to confirm this wallet action.",
794
+ hint: "",
795
+ verify: "Verify",
796
+ verifying: "Verifying\u2026",
797
+ cancel: "Cancel",
798
+ close: "Close",
799
+ invalidCode: "That code didn't work. Try again.",
800
+ incompleteCode: "Enter the 6-digit code.",
801
+ codeLabel: "Verification code"
802
+ },
803
+ de: {
804
+ title: "Pr\xFCfe deine E-Mails",
805
+ description: "Gib den Code ein, den wir dir gesendet haben, um diese Wallet-Aktion zu best\xE4tigen.",
806
+ hint: "",
807
+ verify: "Best\xE4tigen",
808
+ verifying: "Wird best\xE4tigt\u2026",
809
+ cancel: "Abbrechen",
810
+ close: "Schlie\xDFen",
811
+ invalidCode: "Der Code hat nicht funktioniert. Versuche es erneut.",
812
+ incompleteCode: "Gib den 6-stelligen Code ein.",
813
+ codeLabel: "Best\xE4tigungscode"
814
+ },
815
+ es: {
816
+ title: "Revisa tu correo",
817
+ description: "Introduce el c\xF3digo que te enviamos para confirmar esta acci\xF3n de la billetera.",
818
+ hint: "",
819
+ verify: "Verificar",
820
+ verifying: "Verificando\u2026",
821
+ cancel: "Cancelar",
822
+ close: "Cerrar",
823
+ invalidCode: "Ese c\xF3digo no funcion\xF3. Int\xE9ntalo de nuevo.",
824
+ incompleteCode: "Introduce el c\xF3digo de 6 d\xEDgitos.",
825
+ codeLabel: "C\xF3digo de verificaci\xF3n"
826
+ },
827
+ fr: {
828
+ title: "Consultez vos e-mails",
829
+ description: "Saisissez le code que nous vous avons envoy\xE9 pour confirmer cette action sur le portefeuille.",
830
+ hint: "",
831
+ verify: "V\xE9rifier",
832
+ verifying: "V\xE9rification\u2026",
833
+ cancel: "Annuler",
834
+ close: "Fermer",
835
+ invalidCode: "Ce code n'a pas fonctionn\xE9. R\xE9essayez.",
836
+ incompleteCode: "Saisissez le code \xE0 6 chiffres.",
837
+ codeLabel: "Code de v\xE9rification"
838
+ },
839
+ it: {
840
+ title: "Controlla la tua email",
841
+ description: "Inserisci il codice che ti abbiamo inviato per confermare questa azione sul wallet.",
842
+ hint: "",
843
+ verify: "Verifica",
844
+ verifying: "Verifica in corso\u2026",
845
+ cancel: "Annulla",
846
+ close: "Chiudi",
847
+ invalidCode: "Il codice non \xE8 valido. Riprova.",
848
+ incompleteCode: "Inserisci il codice a 6 cifre.",
849
+ codeLabel: "Codice di verifica"
850
+ },
851
+ pt: {
852
+ title: "Verifique seu e-mail",
853
+ description: "Digite o c\xF3digo que enviamos para confirmar esta a\xE7\xE3o na carteira.",
854
+ hint: "",
855
+ verify: "Verificar",
856
+ verifying: "Verificando\u2026",
857
+ cancel: "Cancelar",
858
+ close: "Fechar",
859
+ invalidCode: "Esse c\xF3digo n\xE3o funcionou. Tente novamente.",
860
+ incompleteCode: "Digite o c\xF3digo de 6 d\xEDgitos.",
861
+ codeLabel: "C\xF3digo de verifica\xE7\xE3o"
862
+ }
863
+ };
864
+ var LIGHT_COLORS = {
865
+ background: "#ffffff",
866
+ surface: "#f4f3f9",
867
+ border: "#e6e4ef",
868
+ text: "#010101",
869
+ mutedText: "#747386",
870
+ accent: "#010101",
871
+ accentText: "#fcfbff",
872
+ error: "#c41f1f",
873
+ errorSurface: "#f6e4e4",
874
+ backdrop: "rgba(1, 1, 1, 0.32)"
875
+ };
876
+ var DARK_COLORS = {
877
+ background: "#0b0b0d",
878
+ surface: "#17171b",
879
+ border: "#292930",
880
+ text: "#fcfbff",
881
+ mutedText: "#9e9bae",
882
+ accent: "#fcfbff",
883
+ accentText: "#010101",
884
+ error: "#ff9b98",
885
+ errorSurface: "#3c0202",
886
+ backdrop: "rgba(1, 1, 1, 0.32)"
753
887
  };
754
- var DEFAULT_COLORS = {
755
- background: "#0a0a0a",
756
- surface: "#141414",
757
- border: "#333",
758
- text: "#fafafa",
759
- mutedText: "#a1a1aa",
760
- accent: "#3b82f6",
761
- accentText: "#fff",
762
- error: "#f87171"
888
+ var deviceLanguage = () => {
889
+ try {
890
+ return Intl.DateTimeFormat().resolvedOptions().locale;
891
+ } catch {
892
+ return void 0;
893
+ }
894
+ };
895
+ var resolvePromptCopy = (language) => {
896
+ return COPY[(0, import_utils3.resolveLanguage)(language ?? deviceLanguage(), PROMPT_LANGUAGES, "en")];
763
897
  };
898
+ var resolvePromptColors = (displayMode, systemScheme) => {
899
+ const dark = displayMode === "dark" || displayMode !== "light" && systemScheme === "dark";
900
+ return dark ? DARK_COLORS : LIGHT_COLORS;
901
+ };
902
+
903
+ // src/components/presence-otp-prompt.tsx
904
+ var import_jsx_runtime = require("react/jsx-runtime");
764
905
  var OTP_LENGTH = 6;
906
+ var SHEET_MAX_WIDTH = 480;
907
+ var COMPACT_MAX_WIDTH = 360;
765
908
  var PresenceOtpPrompt = ({
766
909
  publishableKey,
767
910
  options
768
911
  }) => {
769
- const [state, setState] = (0, import_react.useState)(
912
+ const [state, setState] = (0, import_react2.useState)(
770
913
  IDLE_PRESENCE_OTP_STATE
771
914
  );
772
- const [code, setCode] = (0, import_react.useState)("");
773
- const [incomplete, setIncomplete] = (0, import_react.useState)(false);
774
- const controllerRef = (0, import_react.useRef)(null);
775
- const copy = { ...DEFAULT_COPY, ...options?.copy };
776
- const colors = { ...DEFAULT_COLORS, ...options?.colors };
777
- (0, import_react.useEffect)(() => {
915
+ const [code, setCode] = (0, import_react2.useState)("");
916
+ const [incomplete, setIncomplete] = (0, import_react2.useState)(false);
917
+ const [edited, setEdited] = (0, import_react2.useState)(false);
918
+ const [focused, setFocused] = (0, import_react2.useState)(false);
919
+ const controllerRef = (0, import_react2.useRef)(null);
920
+ const inputRef = (0, import_react2.useRef)(null);
921
+ const sheetOffset = (0, import_react2.useRef)(new import_react_native2.Animated.Value(0)).current;
922
+ const shake = (0, import_react2.useRef)(new import_react_native2.Animated.Value(0)).current;
923
+ const caret = (0, import_react2.useRef)(new import_react_native2.Animated.Value(1)).current;
924
+ const { reduceMotion, settled: motionSettled } = useReduceMotion();
925
+ const shakePending = (0, import_react2.useRef)(false);
926
+ const scheme = (0, import_react_native2.useColorScheme)();
927
+ const { width } = (0, import_react_native2.useWindowDimensions)();
928
+ const copy = { ...resolvePromptCopy(options?.language), ...options?.copy };
929
+ const colors = {
930
+ ...resolvePromptColors(options?.displayMode, scheme),
931
+ ...options?.colors
932
+ };
933
+ const visible = state.request !== null;
934
+ const submitting = state.submitting;
935
+ const invalid = state.invalidCode && !edited;
936
+ const error = incomplete ? copy.incompleteCode : invalid ? copy.invalidCode : null;
937
+ const complete = code.length === OTP_LENGTH;
938
+ const sheet = width <= SHEET_MAX_WIDTH;
939
+ const compact = width <= COMPACT_MAX_WIDTH;
940
+ (0, import_react2.useEffect)(() => {
778
941
  const controller = createPresenceOtpController(setState);
779
942
  controllerRef.current = controller;
780
943
  const unregister = (0, import_sdk9.registerPresenceOtpCodeProvider)(
@@ -789,11 +952,63 @@ var PresenceOtpPrompt = ({
789
952
  setState(IDLE_PRESENCE_OTP_STATE);
790
953
  };
791
954
  }, [publishableKey]);
792
- (0, import_react.useEffect)(() => {
955
+ const shakeCells = () => {
956
+ shake.setValue(0);
957
+ import_react_native2.Animated.sequence(
958
+ [-6, 6, -4, 4, -2, 0].map(
959
+ (toValue) => import_react_native2.Animated.timing(shake, {
960
+ toValue,
961
+ duration: 60,
962
+ easing: import_react_native2.Easing.linear,
963
+ useNativeDriver: true
964
+ })
965
+ )
966
+ ).start();
967
+ };
968
+ (0, import_react2.useEffect)(() => {
793
969
  setCode("");
794
970
  setIncomplete(false);
971
+ setEdited(false);
972
+ shakePending.current = false;
973
+ if (!state.request) return;
974
+ inputRef.current?.focus();
975
+ if (!state.invalidCode) return;
976
+ if (!motionSettled) shakePending.current = true;
977
+ else if (!reduceMotion) shakeCells();
795
978
  }, [state.request]);
796
- (0, import_react.useEffect)(() => {
979
+ (0, import_react2.useEffect)(() => {
980
+ if (!motionSettled || !shakePending.current) return;
981
+ shakePending.current = false;
982
+ if (!reduceMotion) shakeCells();
983
+ }, [motionSettled]);
984
+ (0, import_react2.useEffect)(() => {
985
+ if (!visible) return;
986
+ sheetOffset.setValue(reduceMotion ? 0 : 24);
987
+ import_react_native2.Animated.timing(sheetOffset, {
988
+ toValue: 0,
989
+ duration: 240,
990
+ easing: import_react_native2.Easing.out(import_react_native2.Easing.cubic),
991
+ useNativeDriver: true
992
+ }).start();
993
+ }, [visible]);
994
+ (0, import_react2.useEffect)(() => {
995
+ caret.setValue(1);
996
+ if (!focused || reduceMotion) return;
997
+ const blink = import_react_native2.Animated.loop(
998
+ import_react_native2.Animated.sequence([
999
+ import_react_native2.Animated.timing(caret, { toValue: 0, duration: 0, delay: 530, useNativeDriver: true }),
1000
+ import_react_native2.Animated.timing(caret, { toValue: 1, duration: 0, delay: 530, useNativeDriver: true })
1001
+ ])
1002
+ );
1003
+ blink.start();
1004
+ return () => blink.stop();
1005
+ }, [focused, reduceMotion, code]);
1006
+ (0, import_react2.useEffect)(() => {
1007
+ if (error && import_react_native2.Platform.OS === "ios") {
1008
+ import_react_native2.AccessibilityInfo.announceForAccessibility(error);
1009
+ }
1010
+ }, [error]);
1011
+ (0, import_react2.useEffect)(() => {
797
1012
  const request = state.request;
798
1013
  if (!request?.expiresAt || state.submitting) return;
799
1014
  const expire = () => controllerRef.current?.expire(request);
@@ -808,160 +1023,451 @@ var PresenceOtpPrompt = ({
808
1023
  const close = () => {
809
1024
  controllerRef.current?.cancel();
810
1025
  };
811
- const submit = () => {
812
- const normalized = code.trim();
813
- if (!/^\d{6}$/.test(normalized)) {
1026
+ const submit = (value = code) => {
1027
+ if (!/^\d{6}$/.test(value)) {
814
1028
  setIncomplete(true);
815
1029
  return;
816
1030
  }
817
- controllerRef.current?.submit(normalized);
1031
+ controllerRef.current?.submit(value);
818
1032
  };
819
- const submitting = state.submitting;
820
- const error = incomplete ? copy.incompleteCode : state.invalidCode ? copy.invalidCode : null;
821
- const complete = code.length === OTP_LENGTH;
1033
+ const changeCode = (next) => {
1034
+ if (submitting) return;
1035
+ const clean = next.replace(/\D/g, "").slice(0, OTP_LENGTH);
1036
+ setCode(clean);
1037
+ setIncomplete(false);
1038
+ setEdited(true);
1039
+ if (clean.length === OTP_LENGTH) submit(clean);
1040
+ };
1041
+ const cells = Array.from({ length: OTP_LENGTH }, (_, index) => {
1042
+ const digit = code[index] ?? "";
1043
+ const current = focused && !submitting && index === Math.min(code.length, OTP_LENGTH - 1);
1044
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react2.default.Fragment, { children: [
1045
+ index === OTP_LENGTH / 2 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.separator, { backgroundColor: colors.mutedText }] }),
1046
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1047
+ import_react_native2.View,
1048
+ {
1049
+ style: [
1050
+ styles.cell,
1051
+ compact && styles.cellCompact,
1052
+ { backgroundColor: colors.background, borderColor: colors.border },
1053
+ current && { borderColor: colors.accent },
1054
+ invalid && { borderColor: colors.error, backgroundColor: colors.errorSurface }
1055
+ ],
1056
+ children: digit ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [styles.cellText, { color: invalid ? colors.error : colors.text }], children: digit }) : current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1057
+ import_react_native2.Animated.View,
1058
+ {
1059
+ style: [styles.caret, { backgroundColor: colors.accent, opacity: caret }]
1060
+ }
1061
+ )
1062
+ }
1063
+ )
1064
+ ] }, index);
1065
+ });
822
1066
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
823
- import_react_native.Modal,
1067
+ import_react_native2.Modal,
824
1068
  {
825
- visible: state.request !== null,
1069
+ visible,
826
1070
  transparent: true,
827
1071
  animationType: "fade",
828
1072
  onRequestClose: close,
829
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: styles.backdrop, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: [styles.card, { backgroundColor: colors.background }], children: [
830
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.title, { color: colors.text }], children: copy.title }),
831
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.body, { color: colors.mutedText }], children: copy.description }),
832
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
833
- import_react_native.TextInput,
834
- {
835
- autoFocus: true,
836
- style: [
837
- styles.input,
838
- {
839
- borderColor: colors.border,
840
- backgroundColor: colors.surface,
841
- color: colors.text
842
- }
843
- ],
844
- value: code,
845
- onChangeText: (next) => {
846
- setCode(next.replace(/\D/g, "").slice(0, OTP_LENGTH));
847
- setIncomplete(false);
848
- },
849
- onSubmitEditing: submit,
850
- editable: !submitting,
851
- keyboardType: "number-pad",
852
- textContentType: "oneTimeCode",
853
- autoComplete: "sms-otp",
854
- maxLength: OTP_LENGTH,
855
- placeholder: "123456",
856
- placeholderTextColor: colors.mutedText,
857
- accessibilityLabel: "Verification code",
858
- returnKeyType: "done"
859
- }
860
- ),
861
- error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
862
- import_react_native.Text,
863
- {
864
- style: [styles.error, { color: colors.error }],
865
- accessibilityLiveRegion: "polite",
866
- children: error
867
- }
868
- ),
869
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
870
- import_react_native.Pressable,
871
- {
872
- onPress: submit,
873
- disabled: submitting || !complete,
874
- style: [
875
- styles.primaryButton,
876
- { backgroundColor: colors.accent },
877
- (submitting || !complete) && styles.primaryButtonDisabled
878
- ],
879
- accessibilityRole: "button",
880
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.primaryButtonText, { color: colors.accentText }], children: submitting ? copy.verifying : copy.verify })
881
- }
882
- ),
883
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
884
- import_react_native.Pressable,
885
- {
886
- onPress: close,
887
- disabled: submitting,
888
- style: [styles.ghostButton, submitting && styles.primaryButtonDisabled],
889
- accessibilityRole: "button",
890
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.ghostButtonText, { color: colors.mutedText }], children: copy.cancel })
891
- }
892
- ),
893
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.hint, { color: colors.mutedText }], children: copy.hint })
894
- ] }) })
1073
+ onShow: () => inputRef.current?.focus(),
1074
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1075
+ import_react_native2.KeyboardAvoidingView,
1076
+ {
1077
+ behavior: import_react_native2.Platform.OS === "ios" ? "padding" : void 0,
1078
+ style: [
1079
+ styles.backdrop,
1080
+ sheet ? styles.backdropSheet : styles.backdropCentered,
1081
+ { backgroundColor: colors.backdrop }
1082
+ ],
1083
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1084
+ import_react_native2.Animated.View,
1085
+ {
1086
+ accessibilityViewIsModal: true,
1087
+ style: [
1088
+ styles.card,
1089
+ sheet ? styles.sheet : styles.centered,
1090
+ {
1091
+ backgroundColor: colors.background,
1092
+ borderColor: colors.border,
1093
+ transform: [{ translateY: sheetOffset }]
1094
+ }
1095
+ ],
1096
+ children: [
1097
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.header, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1098
+ import_react_native2.Pressable,
1099
+ {
1100
+ onPress: close,
1101
+ disabled: submitting,
1102
+ hitSlop: 8,
1103
+ accessibilityRole: "button",
1104
+ accessibilityLabel: copy.close,
1105
+ style: ({ pressed }) => [
1106
+ styles.iconButton,
1107
+ { backgroundColor: pressed ? colors.border : colors.surface },
1108
+ submitting && styles.disabled
1109
+ ],
1110
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CloseIcon, { color: colors.mutedText })
1111
+ }
1112
+ ) }),
1113
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1114
+ import_react_native2.ScrollView,
1115
+ {
1116
+ bounces: false,
1117
+ keyboardShouldPersistTaps: "handled",
1118
+ contentContainerStyle: styles.content,
1119
+ children: [
1120
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.body, children: [
1121
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.hero, children: [
1122
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.iconDisc, { backgroundColor: colors.surface }], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MailIcon, { color: colors.text }) }),
1123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.heroText, children: [
1124
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { accessibilityRole: "header", style: [styles.title, { color: colors.text }], children: copy.title }),
1125
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [styles.description, { color: colors.mutedText }], children: copy.description })
1126
+ ] })
1127
+ ] }),
1128
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { children: [
1129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1130
+ import_react_native2.Animated.View,
1131
+ {
1132
+ accessibilityElementsHidden: true,
1133
+ importantForAccessibility: "no-hide-descendants",
1134
+ style: [
1135
+ styles.cells,
1136
+ compact && styles.cellsCompact,
1137
+ submitting && styles.cellsBusy,
1138
+ { transform: [{ translateX: shake }] }
1139
+ ],
1140
+ children: cells
1141
+ }
1142
+ ),
1143
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1144
+ import_react_native2.TextInput,
1145
+ {
1146
+ ref: inputRef,
1147
+ autoFocus: true,
1148
+ value: code,
1149
+ onChangeText: changeCode,
1150
+ onSubmitEditing: () => submit(),
1151
+ onFocus: () => setFocused(true),
1152
+ onBlur: () => setFocused(false),
1153
+ keyboardType: "number-pad",
1154
+ textContentType: "oneTimeCode",
1155
+ autoComplete: "sms-otp",
1156
+ autoCorrect: false,
1157
+ spellCheck: false,
1158
+ caretHidden: true,
1159
+ selectionColor: colors.accent,
1160
+ accessibilityLabel: copy.codeLabel,
1161
+ returnKeyType: "done",
1162
+ style: styles.codeInput
1163
+ }
1164
+ )
1165
+ ] }),
1166
+ error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.error, accessibilityLiveRegion: "polite", children: [
1167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertIcon, { color: colors.error }),
1168
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [styles.errorText, { color: colors.error }], children: error })
1169
+ ] })
1170
+ ] }),
1171
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.actions, children: [
1172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1173
+ import_react_native2.Pressable,
1174
+ {
1175
+ onPress: () => submit(),
1176
+ disabled: !complete || submitting,
1177
+ accessibilityRole: "button",
1178
+ accessibilityState: { disabled: !complete || submitting, busy: submitting },
1179
+ style: ({ pressed }) => [
1180
+ styles.button,
1181
+ { backgroundColor: colors.accent },
1182
+ pressed && styles.pressed,
1183
+ !complete && !submitting && styles.disabled
1184
+ ],
1185
+ children: [
1186
+ submitting && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.ActivityIndicator, { size: "small", color: colors.accentText }),
1187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [styles.buttonText, { color: colors.accentText }], children: submitting ? copy.verifying : copy.verify })
1188
+ ]
1189
+ }
1190
+ ),
1191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1192
+ import_react_native2.Pressable,
1193
+ {
1194
+ onPress: close,
1195
+ disabled: submitting,
1196
+ accessibilityRole: "button",
1197
+ style: ({ pressed }) => [
1198
+ styles.button,
1199
+ pressed && { backgroundColor: colors.surface },
1200
+ submitting && styles.disabled
1201
+ ],
1202
+ children: ({ pressed }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1203
+ import_react_native2.Text,
1204
+ {
1205
+ style: [styles.buttonText, { color: pressed ? colors.text : colors.mutedText }],
1206
+ children: copy.cancel
1207
+ }
1208
+ )
1209
+ }
1210
+ ),
1211
+ copy.hint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [styles.hint, { color: colors.mutedText }], children: copy.hint }) : null
1212
+ ] })
1213
+ ]
1214
+ }
1215
+ )
1216
+ ]
1217
+ }
1218
+ )
1219
+ }
1220
+ )
895
1221
  }
896
1222
  );
897
1223
  };
898
- var styles = import_react_native.StyleSheet.create({
1224
+ var CloseIcon = ({ color }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.closeIcon, children: [
1225
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.closeBar, { backgroundColor: color, transform: [{ rotate: "45deg" }] }] }),
1226
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.closeBar, { backgroundColor: color, transform: [{ rotate: "-45deg" }] }] })
1227
+ ] });
1228
+ var MailIcon = ({ color }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.mailIcon, children: [
1229
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.mailBody, { borderColor: color }] }),
1230
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.mailFlap, styles.mailFlapLeft, { backgroundColor: color }] }),
1231
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.mailFlap, styles.mailFlapRight, { backgroundColor: color }] })
1232
+ ] });
1233
+ var AlertIcon = ({ color }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: [styles.alertIcon, { borderColor: color }], children: [
1234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.alertStem, { backgroundColor: color }] }),
1235
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.alertDot, { backgroundColor: color }] })
1236
+ ] });
1237
+ var styles = import_react_native2.StyleSheet.create({
899
1238
  backdrop: {
900
- flex: 1,
1239
+ flex: 1
1240
+ },
1241
+ backdropSheet: {
1242
+ justifyContent: "flex-end"
1243
+ },
1244
+ backdropCentered: {
901
1245
  alignItems: "center",
902
1246
  justifyContent: "center",
903
- padding: 16,
904
- backgroundColor: "rgba(0, 0, 0, 0.45)"
1247
+ padding: 16
905
1248
  },
906
1249
  card: {
907
1250
  width: "100%",
908
- maxWidth: 384,
909
- padding: 24,
910
- borderRadius: 14
1251
+ maxHeight: "100%",
1252
+ overflow: "hidden"
1253
+ },
1254
+ sheet: {
1255
+ borderTopLeftRadius: 24,
1256
+ borderTopRightRadius: 24,
1257
+ borderTopWidth: 1
1258
+ },
1259
+ centered: {
1260
+ maxWidth: 400,
1261
+ borderRadius: 24,
1262
+ borderWidth: 1
1263
+ },
1264
+ header: {
1265
+ flexDirection: "row",
1266
+ justifyContent: "flex-end",
1267
+ alignItems: "center",
1268
+ height: 56,
1269
+ paddingHorizontal: 16
1270
+ },
1271
+ iconButton: {
1272
+ width: 32,
1273
+ height: 32,
1274
+ borderRadius: 8,
1275
+ alignItems: "center",
1276
+ justifyContent: "center"
1277
+ },
1278
+ content: {
1279
+ paddingHorizontal: 24,
1280
+ // Clear of the home indicator when the keyboard is down.
1281
+ paddingBottom: 32
1282
+ },
1283
+ body: {
1284
+ gap: 16
1285
+ },
1286
+ hero: {
1287
+ alignItems: "center",
1288
+ gap: 16,
1289
+ paddingTop: 8
1290
+ },
1291
+ iconDisc: {
1292
+ width: 64,
1293
+ height: 64,
1294
+ borderRadius: 32,
1295
+ alignItems: "center",
1296
+ justifyContent: "center"
1297
+ },
1298
+ heroText: {
1299
+ width: "100%",
1300
+ gap: 4
911
1301
  },
912
1302
  title: {
913
1303
  fontSize: 20,
914
- fontWeight: "600"
1304
+ lineHeight: 24,
1305
+ fontWeight: "500",
1306
+ letterSpacing: -0.4,
1307
+ textAlign: "center"
915
1308
  },
916
- body: {
1309
+ description: {
917
1310
  fontSize: 14,
918
- marginTop: 8
1311
+ lineHeight: 20,
1312
+ textAlign: "center"
919
1313
  },
920
- input: {
921
- marginTop: 16,
922
- paddingVertical: 12,
923
- paddingHorizontal: 16,
1314
+ cells: {
1315
+ flexDirection: "row",
1316
+ alignItems: "center",
1317
+ justifyContent: "center",
1318
+ gap: 8
1319
+ },
1320
+ cellsCompact: {
1321
+ gap: 6
1322
+ },
1323
+ cellsBusy: {
1324
+ opacity: 0.6
1325
+ },
1326
+ cell: {
1327
+ width: 44,
1328
+ height: 52,
1329
+ borderWidth: 1,
924
1330
  borderRadius: 12,
925
- borderWidth: import_react_native.StyleSheet.hairlineWidth,
926
- fontSize: 24,
927
- letterSpacing: 8,
928
- textAlign: "center"
1331
+ alignItems: "center",
1332
+ justifyContent: "center"
1333
+ },
1334
+ cellCompact: {
1335
+ width: 38,
1336
+ height: 48
1337
+ },
1338
+ cellText: {
1339
+ fontSize: 18,
1340
+ fontWeight: "500",
1341
+ fontVariant: ["tabular-nums"]
1342
+ },
1343
+ caret: {
1344
+ width: 1.5,
1345
+ height: 20,
1346
+ borderRadius: 1
1347
+ },
1348
+ separator: {
1349
+ width: 4,
1350
+ height: 4,
1351
+ borderRadius: 2,
1352
+ marginHorizontal: 4,
1353
+ opacity: 0.6
1354
+ },
1355
+ codeInput: {
1356
+ position: "absolute",
1357
+ top: 0,
1358
+ right: 0,
1359
+ bottom: 0,
1360
+ left: 0,
1361
+ // Not 0: iOS stops delivering touches to a view that is fully transparent.
1362
+ opacity: 0.015,
1363
+ color: "transparent",
1364
+ backgroundColor: "transparent",
1365
+ borderWidth: 0
929
1366
  },
930
1367
  error: {
931
- fontSize: 13,
932
- marginTop: 8
1368
+ flexDirection: "row",
1369
+ alignItems: "center",
1370
+ justifyContent: "center",
1371
+ gap: 4
933
1372
  },
934
- primaryButton: {
935
- marginTop: 16,
936
- paddingVertical: 12,
937
- borderRadius: 12,
938
- alignItems: "center"
1373
+ errorText: {
1374
+ flexShrink: 1,
1375
+ fontSize: 12,
1376
+ fontWeight: "500",
1377
+ textAlign: "center"
939
1378
  },
940
- primaryButtonDisabled: {
941
- opacity: 0.5
1379
+ actions: {
1380
+ gap: 8,
1381
+ paddingTop: 24
942
1382
  },
943
- primaryButtonText: {
1383
+ button: {
1384
+ flexDirection: "row",
1385
+ alignItems: "center",
1386
+ justifyContent: "center",
1387
+ gap: 8,
1388
+ height: 48,
1389
+ paddingHorizontal: 20,
1390
+ borderRadius: 999
1391
+ },
1392
+ buttonText: {
944
1393
  fontSize: 16,
945
- fontWeight: "600"
1394
+ fontWeight: "500"
946
1395
  },
947
- ghostButton: {
948
- marginTop: 8,
949
- paddingVertical: 12,
950
- alignItems: "center"
1396
+ pressed: {
1397
+ opacity: 0.88,
1398
+ transform: [{ scale: 0.985 }]
951
1399
  },
952
- ghostButtonText: {
953
- fontSize: 15,
954
- fontWeight: "500"
1400
+ disabled: {
1401
+ opacity: 0.5
955
1402
  },
956
1403
  hint: {
957
1404
  fontSize: 12,
958
- marginTop: 4,
1405
+ lineHeight: 16,
959
1406
  textAlign: "center"
1407
+ },
1408
+ closeIcon: {
1409
+ width: 16,
1410
+ height: 16,
1411
+ alignItems: "center",
1412
+ justifyContent: "center"
1413
+ },
1414
+ closeBar: {
1415
+ position: "absolute",
1416
+ width: 12,
1417
+ height: 1.5,
1418
+ borderRadius: 1
1419
+ },
1420
+ mailIcon: {
1421
+ width: 28,
1422
+ height: 28
1423
+ },
1424
+ mailBody: {
1425
+ position: "absolute",
1426
+ top: 5,
1427
+ left: 2,
1428
+ width: 24,
1429
+ height: 18,
1430
+ borderWidth: 2,
1431
+ borderRadius: 3
1432
+ },
1433
+ mailFlap: {
1434
+ position: "absolute",
1435
+ top: 10.6,
1436
+ width: 13,
1437
+ height: 2,
1438
+ borderRadius: 1
1439
+ },
1440
+ mailFlapLeft: {
1441
+ left: 2,
1442
+ transform: [{ rotate: "29.8deg" }]
1443
+ },
1444
+ mailFlapRight: {
1445
+ left: 13,
1446
+ transform: [{ rotate: "-29.8deg" }]
1447
+ },
1448
+ alertIcon: {
1449
+ width: 14,
1450
+ height: 14,
1451
+ borderRadius: 7,
1452
+ borderWidth: 1.25,
1453
+ alignItems: "center",
1454
+ justifyContent: "center",
1455
+ gap: 1
1456
+ },
1457
+ alertStem: {
1458
+ width: 1.5,
1459
+ height: 4,
1460
+ borderRadius: 1
1461
+ },
1462
+ alertDot: {
1463
+ width: 1.5,
1464
+ height: 1.5,
1465
+ borderRadius: 1
960
1466
  }
961
1467
  });
962
1468
 
963
1469
  // src/transport/webview-bridge.ts
964
- var import_utils3 = require("@moon-x/core/utils");
1470
+ var import_utils4 = require("@moon-x/core/utils");
965
1471
  var RETRYABLE_METHODS = /* @__PURE__ */ new Set([
966
1472
  "GET_APP_CONFIG",
967
1473
  "GET_BALANCE",
@@ -979,9 +1485,14 @@ var RETRYABLE_METHODS = /* @__PURE__ */ new Set([
979
1485
  var RETRY_ATTEMPT_TIMEOUTS_MS = [
980
1486
  5e3,
981
1487
  1e4,
982
- import_utils3.POST_MESSAGE_REQUEST_TIMEOUT_MS
1488
+ import_utils4.POST_MESSAGE_REQUEST_TIMEOUT_MS
983
1489
  ];
984
1490
  var RETRY_BACKOFF_MS = [200, 400];
1491
+ var isRetryableRead = (method, payload) => {
1492
+ const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1493
+ const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1494
+ return RETRYABLE_METHODS.has(method) && !isSigningPreparation && !isResumeCheck;
1495
+ };
985
1496
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
986
1497
  var TimeoutError = class extends Error {
987
1498
  constructor(message) {
@@ -1064,7 +1575,7 @@ var WebViewBridge = class {
1064
1575
  resolver.resolve(message.data);
1065
1576
  } else {
1066
1577
  const err = new Error(message.error || "WebView bridge error");
1067
- for (const key of import_utils3.FORWARDED_ERROR_FIELDS) {
1578
+ for (const key of import_utils4.FORWARDED_ERROR_FIELDS) {
1068
1579
  const value = message[key];
1069
1580
  if (value !== void 0) {
1070
1581
  err[key] = value;
@@ -1117,14 +1628,12 @@ var WebViewBridge = class {
1117
1628
  // Idempotent reads (see RETRYABLE_METHODS) are auto-retried on timeout to
1118
1629
  // ride out the iframe-app mount race; everything else makes a single attempt.
1119
1630
  async send(type, method, payload) {
1120
- const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1121
- const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1122
- if (isSigningPreparation || isResumeCheck || !RETRYABLE_METHODS.has(method)) {
1631
+ if (!isRetryableRead(method, payload)) {
1123
1632
  return this.sendOnce(
1124
1633
  type,
1125
1634
  method,
1126
1635
  payload,
1127
- (0, import_utils3.getPostMessageRequestTimeout)(method)
1636
+ (0, import_utils4.getPostMessageRequestTimeout)(method)
1128
1637
  );
1129
1638
  }
1130
1639
  let lastError;
@@ -1134,7 +1643,8 @@ var WebViewBridge = class {
1134
1643
  type,
1135
1644
  method,
1136
1645
  payload,
1137
- RETRY_ATTEMPT_TIMEOUTS_MS[attempt]
1646
+ RETRY_ATTEMPT_TIMEOUTS_MS[attempt],
1647
+ attempt < RETRY_ATTEMPT_TIMEOUTS_MS.length - 1
1138
1648
  );
1139
1649
  } catch (error) {
1140
1650
  lastError = error;
@@ -1145,7 +1655,7 @@ var WebViewBridge = class {
1145
1655
  }
1146
1656
  throw lastError;
1147
1657
  }
1148
- sendOnce(type, method, payload, timeoutMs) {
1658
+ sendOnce(type, method, payload, timeoutMs, retryOnReady = false) {
1149
1659
  const ref = this.webViewRef.current;
1150
1660
  if (!ref) {
1151
1661
  return Promise.reject(new Error("webview_not_ready"));
@@ -1165,7 +1675,8 @@ var WebViewBridge = class {
1165
1675
  reject,
1166
1676
  timeoutId,
1167
1677
  type,
1168
- method
1678
+ method,
1679
+ retryOnReady
1169
1680
  });
1170
1681
  const envelope = { id, type, method, payload };
1171
1682
  try {
@@ -1206,8 +1717,15 @@ var WebViewBridge = class {
1206
1717
  rejectAllPending(reason) {
1207
1718
  this.rejectPending(() => new TimeoutError(reason));
1208
1719
  }
1209
- rejectPending(createError) {
1720
+ retryPendingReads() {
1721
+ this.rejectPending(
1722
+ () => new TimeoutError("webview_ready"),
1723
+ (resolver) => resolver.retryOnReady
1724
+ );
1725
+ }
1726
+ rejectPending(createError, shouldReject = () => true) {
1210
1727
  for (const [id, resolver] of this.pending.entries()) {
1728
+ if (!shouldReject(resolver)) continue;
1211
1729
  clearTimeout(resolver.timeoutId);
1212
1730
  resolver.reject(createError());
1213
1731
  this.pending.delete(id);
@@ -1224,7 +1742,7 @@ var WebViewBridge = class {
1224
1742
  };
1225
1743
 
1226
1744
  // src/provider.tsx
1227
- var import_react3 = require("@moon-x/core/react");
1745
+ var import_react4 = require("@moon-x/core/react");
1228
1746
  var import_lib2 = require("@moon-x/core/lib");
1229
1747
 
1230
1748
  // src/webview-lifecycle.ts
@@ -1462,7 +1980,7 @@ function createNativeSession(reads) {
1462
1980
 
1463
1981
  // src/session-resume.ts
1464
1982
  var import_sdk10 = require("@moon-x/core/sdk");
1465
- var import_utils4 = require("@moon-x/core/utils");
1983
+ var import_utils5 = require("@moon-x/core/utils");
1466
1984
  var LOGOUT_TOMBSTONE = '{"loggedOut":true}';
1467
1985
  var sharedStates = /* @__PURE__ */ new Map();
1468
1986
  var sharedState = (publishableKey) => {
@@ -1646,8 +2164,8 @@ var createNativeSessionResume = ({
1646
2164
  let result = null;
1647
2165
  try {
1648
2166
  result = await bridge.send(
1649
- import_utils4.PostMessageType.AUTH,
1650
- import_utils4.PostMessageMethod.SESSION_RESUME_BIND,
2167
+ import_utils5.PostMessageType.AUTH,
2168
+ import_utils5.PostMessageMethod.SESSION_RESUME_BIND,
1651
2169
  { publishableKey, publicKey: record.publicKey }
1652
2170
  );
1653
2171
  } catch {
@@ -1670,8 +2188,8 @@ var createNativeSessionResume = ({
1670
2188
  const sessionId = record?.sessionId;
1671
2189
  if (!record || !sessionId) return false;
1672
2190
  const check = await bridge.send(
1673
- import_utils4.PostMessageType.AUTH,
1674
- import_utils4.PostMessageMethod.IS_AUTHENTICATED,
2191
+ import_utils5.PostMessageType.AUTH,
2192
+ import_utils5.PostMessageMethod.IS_AUTHENTICATED,
1675
2193
  { publishableKey, resumeSessionId: sessionId }
1676
2194
  );
1677
2195
  if (check?.isAuthenticated === true) return true;
@@ -1684,8 +2202,8 @@ var createNativeSessionResume = ({
1684
2202
  const signature = (0, import_sdk10.signSessionResume)(record.privateKey, sessionId, challenge);
1685
2203
  if (!signature) return false;
1686
2204
  const resumed = await bridge.send(
1687
- import_utils4.PostMessageType.AUTH,
1688
- import_utils4.PostMessageMethod.SESSION_RESUME,
2205
+ import_utils5.PostMessageType.AUTH,
2206
+ import_utils5.PostMessageMethod.SESSION_RESUME,
1689
2207
  { publishableKey, sessionId, challenge, signature }
1690
2208
  );
1691
2209
  if (resumed?.resumeRejected) {
@@ -1759,7 +2277,7 @@ var createNativeSessionResume = ({
1759
2277
  // src/provider.tsx
1760
2278
  var import_jsx_runtime2 = require("react/jsx-runtime");
1761
2279
  var DEFAULT_IFRAME_URL = "https://x-iframe.moonpay.com";
1762
- var MoonXContext = (0, import_react2.createContext)(null);
2280
+ var MoonXContext = (0, import_react3.createContext)(null);
1763
2281
  var MoonXProvider = ({
1764
2282
  publishableKey,
1765
2283
  config,
@@ -1771,20 +2289,20 @@ var MoonXProvider = ({
1771
2289
  var NativeProvider = ({ publishableKey, config, children }) => {
1772
2290
  const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
1773
2291
  const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
1774
- const webViewRef = (0, import_react2.useRef)(null);
1775
- const bridge = (0, import_react2.useMemo)(
2292
+ const webViewRef = (0, import_react3.useRef)(null);
2293
+ const bridge = (0, import_react3.useMemo)(
1776
2294
  () => new WebViewBridge(
1777
2295
  webViewRef
1778
2296
  ),
1779
2297
  []
1780
2298
  );
1781
- const relyingPartyOriginResolver = (0, import_react2.useMemo)(
2299
+ const relyingPartyOriginResolver = (0, import_react3.useMemo)(
1782
2300
  () => makeRelyingPartyOriginResolver(bridge, publishableKey, relyingPartyOrigin),
1783
2301
  [bridge, publishableKey, relyingPartyOrigin]
1784
2302
  );
1785
- const [sensitiveVisible, setSensitiveVisible] = (0, import_react2.useState)(false);
1786
- const [captchaChallengeVisible, setCaptchaChallengeVisible] = (0, import_react2.useState)(false);
1787
- const cancelRef = (0, import_react2.useRef)(null);
2303
+ const [sensitiveVisible, setSensitiveVisible] = (0, import_react3.useState)(false);
2304
+ const [captchaChallengeVisible, setCaptchaChallengeVisible] = (0, import_react3.useState)(false);
2305
+ const cancelRef = (0, import_react3.useRef)(null);
1788
2306
  const webViewVisible = sensitiveVisible || captchaChallengeVisible;
1789
2307
  const [
1790
2308
  {
@@ -1793,9 +2311,9 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1793
2311
  key: webViewKey
1794
2312
  },
1795
2313
  dispatchWebViewLifecycle
1796
- ] = (0, import_react2.useReducer)(webViewLifecycleReducer, initialWebViewLifecycleState);
2314
+ ] = (0, import_react3.useReducer)(webViewLifecycleReducer, initialWebViewLifecycleState);
1797
2315
  const sessionResumeStorage = config?.sessionResumeStorage;
1798
- const sessionResume = (0, import_react2.useMemo)(
2316
+ const sessionResume = (0, import_react3.useMemo)(
1799
2317
  () => sessionResumeStorage ? createNativeSessionResume({
1800
2318
  bridge,
1801
2319
  publishableKey,
@@ -1804,67 +2322,67 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1804
2322
  }) : void 0,
1805
2323
  [bridge, publishableKey, sessionResumeStorage]
1806
2324
  );
1807
- const session = (0, import_react2.useMemo)(
2325
+ const session = (0, import_react3.useMemo)(
1808
2326
  () => createNativeSession({
1809
- getCurrentSession: () => bridge.send(import_utils5.PostMessageType.AUTH, import_utils5.PostMessageMethod.GET_CURRENT_SESSION, { publishableKey }),
1810
- getUser: () => bridge.send(import_utils5.PostMessageType.AUTH, import_utils5.PostMessageMethod.GET_USER, { publishableKey }),
2327
+ getCurrentSession: () => bridge.send(import_utils6.PostMessageType.AUTH, import_utils6.PostMessageMethod.GET_CURRENT_SESSION, { publishableKey }),
2328
+ getUser: () => bridge.send(import_utils6.PostMessageType.AUTH, import_utils6.PostMessageMethod.GET_USER, { publishableKey }),
1811
2329
  resume: sessionResume?.resume
1812
2330
  }),
1813
2331
  [bridge, publishableKey, sessionResume]
1814
2332
  );
1815
- const sessionSnapshot = (0, import_react2.useSyncExternalStore)(session.subscribe, session.getSnapshot, session.getSnapshot);
2333
+ const sessionSnapshot = (0, import_react3.useSyncExternalStore)(session.subscribe, session.getSnapshot, session.getSnapshot);
1816
2334
  const { isAuthenticated, user, revalidatedAt } = sessionSnapshot;
1817
2335
  const { beginAuthFlow, refreshUser } = session;
1818
- (0, import_react2.useLayoutEffect)(() => {
2336
+ (0, import_react3.useLayoutEffect)(() => {
1819
2337
  session.mount();
1820
2338
  return session.unmount;
1821
2339
  }, [session]);
1822
- (0, import_react2.useEffect)(() => {
2340
+ (0, import_react3.useEffect)(() => {
1823
2341
  session.setReady(ready);
1824
2342
  }, [session, ready]);
1825
2343
  const { sessionStatus } = sessionSnapshot;
1826
- (0, import_react2.useEffect)(() => {
2344
+ (0, import_react3.useEffect)(() => {
1827
2345
  if (!sessionResume || !ready || sessionStatus !== "authenticated") return;
1828
2346
  void sessionResume.bind();
1829
2347
  }, [sessionResume, ready, sessionStatus, revalidatedAt]);
1830
- (0, import_react2.useEffect)(() => {
1831
- const subscription = import_react_native2.AppState.addEventListener("change", (nextState) => {
2348
+ (0, import_react3.useEffect)(() => {
2349
+ const subscription = import_react_native3.AppState.addEventListener("change", (nextState) => {
1832
2350
  if (nextState === "active") {
1833
2351
  session.restartSession();
1834
2352
  }
1835
2353
  });
1836
2354
  return () => subscription.remove();
1837
2355
  }, [session]);
1838
- const { height: screenHeight } = (0, import_react_native2.useWindowDimensions)();
2356
+ const { height: screenHeight } = (0, import_react_native3.useWindowDimensions)();
1839
2357
  const SHEET_TOP_OFFSET = 80;
1840
- const sheetTranslateY = (0, import_react2.useRef)(new import_react_native2.Animated.Value(screenHeight)).current;
1841
- const backdropOpacity = (0, import_react2.useRef)(new import_react_native2.Animated.Value(0)).current;
1842
- (0, import_react2.useEffect)(() => {
1843
- import_react_native2.Animated.parallel([
1844
- import_react_native2.Animated.timing(sheetTranslateY, {
2358
+ const sheetTranslateY = (0, import_react3.useRef)(new import_react_native3.Animated.Value(screenHeight)).current;
2359
+ const backdropOpacity = (0, import_react3.useRef)(new import_react_native3.Animated.Value(0)).current;
2360
+ (0, import_react3.useEffect)(() => {
2361
+ import_react_native3.Animated.parallel([
2362
+ import_react_native3.Animated.timing(sheetTranslateY, {
1845
2363
  toValue: webViewVisible ? 0 : screenHeight,
1846
2364
  duration: 280,
1847
2365
  useNativeDriver: true
1848
2366
  }),
1849
- import_react_native2.Animated.timing(backdropOpacity, {
2367
+ import_react_native3.Animated.timing(backdropOpacity, {
1850
2368
  toValue: webViewVisible ? 0.5 : 0,
1851
2369
  duration: 280,
1852
2370
  useNativeDriver: true
1853
2371
  })
1854
2372
  ]).start();
1855
2373
  }, [webViewVisible, sheetTranslateY, backdropOpacity, screenHeight]);
1856
- const initialSourceUri = (0, import_react2.useMemo)(() => {
2374
+ const initialSourceUri = (0, import_react3.useMemo)(() => {
1857
2375
  const base = iframeUrl.replace(/\/$/, "");
1858
2376
  const sep = base.includes("?") ? "&" : "?";
1859
2377
  return `${base}${sep}publishableKey=${encodeURIComponent(publishableKey)}`;
1860
2378
  }, [iframeUrl, publishableKey]);
1861
- const handleMessage = (0, import_react2.useCallback)(
2379
+ const handleMessage = (0, import_react3.useCallback)(
1862
2380
  (event) => {
1863
2381
  bridge.handleMessage({ nativeEvent: { data: event.nativeEvent.data } });
1864
2382
  },
1865
2383
  [bridge]
1866
2384
  );
1867
- const navigateWebView = (0, import_react2.useCallback)(
2385
+ const navigateWebView = (0, import_react3.useCallback)(
1868
2386
  (path) => {
1869
2387
  const ref = webViewRef.current;
1870
2388
  if (!ref) return;
@@ -1879,7 +2397,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1879
2397
  },
1880
2398
  [iframeUrl, publishableKey]
1881
2399
  );
1882
- const runSensitiveFlow = (0, import_react2.useCallback)(
2400
+ const runSensitiveFlow = (0, import_react3.useCallback)(
1883
2401
  (options) => {
1884
2402
  setSensitiveVisible(true);
1885
2403
  navigateWebView(options.flowPath);
@@ -1921,7 +2439,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1921
2439
  },
1922
2440
  [bridge, navigateWebView]
1923
2441
  );
1924
- const sdk = (0, import_react2.useMemo)(
2442
+ const sdk = (0, import_react3.useMemo)(
1925
2443
  () => createSdkInstance({
1926
2444
  bridge,
1927
2445
  publishableKey,
@@ -1953,18 +2471,18 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1953
2471
  sessionSnapshot
1954
2472
  ]
1955
2473
  );
1956
- const sessionResumeRef = (0, import_react2.useRef)(sessionResume);
2474
+ const sessionResumeRef = (0, import_react3.useRef)(sessionResume);
1957
2475
  sessionResumeRef.current = sessionResume;
1958
- (0, import_react2.useEffect)(() => {
2476
+ (0, import_react3.useEffect)(() => {
1959
2477
  return () => {
1960
2478
  sessionResumeRef.current?.cancelPendingBinds();
1961
2479
  bridge.cleanup("provider_unmounted");
1962
2480
  };
1963
2481
  }, [bridge]);
1964
- (0, import_react2.useEffect)(
2482
+ (0, import_react3.useEffect)(
1965
2483
  () => bridge.register(
1966
- import_utils5.PostMessageType.INIT,
1967
- import_utils5.PostMessageMethod.CAPTCHA_CHALLENGE_VISIBILITY,
2484
+ import_utils6.PostMessageType.INIT,
2485
+ import_utils6.PostMessageMethod.CAPTCHA_CHALLENGE_VISIBILITY,
1968
2486
  (payload) => {
1969
2487
  if (typeof payload?.visible === "boolean") {
1970
2488
  setCaptchaChallengeVisible(payload.visible);
@@ -1973,23 +2491,30 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1973
2491
  ),
1974
2492
  [bridge]
1975
2493
  );
1976
- (0, import_react2.useEffect)(() => {
2494
+ (0, import_react3.useEffect)(() => {
1977
2495
  const unsubscribe = bridge.onResponseError((error) => {
1978
2496
  if (error.message === "no_session") session.retrySession();
1979
2497
  });
1980
2498
  return unsubscribe;
1981
2499
  }, [bridge, session]);
1982
- (0, import_react2.useEffect)(() => {
2500
+ (0, import_react3.useEffect)(() => {
1983
2501
  let cancelled = false;
2502
+ let readinessSource = "pending";
1984
2503
  const unregister = bridge.register(
1985
- import_utils5.PostMessageType.INIT,
1986
- import_utils5.PostMessageMethod.READY,
2504
+ import_utils6.PostMessageType.INIT,
2505
+ import_utils6.PostMessageMethod.READY,
1987
2506
  () => {
1988
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2507
+ if (cancelled || readinessSource === "page") return;
2508
+ const retryPendingReads = readinessSource === "fallback";
2509
+ readinessSource = "page";
2510
+ dispatchWebViewLifecycle({ type: "ready" });
2511
+ if (retryPendingReads) bridge.retryPendingReads();
1989
2512
  }
1990
2513
  );
1991
2514
  const fallback = setTimeout(() => {
1992
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2515
+ if (cancelled || readinessSource !== "pending") return;
2516
+ readinessSource = "fallback";
2517
+ dispatchWebViewLifecycle({ type: "ready" });
1993
2518
  }, 2e3);
1994
2519
  return () => {
1995
2520
  cancelled = true;
@@ -1997,7 +2522,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1997
2522
  clearTimeout(fallback);
1998
2523
  };
1999
2524
  }, [bridge, webViewRecoveryNonce]);
2000
- const contextValue = (0, import_react2.useMemo)(
2525
+ const contextValue = (0, import_react3.useMemo)(
2001
2526
  () => ({
2002
2527
  sdk,
2003
2528
  _bridge: bridge,
@@ -2016,7 +2541,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2016
2541
  ]
2017
2542
  );
2018
2543
  const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
2019
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react3.SDKProvider, { value: sdk, children: [
2544
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react4.SDKProvider, { value: sdk, children: [
2020
2545
  children,
2021
2546
  config?.presenceOtpPrompt !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2022
2547
  PresenceOtpPrompt,
@@ -2026,14 +2551,14 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2026
2551
  }
2027
2552
  ),
2028
2553
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2029
- import_react_native2.Animated.View,
2554
+ import_react_native3.Animated.View,
2030
2555
  {
2031
2556
  style: [styles2.backdrop, { opacity: backdropOpacity }],
2032
2557
  pointerEvents: webViewVisible ? "auto" : "none",
2033
2558
  children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2034
- import_react_native2.Pressable,
2559
+ import_react_native3.Pressable,
2035
2560
  {
2036
- style: import_react_native2.StyleSheet.absoluteFill,
2561
+ style: import_react_native3.StyleSheet.absoluteFill,
2037
2562
  onPress: () => {
2038
2563
  if (sensitiveVisible) cancelRef.current?.();
2039
2564
  }
@@ -2042,7 +2567,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2042
2567
  }
2043
2568
  ),
2044
2569
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2045
- import_react_native2.Animated.View,
2570
+ import_react_native3.Animated.View,
2046
2571
  {
2047
2572
  style: [
2048
2573
  styles2.sheetContainer,
@@ -2054,16 +2579,16 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2054
2579
  pointerEvents: webViewVisible ? "auto" : "none",
2055
2580
  children: [
2056
2581
  sensitiveVisible && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
2057
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.sheetGrabber }),
2058
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles2.modalChrome, children: [
2059
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.modalTitleSpacer }),
2582
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native3.View, { style: styles2.sheetGrabber }),
2583
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native3.View, { style: styles2.modalChrome, children: [
2584
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native3.View, { style: styles2.modalTitleSpacer }),
2060
2585
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2061
- import_react_native2.Pressable,
2586
+ import_react_native3.Pressable,
2062
2587
  {
2063
2588
  onPress: () => cancelRef.current?.(),
2064
2589
  hitSlop: 12,
2065
2590
  style: styles2.closeButton,
2066
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.closeButtonText, children: closeLabel })
2591
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native3.Text, { style: styles2.closeButtonText, children: closeLabel })
2067
2592
  }
2068
2593
  )
2069
2594
  ] })
@@ -2090,8 +2615,8 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2090
2615
  webviewDebuggingEnabled: __DEV__,
2091
2616
  javaScriptEnabled: true,
2092
2617
  domStorageEnabled: true,
2093
- sharedCookiesEnabled: import_react_native2.Platform.OS === "ios",
2094
- thirdPartyCookiesEnabled: import_react_native2.Platform.OS === "android",
2618
+ sharedCookiesEnabled: import_react_native3.Platform.OS === "ios",
2619
+ thirdPartyCookiesEnabled: import_react_native3.Platform.OS === "android",
2095
2620
  startInLoadingState: false,
2096
2621
  originWhitelist: ["https://*", "http://*"],
2097
2622
  style: styles2.webView
@@ -2104,13 +2629,13 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2104
2629
  ] }) });
2105
2630
  };
2106
2631
  var useMoonXContext = () => {
2107
- const ctx = (0, import_react2.useContext)(MoonXContext);
2632
+ const ctx = (0, import_react3.useContext)(MoonXContext);
2108
2633
  if (!ctx) {
2109
2634
  throw new Error("useMoonX must be used within a MoonXProvider");
2110
2635
  }
2111
2636
  return ctx;
2112
2637
  };
2113
- var styles2 = import_react_native2.StyleSheet.create({
2638
+ var styles2 = import_react_native3.StyleSheet.create({
2114
2639
  backdrop: {
2115
2640
  position: "absolute",
2116
2641
  top: 0,
@@ -2160,7 +2685,7 @@ var styles2 = import_react_native2.StyleSheet.create({
2160
2685
  paddingBottom: 12,
2161
2686
  paddingHorizontal: 16,
2162
2687
  backgroundColor: "#0a0a0a",
2163
- borderBottomWidth: import_react_native2.StyleSheet.hairlineWidth,
2688
+ borderBottomWidth: import_react_native3.StyleSheet.hairlineWidth,
2164
2689
  borderBottomColor: "#222"
2165
2690
  },
2166
2691
  // Empty flex spacer keeps the close button right-aligned without
@@ -2182,19 +2707,19 @@ var styles2 = import_react_native2.StyleSheet.create({
2182
2707
  });
2183
2708
 
2184
2709
  // src/hooks/index.ts
2185
- var import_react9 = require("@moon-x/core/react");
2710
+ var import_react10 = require("@moon-x/core/react");
2186
2711
 
2187
2712
  // src/hooks/use-app-config.ts
2188
- var import_utils6 = require("@moon-x/core/utils");
2189
- var import_react4 = require("react");
2713
+ var import_utils7 = require("@moon-x/core/utils");
2714
+ var import_react5 = require("react");
2190
2715
  var useAppConfig = (publishableKey) => {
2191
2716
  const { sdk, _bridge } = useMoonXContext();
2192
2717
  const resolvedKey = publishableKey ?? sdk.publishableKey;
2193
2718
  const ready = sdk.ready;
2194
- const [appConfig, setAppConfig] = (0, import_react4.useState)(null);
2195
- const [isLoading, setIsLoading] = (0, import_react4.useState)(true);
2196
- const [error, setError] = (0, import_react4.useState)(null);
2197
- (0, import_react4.useEffect)(() => {
2719
+ const [appConfig, setAppConfig] = (0, import_react5.useState)(null);
2720
+ const [isLoading, setIsLoading] = (0, import_react5.useState)(true);
2721
+ const [error, setError] = (0, import_react5.useState)(null);
2722
+ (0, import_react5.useEffect)(() => {
2198
2723
  if (!resolvedKey) {
2199
2724
  setIsLoading(false);
2200
2725
  return;
@@ -2208,7 +2733,7 @@ var useAppConfig = (publishableKey) => {
2208
2733
  setError(null);
2209
2734
  setAppConfig(null);
2210
2735
  try {
2211
- const config = await _bridge.send(import_utils6.PostMessageType.AUTH, import_utils6.PostMessageMethod.GET_APP_CONFIG, {
2736
+ const config = await _bridge.send(import_utils7.PostMessageType.AUTH, import_utils7.PostMessageMethod.GET_APP_CONFIG, {
2212
2737
  publishableKey: resolvedKey
2213
2738
  });
2214
2739
  if (!cancelled) setAppConfig(config);
@@ -2229,8 +2754,7 @@ var useAppConfig = (publishableKey) => {
2229
2754
  };
2230
2755
 
2231
2756
  // src/hooks/use-attach-oauth.ts
2232
- var import_utils7 = require("@moon-x/core/utils");
2233
- var import_react5 = require("react");
2757
+ var import_react6 = require("react");
2234
2758
 
2235
2759
  // src/lib/oauth-deep-link.ts
2236
2760
  var openOAuthFlow = async ({
@@ -2270,8 +2794,8 @@ var parseOAuthRedirect = async (redirectUrl) => {
2270
2794
 
2271
2795
  // src/hooks/use-attach-oauth.ts
2272
2796
  var useAttachOAuth = (params) => {
2273
- const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
2274
- const [state, setState] = (0, import_react5.useState)({ status: "idle" });
2797
+ const { sdk, _oauthRedirectUri } = useMoonXContext();
2798
+ const [state, setState] = (0, import_react6.useState)({ status: "idle" });
2275
2799
  return {
2276
2800
  state,
2277
2801
  attachOAuth: async (provider) => {
@@ -2279,15 +2803,9 @@ var useAttachOAuth = (params) => {
2279
2803
  try {
2280
2804
  const redirectUri = params?.redirectUri || _oauthRedirectUri;
2281
2805
  if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
2282
- const startResult = await _bridge.send(
2283
- import_utils7.PostMessageType.AUTH,
2284
- import_utils7.PostMessageMethod.START_OAUTH,
2285
- {
2286
- publishableKey: sdk.publishableKey,
2287
- provider,
2288
- attach: true,
2289
- login_redirect_url: redirectUri
2290
- }
2806
+ const startResult = await sdk.beginOAuthLink(
2807
+ provider,
2808
+ redirectUri
2291
2809
  );
2292
2810
  if (!startResult.redirect_url) {
2293
2811
  throw new Error("start_oauth_failed");
@@ -2299,18 +2817,16 @@ var useAttachOAuth = (params) => {
2299
2817
  });
2300
2818
  const parsed = await parseOAuthRedirect(redirectUrl);
2301
2819
  if (parsed.error) throw new Error(parsed.error);
2820
+ if (!parsed.code && !parsed.token) {
2821
+ throw new Error("oauth_no_code_or_token");
2822
+ }
2302
2823
  setState({ status: "verifying" });
2303
- await _bridge.send(
2304
- import_utils7.PostMessageType.AUTH,
2305
- import_utils7.PostMessageMethod.ATTACH_OAUTH,
2306
- {
2307
- publishableKey: sdk.publishableKey,
2308
- provider,
2309
- code: parsed.code,
2310
- token: parsed.token,
2311
- state: parsed.state
2312
- }
2313
- );
2824
+ await sdk.verifyOAuthLink({
2825
+ provider,
2826
+ code: parsed.code,
2827
+ token: parsed.token,
2828
+ state: parsed.state
2829
+ });
2314
2830
  setState({ status: "complete" });
2315
2831
  } catch (e) {
2316
2832
  const err = e instanceof Error ? e : new Error(String(e));
@@ -2323,23 +2839,22 @@ var useAttachOAuth = (params) => {
2323
2839
  };
2324
2840
 
2325
2841
  // src/hooks/use-detach-oauth.ts
2326
- var import_utils8 = require("@moon-x/core/utils");
2327
2842
  var useDetachOAuth = () => {
2328
- const { sdk, _bridge } = useMoonXContext();
2843
+ const { sdk } = useMoonXContext();
2329
2844
  return {
2845
+ // Removes a Google or Apple sign-in by its id in the user's
2846
+ // linked_accounts, with the presence step-up first when the backend asks
2847
+ // for one. Rejects with last_login_method rather than leave the account
2848
+ // with no way to sign in.
2330
2849
  detachOAuth: async (idpUserId) => {
2331
- await _bridge.send(
2332
- import_utils8.PostMessageType.AUTH,
2333
- import_utils8.PostMessageMethod.DETACH_OAUTH,
2334
- { publishableKey: sdk.publishableKey, idpUserId }
2335
- );
2850
+ await sdk.detachOAuth(idpUserId);
2336
2851
  }
2337
2852
  };
2338
2853
  };
2339
2854
 
2340
2855
  // src/hooks/use-export-key.ts
2341
2856
  var import_sdk11 = require("@moon-x/core/sdk");
2342
- var import_utils9 = require("@moon-x/core/utils");
2857
+ var import_utils8 = require("@moon-x/core/utils");
2343
2858
  var parseExportKeyResult = (value) => {
2344
2859
  if (!value || typeof value !== "object" || !("status" in value)) {
2345
2860
  return { status: "failed", error: "invalid_export_key_result" };
@@ -2383,8 +2898,8 @@ var useExportKey = () => {
2383
2898
  title: "Export key",
2384
2899
  flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
2385
2900
  onMount: ({ bridge, setResult }) => bridge.register(
2386
- import_utils9.PostMessageType.WALLET,
2387
- import_utils9.PostMessageMethod.EXPORT_KEY_RESULT,
2901
+ import_utils8.PostMessageType.WALLET,
2902
+ import_utils8.PostMessageMethod.EXPORT_KEY_RESULT,
2388
2903
  (result) => {
2389
2904
  setResult(parseExportKeyResult(result));
2390
2905
  }
@@ -2407,13 +2922,13 @@ var useFundWallet = () => {
2407
2922
  };
2408
2923
 
2409
2924
  // src/hooks/use-login-with-email.ts
2410
- var import_react6 = require("@moon-x/core/react");
2411
- var import_react7 = require("react");
2925
+ var import_react7 = require("@moon-x/core/react");
2926
+ var import_react8 = require("react");
2412
2927
  var useLoginWithEmail = (callbacks) => {
2413
- const login = (0, import_react6.useLoginWithEmail)(callbacks);
2928
+ const login = (0, import_react7.useLoginWithEmail)(callbacks);
2414
2929
  const { _beginAuthFlow } = useMoonXContext();
2415
2930
  const coreLoginWithCode = login.loginWithCode;
2416
- const loginWithCode = (0, import_react7.useCallback)(
2931
+ const loginWithCode = (0, import_react8.useCallback)(
2417
2932
  async (params) => {
2418
2933
  const finishAuthFlow = _beginAuthFlow();
2419
2934
  try {
@@ -2428,14 +2943,14 @@ var useLoginWithEmail = (callbacks) => {
2428
2943
  };
2429
2944
 
2430
2945
  // src/hooks/use-login-with-oauth.ts
2431
- var import_utils10 = require("@moon-x/core/utils");
2432
- var import_react8 = require("react");
2946
+ var import_utils9 = require("@moon-x/core/utils");
2947
+ var import_react9 = require("react");
2433
2948
  var useLoginWithOAuth = (params) => {
2434
2949
  const { sdk, _bridge, _oauthRedirectUri, _beginAuthFlow } = useMoonXContext();
2435
- const [state, setState] = (0, import_react8.useState)({ status: "idle" });
2436
- const activeFlow = (0, import_react8.useRef)(null);
2437
- const mounted = (0, import_react8.useRef)(true);
2438
- (0, import_react8.useEffect)(() => {
2950
+ const [state, setState] = (0, import_react9.useState)({ status: "idle" });
2951
+ const activeFlow = (0, import_react9.useRef)(null);
2952
+ const mounted = (0, import_react9.useRef)(true);
2953
+ (0, import_react9.useEffect)(() => {
2439
2954
  mounted.current = true;
2440
2955
  return () => {
2441
2956
  mounted.current = false;
@@ -2462,8 +2977,8 @@ var useLoginWithOAuth = (params) => {
2462
2977
  throw new Error("oauth_redirect_uri_missing");
2463
2978
  }
2464
2979
  const startResult = await _bridge.send(
2465
- import_utils10.PostMessageType.AUTH,
2466
- import_utils10.PostMessageMethod.START_OAUTH,
2980
+ import_utils9.PostMessageType.AUTH,
2981
+ import_utils9.PostMessageMethod.START_OAUTH,
2467
2982
  {
2468
2983
  publishableKey: sdk.publishableKey,
2469
2984
  provider,
@@ -2510,17 +3025,17 @@ var useLoginWithOAuth = (params) => {
2510
3025
  var useMoonX = () => useMoonXContext().sdk;
2511
3026
 
2512
3027
  // src/external-wallets/use-external-wallets.ts
2513
- var import_react10 = require("react");
3028
+ var import_react11 = require("react");
2514
3029
  var useExternalWallets = (connectors) => {
2515
- const [wallets, setWallets] = (0, import_react10.useState)([]);
2516
- const [connected, setConnected] = (0, import_react10.useState)(
3030
+ const [wallets, setWallets] = (0, import_react11.useState)([]);
3031
+ const [connected, setConnected] = (0, import_react11.useState)(
2517
3032
  null
2518
3033
  );
2519
- const [status, setStatus] = (0, import_react10.useState)("idle");
2520
- const [error, setError] = (0, import_react10.useState)(null);
2521
- const [refreshNonce, setRefreshNonce] = (0, import_react10.useState)(0);
2522
- const unsubscribeRef = (0, import_react10.useRef)(null);
2523
- (0, import_react10.useEffect)(() => {
3034
+ const [status, setStatus] = (0, import_react11.useState)("idle");
3035
+ const [error, setError] = (0, import_react11.useState)(null);
3036
+ const [refreshNonce, setRefreshNonce] = (0, import_react11.useState)(0);
3037
+ const unsubscribeRef = (0, import_react11.useRef)(null);
3038
+ (0, import_react11.useEffect)(() => {
2524
3039
  let cancelled = false;
2525
3040
  void Promise.all(
2526
3041
  connectors.map(async (connector) => ({
@@ -2534,13 +3049,13 @@ var useExternalWallets = (connectors) => {
2534
3049
  cancelled = true;
2535
3050
  };
2536
3051
  }, [connectors, refreshNonce]);
2537
- (0, import_react10.useEffect)(
3052
+ (0, import_react11.useEffect)(
2538
3053
  () => () => {
2539
3054
  unsubscribeRef.current?.();
2540
3055
  },
2541
3056
  []
2542
3057
  );
2543
- const connect = (0, import_react10.useCallback)(
3058
+ const connect = (0, import_react11.useCallback)(
2544
3059
  async (id) => {
2545
3060
  const connector = connectors.find((candidate) => candidate.info.id === id);
2546
3061
  if (!connector) throw new Error(`External wallet "${id}" not found`);
@@ -2571,7 +3086,7 @@ var useExternalWallets = (connectors) => {
2571
3086
  },
2572
3087
  [connectors]
2573
3088
  );
2574
- const switchAccount = (0, import_react10.useCallback)(
3089
+ const switchAccount = (0, import_react11.useCallback)(
2575
3090
  async (address, chainId) => {
2576
3091
  if (!connected) throw new Error("No external wallet connected");
2577
3092
  const activeAccount = await connected.switchAccount(address, chainId);
@@ -2581,7 +3096,7 @@ var useExternalWallets = (connectors) => {
2581
3096
  },
2582
3097
  [connected]
2583
3098
  );
2584
- const disconnect = (0, import_react10.useCallback)(async () => {
3099
+ const disconnect = (0, import_react11.useCallback)(async () => {
2585
3100
  try {
2586
3101
  await connected?.disconnect();
2587
3102
  } finally {
@@ -2869,7 +3384,7 @@ var restoreWalletConnectSession = (options) => {
2869
3384
  // src/index.ts
2870
3385
  var import_sdk12 = require("@moon-x/core/sdk");
2871
3386
  var import_sdk13 = require("@moon-x/core/sdk");
2872
- var import_utils11 = require("@moon-x/core/utils");
3387
+ var import_utils10 = require("@moon-x/core/utils");
2873
3388
  // Annotate the CommonJS export names for ESM import in node:
2874
3389
  0 && (module.exports = {
2875
3390
  MOONPAY_CONSUMER_SESSION_ERROR_CODES,