@moon-x/react-native-sdk 0.25.0 → 0.28.0
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/README.md +9 -3
- package/dist/ethereum.js +227 -51
- package/dist/ethereum.mjs +228 -43
- package/dist/index.d.mts +43 -4
- package/dist/index.d.ts +43 -4
- package/dist/index.js +799 -293
- package/dist/index.mjs +736 -221
- package/dist/solana.js +227 -51
- package/dist/solana.mjs +228 -43
- package/dist/tron.js +227 -51
- package/dist/tron.mjs +228 -43
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -33,41 +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: () =>
|
|
37
|
-
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: () =>
|
|
42
|
+
useAddPasskey: () => import_react10.useAddPasskey,
|
|
43
43
|
useAppConfig: () => useAppConfig,
|
|
44
44
|
useAttachOAuth: () => useAttachOAuth,
|
|
45
|
-
useBulkImport: () =>
|
|
46
|
-
|
|
45
|
+
useBulkImport: () => import_react10.useBulkImport,
|
|
46
|
+
useChangeEmail: () => import_react10.useChangeEmail,
|
|
47
|
+
useCreateWallet: () => import_react10.useCreateWallet,
|
|
47
48
|
useDetachOAuth: () => useDetachOAuth,
|
|
48
|
-
useEphemeralSigner: () =>
|
|
49
|
+
useEphemeralSigner: () => import_react10.useEphemeralSigner,
|
|
49
50
|
useExportKey: () => useExportKey,
|
|
50
51
|
useExternalWallets: () => useExternalWallets,
|
|
51
52
|
useFundWallet: () => useFundWallet,
|
|
52
|
-
useImportKey: () =>
|
|
53
|
-
useLinkEmail: () =>
|
|
53
|
+
useImportKey: () => import_react10.useImportKey,
|
|
54
|
+
useLinkEmail: () => import_react10.useLinkEmail,
|
|
54
55
|
useLoginWithEmail: () => useLoginWithEmail,
|
|
55
56
|
useLoginWithOAuth: () => useLoginWithOAuth,
|
|
56
|
-
useLogout: () =>
|
|
57
|
+
useLogout: () => import_react10.useLogout,
|
|
57
58
|
useMoonKey: () => useMoonX,
|
|
58
59
|
useMoonX: () => useMoonX,
|
|
59
60
|
useMoonXContext: () => useMoonXContext,
|
|
60
|
-
usePasskeyStatus: () =>
|
|
61
|
-
useRegisterPasskey: () =>
|
|
62
|
-
useRemovePasskey: () =>
|
|
63
|
-
useUser: () =>
|
|
64
|
-
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
|
|
65
66
|
});
|
|
66
67
|
module.exports = __toCommonJS(index_exports);
|
|
67
68
|
|
|
68
69
|
// src/provider.tsx
|
|
69
|
-
var
|
|
70
|
-
var
|
|
70
|
+
var import_react3 = require("react");
|
|
71
|
+
var import_react_native3 = require("react-native");
|
|
71
72
|
var import_react_native_webview = require("react-native-webview");
|
|
72
73
|
|
|
73
74
|
// src/sdk/create-sdk-instance.ts
|
|
@@ -544,6 +545,32 @@ function getSessionMethods(bridge, publishableKey, relyingPartyOrigin, session,
|
|
|
544
545
|
const result = await auth().linkEmailWithCode(params);
|
|
545
546
|
await refreshUser();
|
|
546
547
|
return result;
|
|
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
|
+
},
|
|
567
|
+
// The account's email changes, so the provider's user is read again
|
|
568
|
+
// before the change resolves, the same as a link.
|
|
569
|
+
confirmEmailChangeNewCode: async (params) => {
|
|
570
|
+
const refreshUser = session.captureUserRefresh();
|
|
571
|
+
const result = await auth().confirmEmailChangeNewCode(params);
|
|
572
|
+
await refreshUser();
|
|
573
|
+
return result;
|
|
547
574
|
}
|
|
548
575
|
};
|
|
549
576
|
}
|
|
@@ -613,12 +640,39 @@ var createSdkInstance = ({
|
|
|
613
640
|
});
|
|
614
641
|
|
|
615
642
|
// src/provider.tsx
|
|
616
|
-
var
|
|
643
|
+
var import_utils6 = require("@moon-x/core/utils");
|
|
617
644
|
|
|
618
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
|
|
619
651
|
var import_react = require("react");
|
|
620
652
|
var import_react_native = require("react-native");
|
|
621
|
-
var
|
|
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
|
+
};
|
|
622
676
|
|
|
623
677
|
// src/components/presence-otp-gate.ts
|
|
624
678
|
var createPresenceOtpGate = () => {
|
|
@@ -730,42 +784,160 @@ var createPresenceOtpController = (onChange) => {
|
|
|
730
784
|
};
|
|
731
785
|
};
|
|
732
786
|
|
|
733
|
-
// src/components/presence-otp-
|
|
734
|
-
var
|
|
735
|
-
var
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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)"
|
|
744
887
|
};
|
|
745
|
-
var
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
accent: "#3b82f6",
|
|
752
|
-
accentText: "#fff",
|
|
753
|
-
error: "#f87171"
|
|
888
|
+
var deviceLanguage = () => {
|
|
889
|
+
try {
|
|
890
|
+
return Intl.DateTimeFormat().resolvedOptions().locale;
|
|
891
|
+
} catch {
|
|
892
|
+
return void 0;
|
|
893
|
+
}
|
|
754
894
|
};
|
|
895
|
+
var resolvePromptCopy = (language) => {
|
|
896
|
+
return COPY[(0, import_utils3.resolveLanguage)(language ?? deviceLanguage(), PROMPT_LANGUAGES, "en")];
|
|
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");
|
|
755
905
|
var OTP_LENGTH = 6;
|
|
906
|
+
var SHEET_MAX_WIDTH = 480;
|
|
907
|
+
var COMPACT_MAX_WIDTH = 360;
|
|
756
908
|
var PresenceOtpPrompt = ({
|
|
757
909
|
publishableKey,
|
|
758
910
|
options
|
|
759
911
|
}) => {
|
|
760
|
-
const [state, setState] = (0,
|
|
912
|
+
const [state, setState] = (0, import_react2.useState)(
|
|
761
913
|
IDLE_PRESENCE_OTP_STATE
|
|
762
914
|
);
|
|
763
|
-
const [code, setCode] = (0,
|
|
764
|
-
const [incomplete, setIncomplete] = (0,
|
|
765
|
-
const
|
|
766
|
-
const
|
|
767
|
-
const
|
|
768
|
-
(0,
|
|
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)(() => {
|
|
769
941
|
const controller = createPresenceOtpController(setState);
|
|
770
942
|
controllerRef.current = controller;
|
|
771
943
|
const unregister = (0, import_sdk9.registerPresenceOtpCodeProvider)(
|
|
@@ -780,11 +952,63 @@ var PresenceOtpPrompt = ({
|
|
|
780
952
|
setState(IDLE_PRESENCE_OTP_STATE);
|
|
781
953
|
};
|
|
782
954
|
}, [publishableKey]);
|
|
783
|
-
|
|
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)(() => {
|
|
784
969
|
setCode("");
|
|
785
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();
|
|
786
978
|
}, [state.request]);
|
|
787
|
-
(0,
|
|
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)(() => {
|
|
788
1012
|
const request = state.request;
|
|
789
1013
|
if (!request?.expiresAt || state.submitting) return;
|
|
790
1014
|
const expire = () => controllerRef.current?.expire(request);
|
|
@@ -799,160 +1023,451 @@ var PresenceOtpPrompt = ({
|
|
|
799
1023
|
const close = () => {
|
|
800
1024
|
controllerRef.current?.cancel();
|
|
801
1025
|
};
|
|
802
|
-
const submit = () => {
|
|
803
|
-
|
|
804
|
-
if (!/^\d{6}$/.test(normalized)) {
|
|
1026
|
+
const submit = (value = code) => {
|
|
1027
|
+
if (!/^\d{6}$/.test(value)) {
|
|
805
1028
|
setIncomplete(true);
|
|
806
1029
|
return;
|
|
807
1030
|
}
|
|
808
|
-
controllerRef.current?.submit(
|
|
1031
|
+
controllerRef.current?.submit(value);
|
|
809
1032
|
};
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
|
|
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
|
+
});
|
|
813
1066
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
814
|
-
|
|
1067
|
+
import_react_native2.Modal,
|
|
815
1068
|
{
|
|
816
|
-
visible
|
|
1069
|
+
visible,
|
|
817
1070
|
transparent: true,
|
|
818
1071
|
animationType: "fade",
|
|
819
1072
|
onRequestClose: close,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
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
|
+
)
|
|
886
1221
|
}
|
|
887
1222
|
);
|
|
888
1223
|
};
|
|
889
|
-
var
|
|
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({
|
|
890
1238
|
backdrop: {
|
|
891
|
-
flex: 1
|
|
1239
|
+
flex: 1
|
|
1240
|
+
},
|
|
1241
|
+
backdropSheet: {
|
|
1242
|
+
justifyContent: "flex-end"
|
|
1243
|
+
},
|
|
1244
|
+
backdropCentered: {
|
|
892
1245
|
alignItems: "center",
|
|
893
1246
|
justifyContent: "center",
|
|
894
|
-
padding: 16
|
|
895
|
-
backgroundColor: "rgba(0, 0, 0, 0.45)"
|
|
1247
|
+
padding: 16
|
|
896
1248
|
},
|
|
897
1249
|
card: {
|
|
898
1250
|
width: "100%",
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
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
|
|
902
1301
|
},
|
|
903
1302
|
title: {
|
|
904
1303
|
fontSize: 20,
|
|
905
|
-
|
|
1304
|
+
lineHeight: 24,
|
|
1305
|
+
fontWeight: "500",
|
|
1306
|
+
letterSpacing: -0.4,
|
|
1307
|
+
textAlign: "center"
|
|
906
1308
|
},
|
|
907
|
-
|
|
1309
|
+
description: {
|
|
908
1310
|
fontSize: 14,
|
|
909
|
-
|
|
1311
|
+
lineHeight: 20,
|
|
1312
|
+
textAlign: "center"
|
|
910
1313
|
},
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
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,
|
|
915
1330
|
borderRadius: 12,
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
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
|
|
920
1366
|
},
|
|
921
1367
|
error: {
|
|
922
|
-
|
|
923
|
-
|
|
1368
|
+
flexDirection: "row",
|
|
1369
|
+
alignItems: "center",
|
|
1370
|
+
justifyContent: "center",
|
|
1371
|
+
gap: 4
|
|
924
1372
|
},
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
1373
|
+
errorText: {
|
|
1374
|
+
flexShrink: 1,
|
|
1375
|
+
fontSize: 12,
|
|
1376
|
+
fontWeight: "500",
|
|
1377
|
+
textAlign: "center"
|
|
930
1378
|
},
|
|
931
|
-
|
|
932
|
-
|
|
1379
|
+
actions: {
|
|
1380
|
+
gap: 8,
|
|
1381
|
+
paddingTop: 24
|
|
1382
|
+
},
|
|
1383
|
+
button: {
|
|
1384
|
+
flexDirection: "row",
|
|
1385
|
+
alignItems: "center",
|
|
1386
|
+
justifyContent: "center",
|
|
1387
|
+
gap: 8,
|
|
1388
|
+
height: 48,
|
|
1389
|
+
paddingHorizontal: 20,
|
|
1390
|
+
borderRadius: 999
|
|
933
1391
|
},
|
|
934
|
-
|
|
1392
|
+
buttonText: {
|
|
935
1393
|
fontSize: 16,
|
|
936
|
-
fontWeight: "
|
|
1394
|
+
fontWeight: "500"
|
|
937
1395
|
},
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
alignItems: "center"
|
|
1396
|
+
pressed: {
|
|
1397
|
+
opacity: 0.88,
|
|
1398
|
+
transform: [{ scale: 0.985 }]
|
|
942
1399
|
},
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
fontWeight: "500"
|
|
1400
|
+
disabled: {
|
|
1401
|
+
opacity: 0.5
|
|
946
1402
|
},
|
|
947
1403
|
hint: {
|
|
948
1404
|
fontSize: 12,
|
|
949
|
-
|
|
1405
|
+
lineHeight: 16,
|
|
950
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
|
|
951
1466
|
}
|
|
952
1467
|
});
|
|
953
1468
|
|
|
954
1469
|
// src/transport/webview-bridge.ts
|
|
955
|
-
var
|
|
1470
|
+
var import_utils4 = require("@moon-x/core/utils");
|
|
956
1471
|
var RETRYABLE_METHODS = /* @__PURE__ */ new Set([
|
|
957
1472
|
"GET_APP_CONFIG",
|
|
958
1473
|
"GET_BALANCE",
|
|
@@ -970,7 +1485,7 @@ var RETRYABLE_METHODS = /* @__PURE__ */ new Set([
|
|
|
970
1485
|
var RETRY_ATTEMPT_TIMEOUTS_MS = [
|
|
971
1486
|
5e3,
|
|
972
1487
|
1e4,
|
|
973
|
-
|
|
1488
|
+
import_utils4.POST_MESSAGE_REQUEST_TIMEOUT_MS
|
|
974
1489
|
];
|
|
975
1490
|
var RETRY_BACKOFF_MS = [200, 400];
|
|
976
1491
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -1055,7 +1570,7 @@ var WebViewBridge = class {
|
|
|
1055
1570
|
resolver.resolve(message.data);
|
|
1056
1571
|
} else {
|
|
1057
1572
|
const err = new Error(message.error || "WebView bridge error");
|
|
1058
|
-
for (const key of
|
|
1573
|
+
for (const key of import_utils4.FORWARDED_ERROR_FIELDS) {
|
|
1059
1574
|
const value = message[key];
|
|
1060
1575
|
if (value !== void 0) {
|
|
1061
1576
|
err[key] = value;
|
|
@@ -1115,7 +1630,7 @@ var WebViewBridge = class {
|
|
|
1115
1630
|
type,
|
|
1116
1631
|
method,
|
|
1117
1632
|
payload,
|
|
1118
|
-
(0,
|
|
1633
|
+
(0, import_utils4.getPostMessageRequestTimeout)(method)
|
|
1119
1634
|
);
|
|
1120
1635
|
}
|
|
1121
1636
|
let lastError;
|
|
@@ -1215,7 +1730,7 @@ var WebViewBridge = class {
|
|
|
1215
1730
|
};
|
|
1216
1731
|
|
|
1217
1732
|
// src/provider.tsx
|
|
1218
|
-
var
|
|
1733
|
+
var import_react4 = require("@moon-x/core/react");
|
|
1219
1734
|
var import_lib2 = require("@moon-x/core/lib");
|
|
1220
1735
|
|
|
1221
1736
|
// src/webview-lifecycle.ts
|
|
@@ -1453,7 +1968,7 @@ function createNativeSession(reads) {
|
|
|
1453
1968
|
|
|
1454
1969
|
// src/session-resume.ts
|
|
1455
1970
|
var import_sdk10 = require("@moon-x/core/sdk");
|
|
1456
|
-
var
|
|
1971
|
+
var import_utils5 = require("@moon-x/core/utils");
|
|
1457
1972
|
var LOGOUT_TOMBSTONE = '{"loggedOut":true}';
|
|
1458
1973
|
var sharedStates = /* @__PURE__ */ new Map();
|
|
1459
1974
|
var sharedState = (publishableKey) => {
|
|
@@ -1637,8 +2152,8 @@ var createNativeSessionResume = ({
|
|
|
1637
2152
|
let result = null;
|
|
1638
2153
|
try {
|
|
1639
2154
|
result = await bridge.send(
|
|
1640
|
-
|
|
1641
|
-
|
|
2155
|
+
import_utils5.PostMessageType.AUTH,
|
|
2156
|
+
import_utils5.PostMessageMethod.SESSION_RESUME_BIND,
|
|
1642
2157
|
{ publishableKey, publicKey: record.publicKey }
|
|
1643
2158
|
);
|
|
1644
2159
|
} catch {
|
|
@@ -1661,8 +2176,8 @@ var createNativeSessionResume = ({
|
|
|
1661
2176
|
const sessionId = record?.sessionId;
|
|
1662
2177
|
if (!record || !sessionId) return false;
|
|
1663
2178
|
const check = await bridge.send(
|
|
1664
|
-
|
|
1665
|
-
|
|
2179
|
+
import_utils5.PostMessageType.AUTH,
|
|
2180
|
+
import_utils5.PostMessageMethod.IS_AUTHENTICATED,
|
|
1666
2181
|
{ publishableKey, resumeSessionId: sessionId }
|
|
1667
2182
|
);
|
|
1668
2183
|
if (check?.isAuthenticated === true) return true;
|
|
@@ -1675,8 +2190,8 @@ var createNativeSessionResume = ({
|
|
|
1675
2190
|
const signature = (0, import_sdk10.signSessionResume)(record.privateKey, sessionId, challenge);
|
|
1676
2191
|
if (!signature) return false;
|
|
1677
2192
|
const resumed = await bridge.send(
|
|
1678
|
-
|
|
1679
|
-
|
|
2193
|
+
import_utils5.PostMessageType.AUTH,
|
|
2194
|
+
import_utils5.PostMessageMethod.SESSION_RESUME,
|
|
1680
2195
|
{ publishableKey, sessionId, challenge, signature }
|
|
1681
2196
|
);
|
|
1682
2197
|
if (resumed?.resumeRejected) {
|
|
@@ -1750,7 +2265,7 @@ var createNativeSessionResume = ({
|
|
|
1750
2265
|
// src/provider.tsx
|
|
1751
2266
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1752
2267
|
var DEFAULT_IFRAME_URL = "https://x-iframe.moonpay.com";
|
|
1753
|
-
var MoonXContext = (0,
|
|
2268
|
+
var MoonXContext = (0, import_react3.createContext)(null);
|
|
1754
2269
|
var MoonXProvider = ({
|
|
1755
2270
|
publishableKey,
|
|
1756
2271
|
config,
|
|
@@ -1762,20 +2277,20 @@ var MoonXProvider = ({
|
|
|
1762
2277
|
var NativeProvider = ({ publishableKey, config, children }) => {
|
|
1763
2278
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
1764
2279
|
const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
|
|
1765
|
-
const webViewRef = (0,
|
|
1766
|
-
const bridge = (0,
|
|
2280
|
+
const webViewRef = (0, import_react3.useRef)(null);
|
|
2281
|
+
const bridge = (0, import_react3.useMemo)(
|
|
1767
2282
|
() => new WebViewBridge(
|
|
1768
2283
|
webViewRef
|
|
1769
2284
|
),
|
|
1770
2285
|
[]
|
|
1771
2286
|
);
|
|
1772
|
-
const relyingPartyOriginResolver = (0,
|
|
2287
|
+
const relyingPartyOriginResolver = (0, import_react3.useMemo)(
|
|
1773
2288
|
() => makeRelyingPartyOriginResolver(bridge, publishableKey, relyingPartyOrigin),
|
|
1774
2289
|
[bridge, publishableKey, relyingPartyOrigin]
|
|
1775
2290
|
);
|
|
1776
|
-
const [sensitiveVisible, setSensitiveVisible] = (0,
|
|
1777
|
-
const [captchaChallengeVisible, setCaptchaChallengeVisible] = (0,
|
|
1778
|
-
const cancelRef = (0,
|
|
2291
|
+
const [sensitiveVisible, setSensitiveVisible] = (0, import_react3.useState)(false);
|
|
2292
|
+
const [captchaChallengeVisible, setCaptchaChallengeVisible] = (0, import_react3.useState)(false);
|
|
2293
|
+
const cancelRef = (0, import_react3.useRef)(null);
|
|
1779
2294
|
const webViewVisible = sensitiveVisible || captchaChallengeVisible;
|
|
1780
2295
|
const [
|
|
1781
2296
|
{
|
|
@@ -1784,9 +2299,9 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1784
2299
|
key: webViewKey
|
|
1785
2300
|
},
|
|
1786
2301
|
dispatchWebViewLifecycle
|
|
1787
|
-
] = (0,
|
|
2302
|
+
] = (0, import_react3.useReducer)(webViewLifecycleReducer, initialWebViewLifecycleState);
|
|
1788
2303
|
const sessionResumeStorage = config?.sessionResumeStorage;
|
|
1789
|
-
const sessionResume = (0,
|
|
2304
|
+
const sessionResume = (0, import_react3.useMemo)(
|
|
1790
2305
|
() => sessionResumeStorage ? createNativeSessionResume({
|
|
1791
2306
|
bridge,
|
|
1792
2307
|
publishableKey,
|
|
@@ -1795,67 +2310,67 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1795
2310
|
}) : void 0,
|
|
1796
2311
|
[bridge, publishableKey, sessionResumeStorage]
|
|
1797
2312
|
);
|
|
1798
|
-
const session = (0,
|
|
2313
|
+
const session = (0, import_react3.useMemo)(
|
|
1799
2314
|
() => createNativeSession({
|
|
1800
|
-
getCurrentSession: () => bridge.send(
|
|
1801
|
-
getUser: () => bridge.send(
|
|
2315
|
+
getCurrentSession: () => bridge.send(import_utils6.PostMessageType.AUTH, import_utils6.PostMessageMethod.GET_CURRENT_SESSION, { publishableKey }),
|
|
2316
|
+
getUser: () => bridge.send(import_utils6.PostMessageType.AUTH, import_utils6.PostMessageMethod.GET_USER, { publishableKey }),
|
|
1802
2317
|
resume: sessionResume?.resume
|
|
1803
2318
|
}),
|
|
1804
2319
|
[bridge, publishableKey, sessionResume]
|
|
1805
2320
|
);
|
|
1806
|
-
const sessionSnapshot = (0,
|
|
2321
|
+
const sessionSnapshot = (0, import_react3.useSyncExternalStore)(session.subscribe, session.getSnapshot, session.getSnapshot);
|
|
1807
2322
|
const { isAuthenticated, user, revalidatedAt } = sessionSnapshot;
|
|
1808
2323
|
const { beginAuthFlow, refreshUser } = session;
|
|
1809
|
-
(0,
|
|
2324
|
+
(0, import_react3.useLayoutEffect)(() => {
|
|
1810
2325
|
session.mount();
|
|
1811
2326
|
return session.unmount;
|
|
1812
2327
|
}, [session]);
|
|
1813
|
-
(0,
|
|
2328
|
+
(0, import_react3.useEffect)(() => {
|
|
1814
2329
|
session.setReady(ready);
|
|
1815
2330
|
}, [session, ready]);
|
|
1816
2331
|
const { sessionStatus } = sessionSnapshot;
|
|
1817
|
-
(0,
|
|
2332
|
+
(0, import_react3.useEffect)(() => {
|
|
1818
2333
|
if (!sessionResume || !ready || sessionStatus !== "authenticated") return;
|
|
1819
2334
|
void sessionResume.bind();
|
|
1820
2335
|
}, [sessionResume, ready, sessionStatus, revalidatedAt]);
|
|
1821
|
-
(0,
|
|
1822
|
-
const subscription =
|
|
2336
|
+
(0, import_react3.useEffect)(() => {
|
|
2337
|
+
const subscription = import_react_native3.AppState.addEventListener("change", (nextState) => {
|
|
1823
2338
|
if (nextState === "active") {
|
|
1824
2339
|
session.restartSession();
|
|
1825
2340
|
}
|
|
1826
2341
|
});
|
|
1827
2342
|
return () => subscription.remove();
|
|
1828
2343
|
}, [session]);
|
|
1829
|
-
const { height: screenHeight } = (0,
|
|
2344
|
+
const { height: screenHeight } = (0, import_react_native3.useWindowDimensions)();
|
|
1830
2345
|
const SHEET_TOP_OFFSET = 80;
|
|
1831
|
-
const sheetTranslateY = (0,
|
|
1832
|
-
const backdropOpacity = (0,
|
|
1833
|
-
(0,
|
|
1834
|
-
|
|
1835
|
-
|
|
2346
|
+
const sheetTranslateY = (0, import_react3.useRef)(new import_react_native3.Animated.Value(screenHeight)).current;
|
|
2347
|
+
const backdropOpacity = (0, import_react3.useRef)(new import_react_native3.Animated.Value(0)).current;
|
|
2348
|
+
(0, import_react3.useEffect)(() => {
|
|
2349
|
+
import_react_native3.Animated.parallel([
|
|
2350
|
+
import_react_native3.Animated.timing(sheetTranslateY, {
|
|
1836
2351
|
toValue: webViewVisible ? 0 : screenHeight,
|
|
1837
2352
|
duration: 280,
|
|
1838
2353
|
useNativeDriver: true
|
|
1839
2354
|
}),
|
|
1840
|
-
|
|
2355
|
+
import_react_native3.Animated.timing(backdropOpacity, {
|
|
1841
2356
|
toValue: webViewVisible ? 0.5 : 0,
|
|
1842
2357
|
duration: 280,
|
|
1843
2358
|
useNativeDriver: true
|
|
1844
2359
|
})
|
|
1845
2360
|
]).start();
|
|
1846
2361
|
}, [webViewVisible, sheetTranslateY, backdropOpacity, screenHeight]);
|
|
1847
|
-
const initialSourceUri = (0,
|
|
2362
|
+
const initialSourceUri = (0, import_react3.useMemo)(() => {
|
|
1848
2363
|
const base = iframeUrl.replace(/\/$/, "");
|
|
1849
2364
|
const sep = base.includes("?") ? "&" : "?";
|
|
1850
2365
|
return `${base}${sep}publishableKey=${encodeURIComponent(publishableKey)}`;
|
|
1851
2366
|
}, [iframeUrl, publishableKey]);
|
|
1852
|
-
const handleMessage = (0,
|
|
2367
|
+
const handleMessage = (0, import_react3.useCallback)(
|
|
1853
2368
|
(event) => {
|
|
1854
2369
|
bridge.handleMessage({ nativeEvent: { data: event.nativeEvent.data } });
|
|
1855
2370
|
},
|
|
1856
2371
|
[bridge]
|
|
1857
2372
|
);
|
|
1858
|
-
const navigateWebView = (0,
|
|
2373
|
+
const navigateWebView = (0, import_react3.useCallback)(
|
|
1859
2374
|
(path) => {
|
|
1860
2375
|
const ref = webViewRef.current;
|
|
1861
2376
|
if (!ref) return;
|
|
@@ -1870,7 +2385,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1870
2385
|
},
|
|
1871
2386
|
[iframeUrl, publishableKey]
|
|
1872
2387
|
);
|
|
1873
|
-
const runSensitiveFlow = (0,
|
|
2388
|
+
const runSensitiveFlow = (0, import_react3.useCallback)(
|
|
1874
2389
|
(options) => {
|
|
1875
2390
|
setSensitiveVisible(true);
|
|
1876
2391
|
navigateWebView(options.flowPath);
|
|
@@ -1912,7 +2427,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1912
2427
|
},
|
|
1913
2428
|
[bridge, navigateWebView]
|
|
1914
2429
|
);
|
|
1915
|
-
const sdk = (0,
|
|
2430
|
+
const sdk = (0, import_react3.useMemo)(
|
|
1916
2431
|
() => createSdkInstance({
|
|
1917
2432
|
bridge,
|
|
1918
2433
|
publishableKey,
|
|
@@ -1944,18 +2459,18 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1944
2459
|
sessionSnapshot
|
|
1945
2460
|
]
|
|
1946
2461
|
);
|
|
1947
|
-
const sessionResumeRef = (0,
|
|
2462
|
+
const sessionResumeRef = (0, import_react3.useRef)(sessionResume);
|
|
1948
2463
|
sessionResumeRef.current = sessionResume;
|
|
1949
|
-
(0,
|
|
2464
|
+
(0, import_react3.useEffect)(() => {
|
|
1950
2465
|
return () => {
|
|
1951
2466
|
sessionResumeRef.current?.cancelPendingBinds();
|
|
1952
2467
|
bridge.cleanup("provider_unmounted");
|
|
1953
2468
|
};
|
|
1954
2469
|
}, [bridge]);
|
|
1955
|
-
(0,
|
|
2470
|
+
(0, import_react3.useEffect)(
|
|
1956
2471
|
() => bridge.register(
|
|
1957
|
-
|
|
1958
|
-
|
|
2472
|
+
import_utils6.PostMessageType.INIT,
|
|
2473
|
+
import_utils6.PostMessageMethod.CAPTCHA_CHALLENGE_VISIBILITY,
|
|
1959
2474
|
(payload) => {
|
|
1960
2475
|
if (typeof payload?.visible === "boolean") {
|
|
1961
2476
|
setCaptchaChallengeVisible(payload.visible);
|
|
@@ -1964,17 +2479,17 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1964
2479
|
),
|
|
1965
2480
|
[bridge]
|
|
1966
2481
|
);
|
|
1967
|
-
(0,
|
|
2482
|
+
(0, import_react3.useEffect)(() => {
|
|
1968
2483
|
const unsubscribe = bridge.onResponseError((error) => {
|
|
1969
2484
|
if (error.message === "no_session") session.retrySession();
|
|
1970
2485
|
});
|
|
1971
2486
|
return unsubscribe;
|
|
1972
2487
|
}, [bridge, session]);
|
|
1973
|
-
(0,
|
|
2488
|
+
(0, import_react3.useEffect)(() => {
|
|
1974
2489
|
let cancelled = false;
|
|
1975
2490
|
const unregister = bridge.register(
|
|
1976
|
-
|
|
1977
|
-
|
|
2491
|
+
import_utils6.PostMessageType.INIT,
|
|
2492
|
+
import_utils6.PostMessageMethod.READY,
|
|
1978
2493
|
() => {
|
|
1979
2494
|
if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
|
|
1980
2495
|
}
|
|
@@ -1988,7 +2503,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
1988
2503
|
clearTimeout(fallback);
|
|
1989
2504
|
};
|
|
1990
2505
|
}, [bridge, webViewRecoveryNonce]);
|
|
1991
|
-
const contextValue = (0,
|
|
2506
|
+
const contextValue = (0, import_react3.useMemo)(
|
|
1992
2507
|
() => ({
|
|
1993
2508
|
sdk,
|
|
1994
2509
|
_bridge: bridge,
|
|
@@ -2007,7 +2522,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
2007
2522
|
]
|
|
2008
2523
|
);
|
|
2009
2524
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
2010
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react4.SDKProvider, { value: sdk, children: [
|
|
2011
2526
|
children,
|
|
2012
2527
|
config?.presenceOtpPrompt !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2013
2528
|
PresenceOtpPrompt,
|
|
@@ -2017,14 +2532,14 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
2017
2532
|
}
|
|
2018
2533
|
),
|
|
2019
2534
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2020
|
-
|
|
2535
|
+
import_react_native3.Animated.View,
|
|
2021
2536
|
{
|
|
2022
2537
|
style: [styles2.backdrop, { opacity: backdropOpacity }],
|
|
2023
2538
|
pointerEvents: webViewVisible ? "auto" : "none",
|
|
2024
2539
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2025
|
-
|
|
2540
|
+
import_react_native3.Pressable,
|
|
2026
2541
|
{
|
|
2027
|
-
style:
|
|
2542
|
+
style: import_react_native3.StyleSheet.absoluteFill,
|
|
2028
2543
|
onPress: () => {
|
|
2029
2544
|
if (sensitiveVisible) cancelRef.current?.();
|
|
2030
2545
|
}
|
|
@@ -2033,7 +2548,7 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
2033
2548
|
}
|
|
2034
2549
|
),
|
|
2035
2550
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2036
|
-
|
|
2551
|
+
import_react_native3.Animated.View,
|
|
2037
2552
|
{
|
|
2038
2553
|
style: [
|
|
2039
2554
|
styles2.sheetContainer,
|
|
@@ -2045,16 +2560,16 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
2045
2560
|
pointerEvents: webViewVisible ? "auto" : "none",
|
|
2046
2561
|
children: [
|
|
2047
2562
|
sensitiveVisible && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2048
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2049
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2050
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2563
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native3.View, { style: styles2.sheetGrabber }),
|
|
2564
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native3.View, { style: styles2.modalChrome, children: [
|
|
2565
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native3.View, { style: styles2.modalTitleSpacer }),
|
|
2051
2566
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2052
|
-
|
|
2567
|
+
import_react_native3.Pressable,
|
|
2053
2568
|
{
|
|
2054
2569
|
onPress: () => cancelRef.current?.(),
|
|
2055
2570
|
hitSlop: 12,
|
|
2056
2571
|
style: styles2.closeButton,
|
|
2057
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2572
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native3.Text, { style: styles2.closeButtonText, children: closeLabel })
|
|
2058
2573
|
}
|
|
2059
2574
|
)
|
|
2060
2575
|
] })
|
|
@@ -2081,8 +2596,8 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
2081
2596
|
webviewDebuggingEnabled: __DEV__,
|
|
2082
2597
|
javaScriptEnabled: true,
|
|
2083
2598
|
domStorageEnabled: true,
|
|
2084
|
-
sharedCookiesEnabled:
|
|
2085
|
-
thirdPartyCookiesEnabled:
|
|
2599
|
+
sharedCookiesEnabled: import_react_native3.Platform.OS === "ios",
|
|
2600
|
+
thirdPartyCookiesEnabled: import_react_native3.Platform.OS === "android",
|
|
2086
2601
|
startInLoadingState: false,
|
|
2087
2602
|
originWhitelist: ["https://*", "http://*"],
|
|
2088
2603
|
style: styles2.webView
|
|
@@ -2095,13 +2610,13 @@ var NativeProvider = ({ publishableKey, config, children }) => {
|
|
|
2095
2610
|
] }) });
|
|
2096
2611
|
};
|
|
2097
2612
|
var useMoonXContext = () => {
|
|
2098
|
-
const ctx = (0,
|
|
2613
|
+
const ctx = (0, import_react3.useContext)(MoonXContext);
|
|
2099
2614
|
if (!ctx) {
|
|
2100
2615
|
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
2101
2616
|
}
|
|
2102
2617
|
return ctx;
|
|
2103
2618
|
};
|
|
2104
|
-
var styles2 =
|
|
2619
|
+
var styles2 = import_react_native3.StyleSheet.create({
|
|
2105
2620
|
backdrop: {
|
|
2106
2621
|
position: "absolute",
|
|
2107
2622
|
top: 0,
|
|
@@ -2151,7 +2666,7 @@ var styles2 = import_react_native2.StyleSheet.create({
|
|
|
2151
2666
|
paddingBottom: 12,
|
|
2152
2667
|
paddingHorizontal: 16,
|
|
2153
2668
|
backgroundColor: "#0a0a0a",
|
|
2154
|
-
borderBottomWidth:
|
|
2669
|
+
borderBottomWidth: import_react_native3.StyleSheet.hairlineWidth,
|
|
2155
2670
|
borderBottomColor: "#222"
|
|
2156
2671
|
},
|
|
2157
2672
|
// Empty flex spacer keeps the close button right-aligned without
|
|
@@ -2173,19 +2688,19 @@ var styles2 = import_react_native2.StyleSheet.create({
|
|
|
2173
2688
|
});
|
|
2174
2689
|
|
|
2175
2690
|
// src/hooks/index.ts
|
|
2176
|
-
var
|
|
2691
|
+
var import_react10 = require("@moon-x/core/react");
|
|
2177
2692
|
|
|
2178
2693
|
// src/hooks/use-app-config.ts
|
|
2179
|
-
var
|
|
2180
|
-
var
|
|
2694
|
+
var import_utils7 = require("@moon-x/core/utils");
|
|
2695
|
+
var import_react5 = require("react");
|
|
2181
2696
|
var useAppConfig = (publishableKey) => {
|
|
2182
2697
|
const { sdk, _bridge } = useMoonXContext();
|
|
2183
2698
|
const resolvedKey = publishableKey ?? sdk.publishableKey;
|
|
2184
2699
|
const ready = sdk.ready;
|
|
2185
|
-
const [appConfig, setAppConfig] = (0,
|
|
2186
|
-
const [isLoading, setIsLoading] = (0,
|
|
2187
|
-
const [error, setError] = (0,
|
|
2188
|
-
(0,
|
|
2700
|
+
const [appConfig, setAppConfig] = (0, import_react5.useState)(null);
|
|
2701
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(true);
|
|
2702
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
2703
|
+
(0, import_react5.useEffect)(() => {
|
|
2189
2704
|
if (!resolvedKey) {
|
|
2190
2705
|
setIsLoading(false);
|
|
2191
2706
|
return;
|
|
@@ -2199,7 +2714,7 @@ var useAppConfig = (publishableKey) => {
|
|
|
2199
2714
|
setError(null);
|
|
2200
2715
|
setAppConfig(null);
|
|
2201
2716
|
try {
|
|
2202
|
-
const config = await _bridge.send(
|
|
2717
|
+
const config = await _bridge.send(import_utils7.PostMessageType.AUTH, import_utils7.PostMessageMethod.GET_APP_CONFIG, {
|
|
2203
2718
|
publishableKey: resolvedKey
|
|
2204
2719
|
});
|
|
2205
2720
|
if (!cancelled) setAppConfig(config);
|
|
@@ -2220,8 +2735,7 @@ var useAppConfig = (publishableKey) => {
|
|
|
2220
2735
|
};
|
|
2221
2736
|
|
|
2222
2737
|
// src/hooks/use-attach-oauth.ts
|
|
2223
|
-
var
|
|
2224
|
-
var import_react5 = require("react");
|
|
2738
|
+
var import_react6 = require("react");
|
|
2225
2739
|
|
|
2226
2740
|
// src/lib/oauth-deep-link.ts
|
|
2227
2741
|
var openOAuthFlow = async ({
|
|
@@ -2261,8 +2775,8 @@ var parseOAuthRedirect = async (redirectUrl) => {
|
|
|
2261
2775
|
|
|
2262
2776
|
// src/hooks/use-attach-oauth.ts
|
|
2263
2777
|
var useAttachOAuth = (params) => {
|
|
2264
|
-
const { sdk,
|
|
2265
|
-
const [state, setState] = (0,
|
|
2778
|
+
const { sdk, _oauthRedirectUri } = useMoonXContext();
|
|
2779
|
+
const [state, setState] = (0, import_react6.useState)({ status: "idle" });
|
|
2266
2780
|
return {
|
|
2267
2781
|
state,
|
|
2268
2782
|
attachOAuth: async (provider) => {
|
|
@@ -2270,15 +2784,9 @@ var useAttachOAuth = (params) => {
|
|
|
2270
2784
|
try {
|
|
2271
2785
|
const redirectUri = params?.redirectUri || _oauthRedirectUri;
|
|
2272
2786
|
if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
|
|
2273
|
-
const startResult = await
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
{
|
|
2277
|
-
publishableKey: sdk.publishableKey,
|
|
2278
|
-
provider,
|
|
2279
|
-
attach: true,
|
|
2280
|
-
login_redirect_url: redirectUri
|
|
2281
|
-
}
|
|
2787
|
+
const startResult = await sdk.beginOAuthLink(
|
|
2788
|
+
provider,
|
|
2789
|
+
redirectUri
|
|
2282
2790
|
);
|
|
2283
2791
|
if (!startResult.redirect_url) {
|
|
2284
2792
|
throw new Error("start_oauth_failed");
|
|
@@ -2290,18 +2798,16 @@ var useAttachOAuth = (params) => {
|
|
|
2290
2798
|
});
|
|
2291
2799
|
const parsed = await parseOAuthRedirect(redirectUrl);
|
|
2292
2800
|
if (parsed.error) throw new Error(parsed.error);
|
|
2801
|
+
if (!parsed.code && !parsed.token) {
|
|
2802
|
+
throw new Error("oauth_no_code_or_token");
|
|
2803
|
+
}
|
|
2293
2804
|
setState({ status: "verifying" });
|
|
2294
|
-
await
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
code: parsed.code,
|
|
2301
|
-
token: parsed.token,
|
|
2302
|
-
state: parsed.state
|
|
2303
|
-
}
|
|
2304
|
-
);
|
|
2805
|
+
await sdk.verifyOAuthLink({
|
|
2806
|
+
provider,
|
|
2807
|
+
code: parsed.code,
|
|
2808
|
+
token: parsed.token,
|
|
2809
|
+
state: parsed.state
|
|
2810
|
+
});
|
|
2305
2811
|
setState({ status: "complete" });
|
|
2306
2812
|
} catch (e) {
|
|
2307
2813
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
@@ -2314,23 +2820,22 @@ var useAttachOAuth = (params) => {
|
|
|
2314
2820
|
};
|
|
2315
2821
|
|
|
2316
2822
|
// src/hooks/use-detach-oauth.ts
|
|
2317
|
-
var import_utils8 = require("@moon-x/core/utils");
|
|
2318
2823
|
var useDetachOAuth = () => {
|
|
2319
|
-
const { sdk
|
|
2824
|
+
const { sdk } = useMoonXContext();
|
|
2320
2825
|
return {
|
|
2826
|
+
// Removes a Google or Apple sign-in by its id in the user's
|
|
2827
|
+
// linked_accounts, with the presence step-up first when the backend asks
|
|
2828
|
+
// for one. Rejects with last_login_method rather than leave the account
|
|
2829
|
+
// with no way to sign in.
|
|
2321
2830
|
detachOAuth: async (idpUserId) => {
|
|
2322
|
-
await
|
|
2323
|
-
import_utils8.PostMessageType.AUTH,
|
|
2324
|
-
import_utils8.PostMessageMethod.DETACH_OAUTH,
|
|
2325
|
-
{ publishableKey: sdk.publishableKey, idpUserId }
|
|
2326
|
-
);
|
|
2831
|
+
await sdk.detachOAuth(idpUserId);
|
|
2327
2832
|
}
|
|
2328
2833
|
};
|
|
2329
2834
|
};
|
|
2330
2835
|
|
|
2331
2836
|
// src/hooks/use-export-key.ts
|
|
2332
2837
|
var import_sdk11 = require("@moon-x/core/sdk");
|
|
2333
|
-
var
|
|
2838
|
+
var import_utils8 = require("@moon-x/core/utils");
|
|
2334
2839
|
var parseExportKeyResult = (value) => {
|
|
2335
2840
|
if (!value || typeof value !== "object" || !("status" in value)) {
|
|
2336
2841
|
return { status: "failed", error: "invalid_export_key_result" };
|
|
@@ -2374,8 +2879,8 @@ var useExportKey = () => {
|
|
|
2374
2879
|
title: "Export key",
|
|
2375
2880
|
flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
|
|
2376
2881
|
onMount: ({ bridge, setResult }) => bridge.register(
|
|
2377
|
-
|
|
2378
|
-
|
|
2882
|
+
import_utils8.PostMessageType.WALLET,
|
|
2883
|
+
import_utils8.PostMessageMethod.EXPORT_KEY_RESULT,
|
|
2379
2884
|
(result) => {
|
|
2380
2885
|
setResult(parseExportKeyResult(result));
|
|
2381
2886
|
}
|
|
@@ -2398,13 +2903,13 @@ var useFundWallet = () => {
|
|
|
2398
2903
|
};
|
|
2399
2904
|
|
|
2400
2905
|
// src/hooks/use-login-with-email.ts
|
|
2401
|
-
var
|
|
2402
|
-
var
|
|
2906
|
+
var import_react7 = require("@moon-x/core/react");
|
|
2907
|
+
var import_react8 = require("react");
|
|
2403
2908
|
var useLoginWithEmail = (callbacks) => {
|
|
2404
|
-
const login = (0,
|
|
2909
|
+
const login = (0, import_react7.useLoginWithEmail)(callbacks);
|
|
2405
2910
|
const { _beginAuthFlow } = useMoonXContext();
|
|
2406
2911
|
const coreLoginWithCode = login.loginWithCode;
|
|
2407
|
-
const loginWithCode = (0,
|
|
2912
|
+
const loginWithCode = (0, import_react8.useCallback)(
|
|
2408
2913
|
async (params) => {
|
|
2409
2914
|
const finishAuthFlow = _beginAuthFlow();
|
|
2410
2915
|
try {
|
|
@@ -2419,14 +2924,14 @@ var useLoginWithEmail = (callbacks) => {
|
|
|
2419
2924
|
};
|
|
2420
2925
|
|
|
2421
2926
|
// src/hooks/use-login-with-oauth.ts
|
|
2422
|
-
var
|
|
2423
|
-
var
|
|
2927
|
+
var import_utils9 = require("@moon-x/core/utils");
|
|
2928
|
+
var import_react9 = require("react");
|
|
2424
2929
|
var useLoginWithOAuth = (params) => {
|
|
2425
2930
|
const { sdk, _bridge, _oauthRedirectUri, _beginAuthFlow } = useMoonXContext();
|
|
2426
|
-
const [state, setState] = (0,
|
|
2427
|
-
const activeFlow = (0,
|
|
2428
|
-
const mounted = (0,
|
|
2429
|
-
(0,
|
|
2931
|
+
const [state, setState] = (0, import_react9.useState)({ status: "idle" });
|
|
2932
|
+
const activeFlow = (0, import_react9.useRef)(null);
|
|
2933
|
+
const mounted = (0, import_react9.useRef)(true);
|
|
2934
|
+
(0, import_react9.useEffect)(() => {
|
|
2430
2935
|
mounted.current = true;
|
|
2431
2936
|
return () => {
|
|
2432
2937
|
mounted.current = false;
|
|
@@ -2453,8 +2958,8 @@ var useLoginWithOAuth = (params) => {
|
|
|
2453
2958
|
throw new Error("oauth_redirect_uri_missing");
|
|
2454
2959
|
}
|
|
2455
2960
|
const startResult = await _bridge.send(
|
|
2456
|
-
|
|
2457
|
-
|
|
2961
|
+
import_utils9.PostMessageType.AUTH,
|
|
2962
|
+
import_utils9.PostMessageMethod.START_OAUTH,
|
|
2458
2963
|
{
|
|
2459
2964
|
publishableKey: sdk.publishableKey,
|
|
2460
2965
|
provider,
|
|
@@ -2501,17 +3006,17 @@ var useLoginWithOAuth = (params) => {
|
|
|
2501
3006
|
var useMoonX = () => useMoonXContext().sdk;
|
|
2502
3007
|
|
|
2503
3008
|
// src/external-wallets/use-external-wallets.ts
|
|
2504
|
-
var
|
|
3009
|
+
var import_react11 = require("react");
|
|
2505
3010
|
var useExternalWallets = (connectors) => {
|
|
2506
|
-
const [wallets, setWallets] = (0,
|
|
2507
|
-
const [connected, setConnected] = (0,
|
|
3011
|
+
const [wallets, setWallets] = (0, import_react11.useState)([]);
|
|
3012
|
+
const [connected, setConnected] = (0, import_react11.useState)(
|
|
2508
3013
|
null
|
|
2509
3014
|
);
|
|
2510
|
-
const [status, setStatus] = (0,
|
|
2511
|
-
const [error, setError] = (0,
|
|
2512
|
-
const [refreshNonce, setRefreshNonce] = (0,
|
|
2513
|
-
const unsubscribeRef = (0,
|
|
2514
|
-
(0,
|
|
3015
|
+
const [status, setStatus] = (0, import_react11.useState)("idle");
|
|
3016
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
3017
|
+
const [refreshNonce, setRefreshNonce] = (0, import_react11.useState)(0);
|
|
3018
|
+
const unsubscribeRef = (0, import_react11.useRef)(null);
|
|
3019
|
+
(0, import_react11.useEffect)(() => {
|
|
2515
3020
|
let cancelled = false;
|
|
2516
3021
|
void Promise.all(
|
|
2517
3022
|
connectors.map(async (connector) => ({
|
|
@@ -2525,13 +3030,13 @@ var useExternalWallets = (connectors) => {
|
|
|
2525
3030
|
cancelled = true;
|
|
2526
3031
|
};
|
|
2527
3032
|
}, [connectors, refreshNonce]);
|
|
2528
|
-
(0,
|
|
3033
|
+
(0, import_react11.useEffect)(
|
|
2529
3034
|
() => () => {
|
|
2530
3035
|
unsubscribeRef.current?.();
|
|
2531
3036
|
},
|
|
2532
3037
|
[]
|
|
2533
3038
|
);
|
|
2534
|
-
const connect = (0,
|
|
3039
|
+
const connect = (0, import_react11.useCallback)(
|
|
2535
3040
|
async (id) => {
|
|
2536
3041
|
const connector = connectors.find((candidate) => candidate.info.id === id);
|
|
2537
3042
|
if (!connector) throw new Error(`External wallet "${id}" not found`);
|
|
@@ -2562,7 +3067,7 @@ var useExternalWallets = (connectors) => {
|
|
|
2562
3067
|
},
|
|
2563
3068
|
[connectors]
|
|
2564
3069
|
);
|
|
2565
|
-
const switchAccount = (0,
|
|
3070
|
+
const switchAccount = (0, import_react11.useCallback)(
|
|
2566
3071
|
async (address, chainId) => {
|
|
2567
3072
|
if (!connected) throw new Error("No external wallet connected");
|
|
2568
3073
|
const activeAccount = await connected.switchAccount(address, chainId);
|
|
@@ -2572,7 +3077,7 @@ var useExternalWallets = (connectors) => {
|
|
|
2572
3077
|
},
|
|
2573
3078
|
[connected]
|
|
2574
3079
|
);
|
|
2575
|
-
const disconnect = (0,
|
|
3080
|
+
const disconnect = (0, import_react11.useCallback)(async () => {
|
|
2576
3081
|
try {
|
|
2577
3082
|
await connected?.disconnect();
|
|
2578
3083
|
} finally {
|
|
@@ -2860,7 +3365,7 @@ var restoreWalletConnectSession = (options) => {
|
|
|
2860
3365
|
// src/index.ts
|
|
2861
3366
|
var import_sdk12 = require("@moon-x/core/sdk");
|
|
2862
3367
|
var import_sdk13 = require("@moon-x/core/sdk");
|
|
2863
|
-
var
|
|
3368
|
+
var import_utils10 = require("@moon-x/core/utils");
|
|
2864
3369
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2865
3370
|
0 && (module.exports = {
|
|
2866
3371
|
MOONPAY_CONSUMER_SESSION_ERROR_CODES,
|
|
@@ -2876,6 +3381,7 @@ var import_utils11 = require("@moon-x/core/utils");
|
|
|
2876
3381
|
useAppConfig,
|
|
2877
3382
|
useAttachOAuth,
|
|
2878
3383
|
useBulkImport,
|
|
3384
|
+
useChangeEmail,
|
|
2879
3385
|
useCreateWallet,
|
|
2880
3386
|
useDetachOAuth,
|
|
2881
3387
|
useEphemeralSigner,
|