@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.mjs CHANGED
@@ -3,22 +3,22 @@ import {
3
3
  createContext,
4
4
  useCallback,
5
5
  useContext,
6
- useEffect as useEffect2,
6
+ useEffect as useEffect3,
7
7
  useLayoutEffect,
8
8
  useMemo,
9
9
  useReducer,
10
10
  useRef as useRef2,
11
- useState as useState2,
11
+ useState as useState3,
12
12
  useSyncExternalStore
13
13
  } from "react";
14
14
  import {
15
- Animated,
15
+ Animated as Animated2,
16
16
  AppState,
17
- Platform,
17
+ Platform as Platform2,
18
18
  Pressable as Pressable2,
19
19
  StyleSheet as StyleSheet2,
20
20
  Text as Text2,
21
- useWindowDimensions,
21
+ useWindowDimensions as useWindowDimensions2,
22
22
  View as View2
23
23
  } from "react-native";
24
24
  import { WebView } from "react-native-webview";
@@ -521,6 +521,24 @@ function getSessionMethods(bridge, publishableKey, relyingPartyOrigin, session,
521
521
  await refreshUser();
522
522
  return result;
523
523
  },
524
+ // Redeems the provider's token for a link (useAttachOAuth). The user
525
+ // stays the same account, so unlike verifyOAuth this isn't a login: a
526
+ // failed link leaves the session-resume binding and the published user
527
+ // alone, and a successful one refreshes the user like linkEmailWithCode.
528
+ verifyOAuthLink: async (params) => {
529
+ const refreshUser = session.captureUserRefresh();
530
+ await auth().verifyOAuthLink(params);
531
+ await refreshUser();
532
+ },
533
+ // linked_accounts changed, so the published user is read again, the same
534
+ // as after a link. (Core's own refresh needs a raw setUser, which the
535
+ // session-managed provider doesn't hand it.)
536
+ detachOAuth: async (idpUserId) => {
537
+ const refreshUser = session.captureUserRefresh();
538
+ const result = await general().detachOAuth(idpUserId);
539
+ await refreshUser();
540
+ return result;
541
+ },
524
542
  // The account's email changes, so the provider's user is read again
525
543
  // before the change resolves, the same as a link.
526
544
  confirmEmailChangeNewCode: async (params) => {
@@ -600,17 +618,53 @@ var createSdkInstance = ({
600
618
  import { PostMessageMethod as PostMessageMethod4, PostMessageType as PostMessageType4 } from "@moon-x/core/utils";
601
619
 
602
620
  // src/components/presence-otp-prompt.tsx
603
- import { useEffect, useRef, useState } from "react";
621
+ import React, { useEffect as useEffect2, useRef, useState as useState2 } from "react";
604
622
  import {
623
+ AccessibilityInfo as AccessibilityInfo2,
624
+ ActivityIndicator,
625
+ Animated,
626
+ Easing,
627
+ KeyboardAvoidingView,
605
628
  Modal,
629
+ Platform,
606
630
  Pressable,
631
+ ScrollView,
607
632
  StyleSheet,
608
633
  Text,
609
634
  TextInput,
610
- View
635
+ View,
636
+ useColorScheme,
637
+ useWindowDimensions
611
638
  } from "react-native";
612
639
  import { registerPresenceOtpCodeProvider } from "@moon-x/core/sdk";
613
640
 
641
+ // src/components/use-reduce-motion.ts
642
+ import { useEffect, useState } from "react";
643
+ import { AccessibilityInfo } from "react-native";
644
+ var lastKnown;
645
+ var useReduceMotion = () => {
646
+ const [state, setState] = useState(() => ({
647
+ reduceMotion: lastKnown ?? true,
648
+ settled: lastKnown !== void 0
649
+ }));
650
+ useEffect(() => {
651
+ let live = true;
652
+ const update = (enabled) => {
653
+ lastKnown = enabled;
654
+ if (live) setState({ reduceMotion: enabled, settled: true });
655
+ };
656
+ AccessibilityInfo.isReduceMotionEnabled().then(update).catch(() => {
657
+ if (live) setState((current) => ({ ...current, settled: true }));
658
+ });
659
+ const subscription = AccessibilityInfo.addEventListener("reduceMotionChanged", update);
660
+ return () => {
661
+ live = false;
662
+ subscription.remove();
663
+ };
664
+ }, []);
665
+ return state;
666
+ };
667
+
614
668
  // src/components/presence-otp-gate.ts
615
669
  var createPresenceOtpGate = () => {
616
670
  let cancelledChallengeId = null;
@@ -721,42 +775,160 @@ var createPresenceOtpController = (onChange) => {
721
775
  };
722
776
  };
723
777
 
724
- // src/components/presence-otp-prompt.tsx
725
- import { jsx, jsxs } from "react/jsx-runtime";
726
- var DEFAULT_COPY = {
727
- title: "Check your email",
728
- description: "Enter the verification code we sent to confirm this wallet action.",
729
- hint: "Didn't get it? Check spam, or cancel and try again in a minute.",
730
- verify: "Verify",
731
- verifying: "Verifying...",
732
- cancel: "Cancel",
733
- invalidCode: "That code was incorrect. Try again.",
734
- incompleteCode: "Enter the 6-digit code."
778
+ // src/components/presence-otp-strings.ts
779
+ import { resolveLanguage } from "@moon-x/core/utils";
780
+ var PROMPT_LANGUAGES = ["en", "de", "es", "fr", "it", "pt"];
781
+ var COPY = {
782
+ en: {
783
+ title: "Check your email",
784
+ description: "Enter the code we sent to confirm this wallet action.",
785
+ hint: "",
786
+ verify: "Verify",
787
+ verifying: "Verifying\u2026",
788
+ cancel: "Cancel",
789
+ close: "Close",
790
+ invalidCode: "That code didn't work. Try again.",
791
+ incompleteCode: "Enter the 6-digit code.",
792
+ codeLabel: "Verification code"
793
+ },
794
+ de: {
795
+ title: "Pr\xFCfe deine E-Mails",
796
+ description: "Gib den Code ein, den wir dir gesendet haben, um diese Wallet-Aktion zu best\xE4tigen.",
797
+ hint: "",
798
+ verify: "Best\xE4tigen",
799
+ verifying: "Wird best\xE4tigt\u2026",
800
+ cancel: "Abbrechen",
801
+ close: "Schlie\xDFen",
802
+ invalidCode: "Der Code hat nicht funktioniert. Versuche es erneut.",
803
+ incompleteCode: "Gib den 6-stelligen Code ein.",
804
+ codeLabel: "Best\xE4tigungscode"
805
+ },
806
+ es: {
807
+ title: "Revisa tu correo",
808
+ description: "Introduce el c\xF3digo que te enviamos para confirmar esta acci\xF3n de la billetera.",
809
+ hint: "",
810
+ verify: "Verificar",
811
+ verifying: "Verificando\u2026",
812
+ cancel: "Cancelar",
813
+ close: "Cerrar",
814
+ invalidCode: "Ese c\xF3digo no funcion\xF3. Int\xE9ntalo de nuevo.",
815
+ incompleteCode: "Introduce el c\xF3digo de 6 d\xEDgitos.",
816
+ codeLabel: "C\xF3digo de verificaci\xF3n"
817
+ },
818
+ fr: {
819
+ title: "Consultez vos e-mails",
820
+ description: "Saisissez le code que nous vous avons envoy\xE9 pour confirmer cette action sur le portefeuille.",
821
+ hint: "",
822
+ verify: "V\xE9rifier",
823
+ verifying: "V\xE9rification\u2026",
824
+ cancel: "Annuler",
825
+ close: "Fermer",
826
+ invalidCode: "Ce code n'a pas fonctionn\xE9. R\xE9essayez.",
827
+ incompleteCode: "Saisissez le code \xE0 6 chiffres.",
828
+ codeLabel: "Code de v\xE9rification"
829
+ },
830
+ it: {
831
+ title: "Controlla la tua email",
832
+ description: "Inserisci il codice che ti abbiamo inviato per confermare questa azione sul wallet.",
833
+ hint: "",
834
+ verify: "Verifica",
835
+ verifying: "Verifica in corso\u2026",
836
+ cancel: "Annulla",
837
+ close: "Chiudi",
838
+ invalidCode: "Il codice non \xE8 valido. Riprova.",
839
+ incompleteCode: "Inserisci il codice a 6 cifre.",
840
+ codeLabel: "Codice di verifica"
841
+ },
842
+ pt: {
843
+ title: "Verifique seu e-mail",
844
+ description: "Digite o c\xF3digo que enviamos para confirmar esta a\xE7\xE3o na carteira.",
845
+ hint: "",
846
+ verify: "Verificar",
847
+ verifying: "Verificando\u2026",
848
+ cancel: "Cancelar",
849
+ close: "Fechar",
850
+ invalidCode: "Esse c\xF3digo n\xE3o funcionou. Tente novamente.",
851
+ incompleteCode: "Digite o c\xF3digo de 6 d\xEDgitos.",
852
+ codeLabel: "C\xF3digo de verifica\xE7\xE3o"
853
+ }
854
+ };
855
+ var LIGHT_COLORS = {
856
+ background: "#ffffff",
857
+ surface: "#f4f3f9",
858
+ border: "#e6e4ef",
859
+ text: "#010101",
860
+ mutedText: "#747386",
861
+ accent: "#010101",
862
+ accentText: "#fcfbff",
863
+ error: "#c41f1f",
864
+ errorSurface: "#f6e4e4",
865
+ backdrop: "rgba(1, 1, 1, 0.32)"
866
+ };
867
+ var DARK_COLORS = {
868
+ background: "#0b0b0d",
869
+ surface: "#17171b",
870
+ border: "#292930",
871
+ text: "#fcfbff",
872
+ mutedText: "#9e9bae",
873
+ accent: "#fcfbff",
874
+ accentText: "#010101",
875
+ error: "#ff9b98",
876
+ errorSurface: "#3c0202",
877
+ backdrop: "rgba(1, 1, 1, 0.32)"
878
+ };
879
+ var deviceLanguage = () => {
880
+ try {
881
+ return Intl.DateTimeFormat().resolvedOptions().locale;
882
+ } catch {
883
+ return void 0;
884
+ }
885
+ };
886
+ var resolvePromptCopy = (language) => {
887
+ return COPY[resolveLanguage(language ?? deviceLanguage(), PROMPT_LANGUAGES, "en")];
735
888
  };
736
- var DEFAULT_COLORS = {
737
- background: "#0a0a0a",
738
- surface: "#141414",
739
- border: "#333",
740
- text: "#fafafa",
741
- mutedText: "#a1a1aa",
742
- accent: "#3b82f6",
743
- accentText: "#fff",
744
- error: "#f87171"
889
+ var resolvePromptColors = (displayMode, systemScheme) => {
890
+ const dark = displayMode === "dark" || displayMode !== "light" && systemScheme === "dark";
891
+ return dark ? DARK_COLORS : LIGHT_COLORS;
745
892
  };
893
+
894
+ // src/components/presence-otp-prompt.tsx
895
+ import { jsx, jsxs } from "react/jsx-runtime";
746
896
  var OTP_LENGTH = 6;
897
+ var SHEET_MAX_WIDTH = 480;
898
+ var COMPACT_MAX_WIDTH = 360;
747
899
  var PresenceOtpPrompt = ({
748
900
  publishableKey,
749
901
  options
750
902
  }) => {
751
- const [state, setState] = useState(
903
+ const [state, setState] = useState2(
752
904
  IDLE_PRESENCE_OTP_STATE
753
905
  );
754
- const [code, setCode] = useState("");
755
- const [incomplete, setIncomplete] = useState(false);
906
+ const [code, setCode] = useState2("");
907
+ const [incomplete, setIncomplete] = useState2(false);
908
+ const [edited, setEdited] = useState2(false);
909
+ const [focused, setFocused] = useState2(false);
756
910
  const controllerRef = useRef(null);
757
- const copy = { ...DEFAULT_COPY, ...options?.copy };
758
- const colors = { ...DEFAULT_COLORS, ...options?.colors };
759
- useEffect(() => {
911
+ const inputRef = useRef(null);
912
+ const sheetOffset = useRef(new Animated.Value(0)).current;
913
+ const shake = useRef(new Animated.Value(0)).current;
914
+ const caret = useRef(new Animated.Value(1)).current;
915
+ const { reduceMotion, settled: motionSettled } = useReduceMotion();
916
+ const shakePending = useRef(false);
917
+ const scheme = useColorScheme();
918
+ const { width } = useWindowDimensions();
919
+ const copy = { ...resolvePromptCopy(options?.language), ...options?.copy };
920
+ const colors = {
921
+ ...resolvePromptColors(options?.displayMode, scheme),
922
+ ...options?.colors
923
+ };
924
+ const visible = state.request !== null;
925
+ const submitting = state.submitting;
926
+ const invalid = state.invalidCode && !edited;
927
+ const error = incomplete ? copy.incompleteCode : invalid ? copy.invalidCode : null;
928
+ const complete = code.length === OTP_LENGTH;
929
+ const sheet = width <= SHEET_MAX_WIDTH;
930
+ const compact = width <= COMPACT_MAX_WIDTH;
931
+ useEffect2(() => {
760
932
  const controller = createPresenceOtpController(setState);
761
933
  controllerRef.current = controller;
762
934
  const unregister = registerPresenceOtpCodeProvider(
@@ -771,11 +943,63 @@ var PresenceOtpPrompt = ({
771
943
  setState(IDLE_PRESENCE_OTP_STATE);
772
944
  };
773
945
  }, [publishableKey]);
774
- useEffect(() => {
946
+ const shakeCells = () => {
947
+ shake.setValue(0);
948
+ Animated.sequence(
949
+ [-6, 6, -4, 4, -2, 0].map(
950
+ (toValue) => Animated.timing(shake, {
951
+ toValue,
952
+ duration: 60,
953
+ easing: Easing.linear,
954
+ useNativeDriver: true
955
+ })
956
+ )
957
+ ).start();
958
+ };
959
+ useEffect2(() => {
775
960
  setCode("");
776
961
  setIncomplete(false);
962
+ setEdited(false);
963
+ shakePending.current = false;
964
+ if (!state.request) return;
965
+ inputRef.current?.focus();
966
+ if (!state.invalidCode) return;
967
+ if (!motionSettled) shakePending.current = true;
968
+ else if (!reduceMotion) shakeCells();
777
969
  }, [state.request]);
778
- useEffect(() => {
970
+ useEffect2(() => {
971
+ if (!motionSettled || !shakePending.current) return;
972
+ shakePending.current = false;
973
+ if (!reduceMotion) shakeCells();
974
+ }, [motionSettled]);
975
+ useEffect2(() => {
976
+ if (!visible) return;
977
+ sheetOffset.setValue(reduceMotion ? 0 : 24);
978
+ Animated.timing(sheetOffset, {
979
+ toValue: 0,
980
+ duration: 240,
981
+ easing: Easing.out(Easing.cubic),
982
+ useNativeDriver: true
983
+ }).start();
984
+ }, [visible]);
985
+ useEffect2(() => {
986
+ caret.setValue(1);
987
+ if (!focused || reduceMotion) return;
988
+ const blink = Animated.loop(
989
+ Animated.sequence([
990
+ Animated.timing(caret, { toValue: 0, duration: 0, delay: 530, useNativeDriver: true }),
991
+ Animated.timing(caret, { toValue: 1, duration: 0, delay: 530, useNativeDriver: true })
992
+ ])
993
+ );
994
+ blink.start();
995
+ return () => blink.stop();
996
+ }, [focused, reduceMotion, code]);
997
+ useEffect2(() => {
998
+ if (error && Platform.OS === "ios") {
999
+ AccessibilityInfo2.announceForAccessibility(error);
1000
+ }
1001
+ }, [error]);
1002
+ useEffect2(() => {
779
1003
  const request = state.request;
780
1004
  if (!request?.expiresAt || state.submitting) return;
781
1005
  const expire = () => controllerRef.current?.expire(request);
@@ -790,155 +1014,446 @@ var PresenceOtpPrompt = ({
790
1014
  const close = () => {
791
1015
  controllerRef.current?.cancel();
792
1016
  };
793
- const submit = () => {
794
- const normalized = code.trim();
795
- if (!/^\d{6}$/.test(normalized)) {
1017
+ const submit = (value = code) => {
1018
+ if (!/^\d{6}$/.test(value)) {
796
1019
  setIncomplete(true);
797
1020
  return;
798
1021
  }
799
- controllerRef.current?.submit(normalized);
1022
+ controllerRef.current?.submit(value);
800
1023
  };
801
- const submitting = state.submitting;
802
- const error = incomplete ? copy.incompleteCode : state.invalidCode ? copy.invalidCode : null;
803
- const complete = code.length === OTP_LENGTH;
1024
+ const changeCode = (next) => {
1025
+ if (submitting) return;
1026
+ const clean = next.replace(/\D/g, "").slice(0, OTP_LENGTH);
1027
+ setCode(clean);
1028
+ setIncomplete(false);
1029
+ setEdited(true);
1030
+ if (clean.length === OTP_LENGTH) submit(clean);
1031
+ };
1032
+ const cells = Array.from({ length: OTP_LENGTH }, (_, index) => {
1033
+ const digit = code[index] ?? "";
1034
+ const current = focused && !submitting && index === Math.min(code.length, OTP_LENGTH - 1);
1035
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
1036
+ index === OTP_LENGTH / 2 && /* @__PURE__ */ jsx(View, { style: [styles.separator, { backgroundColor: colors.mutedText }] }),
1037
+ /* @__PURE__ */ jsx(
1038
+ View,
1039
+ {
1040
+ style: [
1041
+ styles.cell,
1042
+ compact && styles.cellCompact,
1043
+ { backgroundColor: colors.background, borderColor: colors.border },
1044
+ current && { borderColor: colors.accent },
1045
+ invalid && { borderColor: colors.error, backgroundColor: colors.errorSurface }
1046
+ ],
1047
+ children: digit ? /* @__PURE__ */ jsx(Text, { style: [styles.cellText, { color: invalid ? colors.error : colors.text }], children: digit }) : current && /* @__PURE__ */ jsx(
1048
+ Animated.View,
1049
+ {
1050
+ style: [styles.caret, { backgroundColor: colors.accent, opacity: caret }]
1051
+ }
1052
+ )
1053
+ }
1054
+ )
1055
+ ] }, index);
1056
+ });
804
1057
  return /* @__PURE__ */ jsx(
805
1058
  Modal,
806
1059
  {
807
- visible: state.request !== null,
1060
+ visible,
808
1061
  transparent: true,
809
1062
  animationType: "fade",
810
1063
  onRequestClose: close,
811
- children: /* @__PURE__ */ jsx(View, { style: styles.backdrop, children: /* @__PURE__ */ jsxs(View, { style: [styles.card, { backgroundColor: colors.background }], children: [
812
- /* @__PURE__ */ jsx(Text, { style: [styles.title, { color: colors.text }], children: copy.title }),
813
- /* @__PURE__ */ jsx(Text, { style: [styles.body, { color: colors.mutedText }], children: copy.description }),
814
- /* @__PURE__ */ jsx(
815
- TextInput,
816
- {
817
- autoFocus: true,
818
- style: [
819
- styles.input,
820
- {
821
- borderColor: colors.border,
822
- backgroundColor: colors.surface,
823
- color: colors.text
824
- }
825
- ],
826
- value: code,
827
- onChangeText: (next) => {
828
- setCode(next.replace(/\D/g, "").slice(0, OTP_LENGTH));
829
- setIncomplete(false);
830
- },
831
- onSubmitEditing: submit,
832
- editable: !submitting,
833
- keyboardType: "number-pad",
834
- textContentType: "oneTimeCode",
835
- autoComplete: "sms-otp",
836
- maxLength: OTP_LENGTH,
837
- placeholder: "123456",
838
- placeholderTextColor: colors.mutedText,
839
- accessibilityLabel: "Verification code",
840
- returnKeyType: "done"
841
- }
842
- ),
843
- error !== null && /* @__PURE__ */ jsx(
844
- Text,
845
- {
846
- style: [styles.error, { color: colors.error }],
847
- accessibilityLiveRegion: "polite",
848
- children: error
849
- }
850
- ),
851
- /* @__PURE__ */ jsx(
852
- Pressable,
853
- {
854
- onPress: submit,
855
- disabled: submitting || !complete,
856
- style: [
857
- styles.primaryButton,
858
- { backgroundColor: colors.accent },
859
- (submitting || !complete) && styles.primaryButtonDisabled
860
- ],
861
- accessibilityRole: "button",
862
- children: /* @__PURE__ */ jsx(Text, { style: [styles.primaryButtonText, { color: colors.accentText }], children: submitting ? copy.verifying : copy.verify })
863
- }
864
- ),
865
- /* @__PURE__ */ jsx(
866
- Pressable,
867
- {
868
- onPress: close,
869
- disabled: submitting,
870
- style: [styles.ghostButton, submitting && styles.primaryButtonDisabled],
871
- accessibilityRole: "button",
872
- children: /* @__PURE__ */ jsx(Text, { style: [styles.ghostButtonText, { color: colors.mutedText }], children: copy.cancel })
873
- }
874
- ),
875
- /* @__PURE__ */ jsx(Text, { style: [styles.hint, { color: colors.mutedText }], children: copy.hint })
876
- ] }) })
1064
+ onShow: () => inputRef.current?.focus(),
1065
+ children: /* @__PURE__ */ jsx(
1066
+ KeyboardAvoidingView,
1067
+ {
1068
+ behavior: Platform.OS === "ios" ? "padding" : void 0,
1069
+ style: [
1070
+ styles.backdrop,
1071
+ sheet ? styles.backdropSheet : styles.backdropCentered,
1072
+ { backgroundColor: colors.backdrop }
1073
+ ],
1074
+ children: /* @__PURE__ */ jsxs(
1075
+ Animated.View,
1076
+ {
1077
+ accessibilityViewIsModal: true,
1078
+ style: [
1079
+ styles.card,
1080
+ sheet ? styles.sheet : styles.centered,
1081
+ {
1082
+ backgroundColor: colors.background,
1083
+ borderColor: colors.border,
1084
+ transform: [{ translateY: sheetOffset }]
1085
+ }
1086
+ ],
1087
+ children: [
1088
+ /* @__PURE__ */ jsx(View, { style: styles.header, children: /* @__PURE__ */ jsx(
1089
+ Pressable,
1090
+ {
1091
+ onPress: close,
1092
+ disabled: submitting,
1093
+ hitSlop: 8,
1094
+ accessibilityRole: "button",
1095
+ accessibilityLabel: copy.close,
1096
+ style: ({ pressed }) => [
1097
+ styles.iconButton,
1098
+ { backgroundColor: pressed ? colors.border : colors.surface },
1099
+ submitting && styles.disabled
1100
+ ],
1101
+ children: /* @__PURE__ */ jsx(CloseIcon, { color: colors.mutedText })
1102
+ }
1103
+ ) }),
1104
+ /* @__PURE__ */ jsxs(
1105
+ ScrollView,
1106
+ {
1107
+ bounces: false,
1108
+ keyboardShouldPersistTaps: "handled",
1109
+ contentContainerStyle: styles.content,
1110
+ children: [
1111
+ /* @__PURE__ */ jsxs(View, { style: styles.body, children: [
1112
+ /* @__PURE__ */ jsxs(View, { style: styles.hero, children: [
1113
+ /* @__PURE__ */ jsx(View, { style: [styles.iconDisc, { backgroundColor: colors.surface }], children: /* @__PURE__ */ jsx(MailIcon, { color: colors.text }) }),
1114
+ /* @__PURE__ */ jsxs(View, { style: styles.heroText, children: [
1115
+ /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles.title, { color: colors.text }], children: copy.title }),
1116
+ /* @__PURE__ */ jsx(Text, { style: [styles.description, { color: colors.mutedText }], children: copy.description })
1117
+ ] })
1118
+ ] }),
1119
+ /* @__PURE__ */ jsxs(View, { children: [
1120
+ /* @__PURE__ */ jsx(
1121
+ Animated.View,
1122
+ {
1123
+ accessibilityElementsHidden: true,
1124
+ importantForAccessibility: "no-hide-descendants",
1125
+ style: [
1126
+ styles.cells,
1127
+ compact && styles.cellsCompact,
1128
+ submitting && styles.cellsBusy,
1129
+ { transform: [{ translateX: shake }] }
1130
+ ],
1131
+ children: cells
1132
+ }
1133
+ ),
1134
+ /* @__PURE__ */ jsx(
1135
+ TextInput,
1136
+ {
1137
+ ref: inputRef,
1138
+ autoFocus: true,
1139
+ value: code,
1140
+ onChangeText: changeCode,
1141
+ onSubmitEditing: () => submit(),
1142
+ onFocus: () => setFocused(true),
1143
+ onBlur: () => setFocused(false),
1144
+ keyboardType: "number-pad",
1145
+ textContentType: "oneTimeCode",
1146
+ autoComplete: "sms-otp",
1147
+ autoCorrect: false,
1148
+ spellCheck: false,
1149
+ caretHidden: true,
1150
+ selectionColor: colors.accent,
1151
+ accessibilityLabel: copy.codeLabel,
1152
+ returnKeyType: "done",
1153
+ style: styles.codeInput
1154
+ }
1155
+ )
1156
+ ] }),
1157
+ error !== null && /* @__PURE__ */ jsxs(View, { style: styles.error, accessibilityLiveRegion: "polite", children: [
1158
+ /* @__PURE__ */ jsx(AlertIcon, { color: colors.error }),
1159
+ /* @__PURE__ */ jsx(Text, { style: [styles.errorText, { color: colors.error }], children: error })
1160
+ ] })
1161
+ ] }),
1162
+ /* @__PURE__ */ jsxs(View, { style: styles.actions, children: [
1163
+ /* @__PURE__ */ jsxs(
1164
+ Pressable,
1165
+ {
1166
+ onPress: () => submit(),
1167
+ disabled: !complete || submitting,
1168
+ accessibilityRole: "button",
1169
+ accessibilityState: { disabled: !complete || submitting, busy: submitting },
1170
+ style: ({ pressed }) => [
1171
+ styles.button,
1172
+ { backgroundColor: colors.accent },
1173
+ pressed && styles.pressed,
1174
+ !complete && !submitting && styles.disabled
1175
+ ],
1176
+ children: [
1177
+ submitting && /* @__PURE__ */ jsx(ActivityIndicator, { size: "small", color: colors.accentText }),
1178
+ /* @__PURE__ */ jsx(Text, { style: [styles.buttonText, { color: colors.accentText }], children: submitting ? copy.verifying : copy.verify })
1179
+ ]
1180
+ }
1181
+ ),
1182
+ /* @__PURE__ */ jsx(
1183
+ Pressable,
1184
+ {
1185
+ onPress: close,
1186
+ disabled: submitting,
1187
+ accessibilityRole: "button",
1188
+ style: ({ pressed }) => [
1189
+ styles.button,
1190
+ pressed && { backgroundColor: colors.surface },
1191
+ submitting && styles.disabled
1192
+ ],
1193
+ children: ({ pressed }) => /* @__PURE__ */ jsx(
1194
+ Text,
1195
+ {
1196
+ style: [styles.buttonText, { color: pressed ? colors.text : colors.mutedText }],
1197
+ children: copy.cancel
1198
+ }
1199
+ )
1200
+ }
1201
+ ),
1202
+ copy.hint ? /* @__PURE__ */ jsx(Text, { style: [styles.hint, { color: colors.mutedText }], children: copy.hint }) : null
1203
+ ] })
1204
+ ]
1205
+ }
1206
+ )
1207
+ ]
1208
+ }
1209
+ )
1210
+ }
1211
+ )
877
1212
  }
878
1213
  );
879
1214
  };
1215
+ var CloseIcon = ({ color }) => /* @__PURE__ */ jsxs(View, { style: styles.closeIcon, children: [
1216
+ /* @__PURE__ */ jsx(View, { style: [styles.closeBar, { backgroundColor: color, transform: [{ rotate: "45deg" }] }] }),
1217
+ /* @__PURE__ */ jsx(View, { style: [styles.closeBar, { backgroundColor: color, transform: [{ rotate: "-45deg" }] }] })
1218
+ ] });
1219
+ var MailIcon = ({ color }) => /* @__PURE__ */ jsxs(View, { style: styles.mailIcon, children: [
1220
+ /* @__PURE__ */ jsx(View, { style: [styles.mailBody, { borderColor: color }] }),
1221
+ /* @__PURE__ */ jsx(View, { style: [styles.mailFlap, styles.mailFlapLeft, { backgroundColor: color }] }),
1222
+ /* @__PURE__ */ jsx(View, { style: [styles.mailFlap, styles.mailFlapRight, { backgroundColor: color }] })
1223
+ ] });
1224
+ var AlertIcon = ({ color }) => /* @__PURE__ */ jsxs(View, { style: [styles.alertIcon, { borderColor: color }], children: [
1225
+ /* @__PURE__ */ jsx(View, { style: [styles.alertStem, { backgroundColor: color }] }),
1226
+ /* @__PURE__ */ jsx(View, { style: [styles.alertDot, { backgroundColor: color }] })
1227
+ ] });
880
1228
  var styles = StyleSheet.create({
881
1229
  backdrop: {
882
- flex: 1,
1230
+ flex: 1
1231
+ },
1232
+ backdropSheet: {
1233
+ justifyContent: "flex-end"
1234
+ },
1235
+ backdropCentered: {
883
1236
  alignItems: "center",
884
1237
  justifyContent: "center",
885
- padding: 16,
886
- backgroundColor: "rgba(0, 0, 0, 0.45)"
1238
+ padding: 16
887
1239
  },
888
1240
  card: {
889
1241
  width: "100%",
890
- maxWidth: 384,
891
- padding: 24,
892
- borderRadius: 14
1242
+ maxHeight: "100%",
1243
+ overflow: "hidden"
1244
+ },
1245
+ sheet: {
1246
+ borderTopLeftRadius: 24,
1247
+ borderTopRightRadius: 24,
1248
+ borderTopWidth: 1
1249
+ },
1250
+ centered: {
1251
+ maxWidth: 400,
1252
+ borderRadius: 24,
1253
+ borderWidth: 1
1254
+ },
1255
+ header: {
1256
+ flexDirection: "row",
1257
+ justifyContent: "flex-end",
1258
+ alignItems: "center",
1259
+ height: 56,
1260
+ paddingHorizontal: 16
1261
+ },
1262
+ iconButton: {
1263
+ width: 32,
1264
+ height: 32,
1265
+ borderRadius: 8,
1266
+ alignItems: "center",
1267
+ justifyContent: "center"
1268
+ },
1269
+ content: {
1270
+ paddingHorizontal: 24,
1271
+ // Clear of the home indicator when the keyboard is down.
1272
+ paddingBottom: 32
1273
+ },
1274
+ body: {
1275
+ gap: 16
1276
+ },
1277
+ hero: {
1278
+ alignItems: "center",
1279
+ gap: 16,
1280
+ paddingTop: 8
1281
+ },
1282
+ iconDisc: {
1283
+ width: 64,
1284
+ height: 64,
1285
+ borderRadius: 32,
1286
+ alignItems: "center",
1287
+ justifyContent: "center"
1288
+ },
1289
+ heroText: {
1290
+ width: "100%",
1291
+ gap: 4
893
1292
  },
894
1293
  title: {
895
1294
  fontSize: 20,
896
- fontWeight: "600"
1295
+ lineHeight: 24,
1296
+ fontWeight: "500",
1297
+ letterSpacing: -0.4,
1298
+ textAlign: "center"
897
1299
  },
898
- body: {
1300
+ description: {
899
1301
  fontSize: 14,
900
- marginTop: 8
1302
+ lineHeight: 20,
1303
+ textAlign: "center"
901
1304
  },
902
- input: {
903
- marginTop: 16,
904
- paddingVertical: 12,
905
- paddingHorizontal: 16,
1305
+ cells: {
1306
+ flexDirection: "row",
1307
+ alignItems: "center",
1308
+ justifyContent: "center",
1309
+ gap: 8
1310
+ },
1311
+ cellsCompact: {
1312
+ gap: 6
1313
+ },
1314
+ cellsBusy: {
1315
+ opacity: 0.6
1316
+ },
1317
+ cell: {
1318
+ width: 44,
1319
+ height: 52,
1320
+ borderWidth: 1,
906
1321
  borderRadius: 12,
907
- borderWidth: StyleSheet.hairlineWidth,
908
- fontSize: 24,
909
- letterSpacing: 8,
910
- textAlign: "center"
1322
+ alignItems: "center",
1323
+ justifyContent: "center"
1324
+ },
1325
+ cellCompact: {
1326
+ width: 38,
1327
+ height: 48
1328
+ },
1329
+ cellText: {
1330
+ fontSize: 18,
1331
+ fontWeight: "500",
1332
+ fontVariant: ["tabular-nums"]
1333
+ },
1334
+ caret: {
1335
+ width: 1.5,
1336
+ height: 20,
1337
+ borderRadius: 1
1338
+ },
1339
+ separator: {
1340
+ width: 4,
1341
+ height: 4,
1342
+ borderRadius: 2,
1343
+ marginHorizontal: 4,
1344
+ opacity: 0.6
1345
+ },
1346
+ codeInput: {
1347
+ position: "absolute",
1348
+ top: 0,
1349
+ right: 0,
1350
+ bottom: 0,
1351
+ left: 0,
1352
+ // Not 0: iOS stops delivering touches to a view that is fully transparent.
1353
+ opacity: 0.015,
1354
+ color: "transparent",
1355
+ backgroundColor: "transparent",
1356
+ borderWidth: 0
911
1357
  },
912
1358
  error: {
913
- fontSize: 13,
914
- marginTop: 8
1359
+ flexDirection: "row",
1360
+ alignItems: "center",
1361
+ justifyContent: "center",
1362
+ gap: 4
915
1363
  },
916
- primaryButton: {
917
- marginTop: 16,
918
- paddingVertical: 12,
919
- borderRadius: 12,
920
- alignItems: "center"
1364
+ errorText: {
1365
+ flexShrink: 1,
1366
+ fontSize: 12,
1367
+ fontWeight: "500",
1368
+ textAlign: "center"
921
1369
  },
922
- primaryButtonDisabled: {
923
- opacity: 0.5
1370
+ actions: {
1371
+ gap: 8,
1372
+ paddingTop: 24
1373
+ },
1374
+ button: {
1375
+ flexDirection: "row",
1376
+ alignItems: "center",
1377
+ justifyContent: "center",
1378
+ gap: 8,
1379
+ height: 48,
1380
+ paddingHorizontal: 20,
1381
+ borderRadius: 999
924
1382
  },
925
- primaryButtonText: {
1383
+ buttonText: {
926
1384
  fontSize: 16,
927
- fontWeight: "600"
1385
+ fontWeight: "500"
928
1386
  },
929
- ghostButton: {
930
- marginTop: 8,
931
- paddingVertical: 12,
932
- alignItems: "center"
1387
+ pressed: {
1388
+ opacity: 0.88,
1389
+ transform: [{ scale: 0.985 }]
933
1390
  },
934
- ghostButtonText: {
935
- fontSize: 15,
936
- fontWeight: "500"
1391
+ disabled: {
1392
+ opacity: 0.5
937
1393
  },
938
1394
  hint: {
939
1395
  fontSize: 12,
940
- marginTop: 4,
1396
+ lineHeight: 16,
941
1397
  textAlign: "center"
1398
+ },
1399
+ closeIcon: {
1400
+ width: 16,
1401
+ height: 16,
1402
+ alignItems: "center",
1403
+ justifyContent: "center"
1404
+ },
1405
+ closeBar: {
1406
+ position: "absolute",
1407
+ width: 12,
1408
+ height: 1.5,
1409
+ borderRadius: 1
1410
+ },
1411
+ mailIcon: {
1412
+ width: 28,
1413
+ height: 28
1414
+ },
1415
+ mailBody: {
1416
+ position: "absolute",
1417
+ top: 5,
1418
+ left: 2,
1419
+ width: 24,
1420
+ height: 18,
1421
+ borderWidth: 2,
1422
+ borderRadius: 3
1423
+ },
1424
+ mailFlap: {
1425
+ position: "absolute",
1426
+ top: 10.6,
1427
+ width: 13,
1428
+ height: 2,
1429
+ borderRadius: 1
1430
+ },
1431
+ mailFlapLeft: {
1432
+ left: 2,
1433
+ transform: [{ rotate: "29.8deg" }]
1434
+ },
1435
+ mailFlapRight: {
1436
+ left: 13,
1437
+ transform: [{ rotate: "-29.8deg" }]
1438
+ },
1439
+ alertIcon: {
1440
+ width: 14,
1441
+ height: 14,
1442
+ borderRadius: 7,
1443
+ borderWidth: 1.25,
1444
+ alignItems: "center",
1445
+ justifyContent: "center",
1446
+ gap: 1
1447
+ },
1448
+ alertStem: {
1449
+ width: 1.5,
1450
+ height: 4,
1451
+ borderRadius: 1
1452
+ },
1453
+ alertDot: {
1454
+ width: 1.5,
1455
+ height: 1.5,
1456
+ borderRadius: 1
942
1457
  }
943
1458
  });
944
1459
 
@@ -968,6 +1483,11 @@ var RETRY_ATTEMPT_TIMEOUTS_MS = [
968
1483
  POST_MESSAGE_REQUEST_TIMEOUT_MS
969
1484
  ];
970
1485
  var RETRY_BACKOFF_MS = [200, 400];
1486
+ var isRetryableRead = (method, payload) => {
1487
+ const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1488
+ const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1489
+ return RETRYABLE_METHODS.has(method) && !isSigningPreparation && !isResumeCheck;
1490
+ };
971
1491
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
972
1492
  var TimeoutError = class extends Error {
973
1493
  constructor(message) {
@@ -1103,9 +1623,7 @@ var WebViewBridge = class {
1103
1623
  // Idempotent reads (see RETRYABLE_METHODS) are auto-retried on timeout to
1104
1624
  // ride out the iframe-app mount race; everything else makes a single attempt.
1105
1625
  async send(type, method, payload) {
1106
- const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
1107
- const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
1108
- if (isSigningPreparation || isResumeCheck || !RETRYABLE_METHODS.has(method)) {
1626
+ if (!isRetryableRead(method, payload)) {
1109
1627
  return this.sendOnce(
1110
1628
  type,
1111
1629
  method,
@@ -1120,7 +1638,8 @@ var WebViewBridge = class {
1120
1638
  type,
1121
1639
  method,
1122
1640
  payload,
1123
- RETRY_ATTEMPT_TIMEOUTS_MS[attempt]
1641
+ RETRY_ATTEMPT_TIMEOUTS_MS[attempt],
1642
+ attempt < RETRY_ATTEMPT_TIMEOUTS_MS.length - 1
1124
1643
  );
1125
1644
  } catch (error) {
1126
1645
  lastError = error;
@@ -1131,7 +1650,7 @@ var WebViewBridge = class {
1131
1650
  }
1132
1651
  throw lastError;
1133
1652
  }
1134
- sendOnce(type, method, payload, timeoutMs) {
1653
+ sendOnce(type, method, payload, timeoutMs, retryOnReady = false) {
1135
1654
  const ref = this.webViewRef.current;
1136
1655
  if (!ref) {
1137
1656
  return Promise.reject(new Error("webview_not_ready"));
@@ -1151,7 +1670,8 @@ var WebViewBridge = class {
1151
1670
  reject,
1152
1671
  timeoutId,
1153
1672
  type,
1154
- method
1673
+ method,
1674
+ retryOnReady
1155
1675
  });
1156
1676
  const envelope = { id, type, method, payload };
1157
1677
  try {
@@ -1192,8 +1712,15 @@ var WebViewBridge = class {
1192
1712
  rejectAllPending(reason) {
1193
1713
  this.rejectPending(() => new TimeoutError(reason));
1194
1714
  }
1195
- rejectPending(createError) {
1715
+ retryPendingReads() {
1716
+ this.rejectPending(
1717
+ () => new TimeoutError("webview_ready"),
1718
+ (resolver) => resolver.retryOnReady
1719
+ );
1720
+ }
1721
+ rejectPending(createError, shouldReject = () => true) {
1196
1722
  for (const [id, resolver] of this.pending.entries()) {
1723
+ if (!shouldReject(resolver)) continue;
1197
1724
  clearTimeout(resolver.timeoutId);
1198
1725
  resolver.reject(createError());
1199
1726
  this.pending.delete(id);
@@ -1774,8 +2301,8 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1774
2301
  () => makeRelyingPartyOriginResolver(bridge, publishableKey, relyingPartyOrigin),
1775
2302
  [bridge, publishableKey, relyingPartyOrigin]
1776
2303
  );
1777
- const [sensitiveVisible, setSensitiveVisible] = useState2(false);
1778
- const [captchaChallengeVisible, setCaptchaChallengeVisible] = useState2(false);
2304
+ const [sensitiveVisible, setSensitiveVisible] = useState3(false);
2305
+ const [captchaChallengeVisible, setCaptchaChallengeVisible] = useState3(false);
1779
2306
  const cancelRef = useRef2(null);
1780
2307
  const webViewVisible = sensitiveVisible || captchaChallengeVisible;
1781
2308
  const [
@@ -1811,15 +2338,15 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1811
2338
  session.mount();
1812
2339
  return session.unmount;
1813
2340
  }, [session]);
1814
- useEffect2(() => {
2341
+ useEffect3(() => {
1815
2342
  session.setReady(ready);
1816
2343
  }, [session, ready]);
1817
2344
  const { sessionStatus } = sessionSnapshot;
1818
- useEffect2(() => {
2345
+ useEffect3(() => {
1819
2346
  if (!sessionResume || !ready || sessionStatus !== "authenticated") return;
1820
2347
  void sessionResume.bind();
1821
2348
  }, [sessionResume, ready, sessionStatus, revalidatedAt]);
1822
- useEffect2(() => {
2349
+ useEffect3(() => {
1823
2350
  const subscription = AppState.addEventListener("change", (nextState) => {
1824
2351
  if (nextState === "active") {
1825
2352
  session.restartSession();
@@ -1827,18 +2354,18 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1827
2354
  });
1828
2355
  return () => subscription.remove();
1829
2356
  }, [session]);
1830
- const { height: screenHeight } = useWindowDimensions();
2357
+ const { height: screenHeight } = useWindowDimensions2();
1831
2358
  const SHEET_TOP_OFFSET = 80;
1832
- const sheetTranslateY = useRef2(new Animated.Value(screenHeight)).current;
1833
- const backdropOpacity = useRef2(new Animated.Value(0)).current;
1834
- useEffect2(() => {
1835
- Animated.parallel([
1836
- Animated.timing(sheetTranslateY, {
2359
+ const sheetTranslateY = useRef2(new Animated2.Value(screenHeight)).current;
2360
+ const backdropOpacity = useRef2(new Animated2.Value(0)).current;
2361
+ useEffect3(() => {
2362
+ Animated2.parallel([
2363
+ Animated2.timing(sheetTranslateY, {
1837
2364
  toValue: webViewVisible ? 0 : screenHeight,
1838
2365
  duration: 280,
1839
2366
  useNativeDriver: true
1840
2367
  }),
1841
- Animated.timing(backdropOpacity, {
2368
+ Animated2.timing(backdropOpacity, {
1842
2369
  toValue: webViewVisible ? 0.5 : 0,
1843
2370
  duration: 280,
1844
2371
  useNativeDriver: true
@@ -1947,13 +2474,13 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1947
2474
  );
1948
2475
  const sessionResumeRef = useRef2(sessionResume);
1949
2476
  sessionResumeRef.current = sessionResume;
1950
- useEffect2(() => {
2477
+ useEffect3(() => {
1951
2478
  return () => {
1952
2479
  sessionResumeRef.current?.cancelPendingBinds();
1953
2480
  bridge.cleanup("provider_unmounted");
1954
2481
  };
1955
2482
  }, [bridge]);
1956
- useEffect2(
2483
+ useEffect3(
1957
2484
  () => bridge.register(
1958
2485
  PostMessageType4.INIT,
1959
2486
  PostMessageMethod4.CAPTCHA_CHALLENGE_VISIBILITY,
@@ -1965,23 +2492,30 @@ var NativeProvider = ({ publishableKey, config, children }) => {
1965
2492
  ),
1966
2493
  [bridge]
1967
2494
  );
1968
- useEffect2(() => {
2495
+ useEffect3(() => {
1969
2496
  const unsubscribe = bridge.onResponseError((error) => {
1970
2497
  if (error.message === "no_session") session.retrySession();
1971
2498
  });
1972
2499
  return unsubscribe;
1973
2500
  }, [bridge, session]);
1974
- useEffect2(() => {
2501
+ useEffect3(() => {
1975
2502
  let cancelled = false;
2503
+ let readinessSource = "pending";
1976
2504
  const unregister = bridge.register(
1977
2505
  PostMessageType4.INIT,
1978
2506
  PostMessageMethod4.READY,
1979
2507
  () => {
1980
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2508
+ if (cancelled || readinessSource === "page") return;
2509
+ const retryPendingReads = readinessSource === "fallback";
2510
+ readinessSource = "page";
2511
+ dispatchWebViewLifecycle({ type: "ready" });
2512
+ if (retryPendingReads) bridge.retryPendingReads();
1981
2513
  }
1982
2514
  );
1983
2515
  const fallback = setTimeout(() => {
1984
- if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
2516
+ if (cancelled || readinessSource !== "pending") return;
2517
+ readinessSource = "fallback";
2518
+ dispatchWebViewLifecycle({ type: "ready" });
1985
2519
  }, 2e3);
1986
2520
  return () => {
1987
2521
  cancelled = true;
@@ -2018,7 +2552,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2018
2552
  }
2019
2553
  ),
2020
2554
  /* @__PURE__ */ jsx2(
2021
- Animated.View,
2555
+ Animated2.View,
2022
2556
  {
2023
2557
  style: [styles2.backdrop, { opacity: backdropOpacity }],
2024
2558
  pointerEvents: webViewVisible ? "auto" : "none",
@@ -2034,7 +2568,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2034
2568
  }
2035
2569
  ),
2036
2570
  /* @__PURE__ */ jsxs2(
2037
- Animated.View,
2571
+ Animated2.View,
2038
2572
  {
2039
2573
  style: [
2040
2574
  styles2.sheetContainer,
@@ -2082,8 +2616,8 @@ var NativeProvider = ({ publishableKey, config, children }) => {
2082
2616
  webviewDebuggingEnabled: __DEV__,
2083
2617
  javaScriptEnabled: true,
2084
2618
  domStorageEnabled: true,
2085
- sharedCookiesEnabled: Platform.OS === "ios",
2086
- thirdPartyCookiesEnabled: Platform.OS === "android",
2619
+ sharedCookiesEnabled: Platform2.OS === "ios",
2620
+ thirdPartyCookiesEnabled: Platform2.OS === "android",
2087
2621
  startInLoadingState: false,
2088
2622
  originWhitelist: ["https://*", "http://*"],
2089
2623
  style: styles2.webView
@@ -2192,15 +2726,15 @@ import {
2192
2726
 
2193
2727
  // src/hooks/use-app-config.ts
2194
2728
  import { PostMessageMethod as PostMessageMethod5, PostMessageType as PostMessageType5 } from "@moon-x/core/utils";
2195
- import { useEffect as useEffect3, useState as useState3 } from "react";
2729
+ import { useEffect as useEffect4, useState as useState4 } from "react";
2196
2730
  var useAppConfig = (publishableKey) => {
2197
2731
  const { sdk, _bridge } = useMoonXContext();
2198
2732
  const resolvedKey = publishableKey ?? sdk.publishableKey;
2199
2733
  const ready = sdk.ready;
2200
- const [appConfig, setAppConfig] = useState3(null);
2201
- const [isLoading, setIsLoading] = useState3(true);
2202
- const [error, setError] = useState3(null);
2203
- useEffect3(() => {
2734
+ const [appConfig, setAppConfig] = useState4(null);
2735
+ const [isLoading, setIsLoading] = useState4(true);
2736
+ const [error, setError] = useState4(null);
2737
+ useEffect4(() => {
2204
2738
  if (!resolvedKey) {
2205
2739
  setIsLoading(false);
2206
2740
  return;
@@ -2235,8 +2769,7 @@ var useAppConfig = (publishableKey) => {
2235
2769
  };
2236
2770
 
2237
2771
  // src/hooks/use-attach-oauth.ts
2238
- import { PostMessageMethod as PostMessageMethod6, PostMessageType as PostMessageType6 } from "@moon-x/core/utils";
2239
- import { useState as useState4 } from "react";
2772
+ import { useState as useState5 } from "react";
2240
2773
 
2241
2774
  // src/lib/oauth-deep-link.ts
2242
2775
  var openOAuthFlow = async ({
@@ -2276,8 +2809,8 @@ var parseOAuthRedirect = async (redirectUrl) => {
2276
2809
 
2277
2810
  // src/hooks/use-attach-oauth.ts
2278
2811
  var useAttachOAuth = (params) => {
2279
- const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
2280
- const [state, setState] = useState4({ status: "idle" });
2812
+ const { sdk, _oauthRedirectUri } = useMoonXContext();
2813
+ const [state, setState] = useState5({ status: "idle" });
2281
2814
  return {
2282
2815
  state,
2283
2816
  attachOAuth: async (provider) => {
@@ -2285,15 +2818,9 @@ var useAttachOAuth = (params) => {
2285
2818
  try {
2286
2819
  const redirectUri = params?.redirectUri || _oauthRedirectUri;
2287
2820
  if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
2288
- const startResult = await _bridge.send(
2289
- PostMessageType6.AUTH,
2290
- PostMessageMethod6.START_OAUTH,
2291
- {
2292
- publishableKey: sdk.publishableKey,
2293
- provider,
2294
- attach: true,
2295
- login_redirect_url: redirectUri
2296
- }
2821
+ const startResult = await sdk.beginOAuthLink(
2822
+ provider,
2823
+ redirectUri
2297
2824
  );
2298
2825
  if (!startResult.redirect_url) {
2299
2826
  throw new Error("start_oauth_failed");
@@ -2305,18 +2832,16 @@ var useAttachOAuth = (params) => {
2305
2832
  });
2306
2833
  const parsed = await parseOAuthRedirect(redirectUrl);
2307
2834
  if (parsed.error) throw new Error(parsed.error);
2835
+ if (!parsed.code && !parsed.token) {
2836
+ throw new Error("oauth_no_code_or_token");
2837
+ }
2308
2838
  setState({ status: "verifying" });
2309
- await _bridge.send(
2310
- PostMessageType6.AUTH,
2311
- PostMessageMethod6.ATTACH_OAUTH,
2312
- {
2313
- publishableKey: sdk.publishableKey,
2314
- provider,
2315
- code: parsed.code,
2316
- token: parsed.token,
2317
- state: parsed.state
2318
- }
2319
- );
2839
+ await sdk.verifyOAuthLink({
2840
+ provider,
2841
+ code: parsed.code,
2842
+ token: parsed.token,
2843
+ state: parsed.state
2844
+ });
2320
2845
  setState({ status: "complete" });
2321
2846
  } catch (e) {
2322
2847
  const err = e instanceof Error ? e : new Error(String(e));
@@ -2329,23 +2854,22 @@ var useAttachOAuth = (params) => {
2329
2854
  };
2330
2855
 
2331
2856
  // src/hooks/use-detach-oauth.ts
2332
- import { PostMessageMethod as PostMessageMethod7, PostMessageType as PostMessageType7 } from "@moon-x/core/utils";
2333
2857
  var useDetachOAuth = () => {
2334
- const { sdk, _bridge } = useMoonXContext();
2858
+ const { sdk } = useMoonXContext();
2335
2859
  return {
2860
+ // Removes a Google or Apple sign-in by its id in the user's
2861
+ // linked_accounts, with the presence step-up first when the backend asks
2862
+ // for one. Rejects with last_login_method rather than leave the account
2863
+ // with no way to sign in.
2336
2864
  detachOAuth: async (idpUserId) => {
2337
- await _bridge.send(
2338
- PostMessageType7.AUTH,
2339
- PostMessageMethod7.DETACH_OAUTH,
2340
- { publishableKey: sdk.publishableKey, idpUserId }
2341
- );
2865
+ await sdk.detachOAuth(idpUserId);
2342
2866
  }
2343
2867
  };
2344
2868
  };
2345
2869
 
2346
2870
  // src/hooks/use-export-key.ts
2347
2871
  import { getInternalPresenceTokens as getInternalPresenceTokens2, SCOPES_EXPORT_KEY } from "@moon-x/core/sdk";
2348
- import { PostMessageMethod as PostMessageMethod8, PostMessageType as PostMessageType8 } from "@moon-x/core/utils";
2872
+ import { PostMessageMethod as PostMessageMethod6, PostMessageType as PostMessageType6 } from "@moon-x/core/utils";
2349
2873
  var parseExportKeyResult = (value) => {
2350
2874
  if (!value || typeof value !== "object" || !("status" in value)) {
2351
2875
  return { status: "failed", error: "invalid_export_key_result" };
@@ -2389,8 +2913,8 @@ var useExportKey = () => {
2389
2913
  title: "Export key",
2390
2914
  flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
2391
2915
  onMount: ({ bridge, setResult }) => bridge.register(
2392
- PostMessageType8.WALLET,
2393
- PostMessageMethod8.EXPORT_KEY_RESULT,
2916
+ PostMessageType6.WALLET,
2917
+ PostMessageMethod6.EXPORT_KEY_RESULT,
2394
2918
  (result) => {
2395
2919
  setResult(parseExportKeyResult(result));
2396
2920
  }
@@ -2436,14 +2960,14 @@ var useLoginWithEmail = (callbacks) => {
2436
2960
  };
2437
2961
 
2438
2962
  // src/hooks/use-login-with-oauth.ts
2439
- import { PostMessageMethod as PostMessageMethod9, PostMessageType as PostMessageType9 } from "@moon-x/core/utils";
2440
- import { useEffect as useEffect4, useRef as useRef3, useState as useState5 } from "react";
2963
+ import { PostMessageMethod as PostMessageMethod7, PostMessageType as PostMessageType7 } from "@moon-x/core/utils";
2964
+ import { useEffect as useEffect5, useRef as useRef3, useState as useState6 } from "react";
2441
2965
  var useLoginWithOAuth = (params) => {
2442
2966
  const { sdk, _bridge, _oauthRedirectUri, _beginAuthFlow } = useMoonXContext();
2443
- const [state, setState] = useState5({ status: "idle" });
2967
+ const [state, setState] = useState6({ status: "idle" });
2444
2968
  const activeFlow = useRef3(null);
2445
2969
  const mounted = useRef3(true);
2446
- useEffect4(() => {
2970
+ useEffect5(() => {
2447
2971
  mounted.current = true;
2448
2972
  return () => {
2449
2973
  mounted.current = false;
@@ -2470,8 +2994,8 @@ var useLoginWithOAuth = (params) => {
2470
2994
  throw new Error("oauth_redirect_uri_missing");
2471
2995
  }
2472
2996
  const startResult = await _bridge.send(
2473
- PostMessageType9.AUTH,
2474
- PostMessageMethod9.START_OAUTH,
2997
+ PostMessageType7.AUTH,
2998
+ PostMessageMethod7.START_OAUTH,
2475
2999
  {
2476
3000
  publishableKey: sdk.publishableKey,
2477
3001
  provider,
@@ -2518,17 +3042,17 @@ var useLoginWithOAuth = (params) => {
2518
3042
  var useMoonX = () => useMoonXContext().sdk;
2519
3043
 
2520
3044
  // src/external-wallets/use-external-wallets.ts
2521
- import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef4, useState as useState6 } from "react";
3045
+ import { useCallback as useCallback3, useEffect as useEffect6, useRef as useRef4, useState as useState7 } from "react";
2522
3046
  var useExternalWallets = (connectors) => {
2523
- const [wallets, setWallets] = useState6([]);
2524
- const [connected, setConnected] = useState6(
3047
+ const [wallets, setWallets] = useState7([]);
3048
+ const [connected, setConnected] = useState7(
2525
3049
  null
2526
3050
  );
2527
- const [status, setStatus] = useState6("idle");
2528
- const [error, setError] = useState6(null);
2529
- const [refreshNonce, setRefreshNonce] = useState6(0);
3051
+ const [status, setStatus] = useState7("idle");
3052
+ const [error, setError] = useState7(null);
3053
+ const [refreshNonce, setRefreshNonce] = useState7(0);
2530
3054
  const unsubscribeRef = useRef4(null);
2531
- useEffect5(() => {
3055
+ useEffect6(() => {
2532
3056
  let cancelled = false;
2533
3057
  void Promise.all(
2534
3058
  connectors.map(async (connector) => ({
@@ -2542,7 +3066,7 @@ var useExternalWallets = (connectors) => {
2542
3066
  cancelled = true;
2543
3067
  };
2544
3068
  }, [connectors, refreshNonce]);
2545
- useEffect5(
3069
+ useEffect6(
2546
3070
  () => () => {
2547
3071
  unsubscribeRef.current?.();
2548
3072
  },
@@ -2883,13 +3407,13 @@ var restoreWalletConnectSession = (options) => {
2883
3407
  // src/index.ts
2884
3408
  import { MOONPAY_CONSUMER_SESSION_ERROR_CODES } from "@moon-x/core/sdk";
2885
3409
  import { registerPresenceOtpCodeProvider as registerPresenceOtpCodeProvider2 } from "@moon-x/core/sdk";
2886
- import { PostMessageMethod as PostMessageMethod10, PostMessageType as PostMessageType10 } from "@moon-x/core/utils";
3410
+ import { PostMessageMethod as PostMessageMethod8, PostMessageType as PostMessageType8 } from "@moon-x/core/utils";
2887
3411
  export {
2888
3412
  MOONPAY_CONSUMER_SESSION_ERROR_CODES,
2889
3413
  MoonXProvider as MoonKeyProvider,
2890
3414
  MoonXProvider,
2891
- PostMessageMethod10 as PostMessageMethod,
2892
- PostMessageType10 as PostMessageType,
3415
+ PostMessageMethod8 as PostMessageMethod,
3416
+ PostMessageType8 as PostMessageType,
2893
3417
  connectWalletConnect,
2894
3418
  listWalletConnectSessions,
2895
3419
  registerPresenceOtpCodeProvider2 as registerPresenceOtpCodeProvider,