Advertisement
Guest User

Untitled

a guest
May 28th, 2024
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.08 KB | None | 0 0
  1. import React, { useState, useEffect, Fragment } from 'react';
  2.  
  3. var VerifyUserComponent = function(props) {
  4. // Destructuring and initializing variables
  5. let onSuccessCallback = props.onSuccess;
  6. let {
  7. open: isOpen,
  8. loading: isLoading,
  9. error: hasError,
  10. securities: userSecurities,
  11. ready: isReady,
  12. hasFetchedSecurities: securitiesFetched,
  13. fetchingSecurities: isFetchingSecurities
  14. } = useAuthContext();
  15.  
  16. const [isVerified, setVerified] = useState(false); // Boolean state to track if user is verified
  17. const isGme = props.isGme; // Boolean to check if it's GME
  18.  
  19. // Default onSuccess callback if not provided
  20. if (!props.onSuccess) {
  21. onSuccessCallback = e => {
  22. console.log("Phone number confirmed", e);
  23. };
  24. }
  25.  
  26. // State variables
  27. const [currentStage, setCurrentStage] = useState("initial"); // String state for current process stage
  28. const [errorMessage, setErrorMessage] = useState(null); // Error state
  29. const authContext = useAuthContext(); // Custom hook or context
  30. const [isModalOpen, setModalOpen] = useState(false); // Boolean state for modal toggle
  31.  
  32. // Some date-related calculation
  33. const yearsUntil2103 = function() {
  34. let futureDate = new Date(2103, 9, 8);
  35. let currentDate = new Date();
  36. return calculateYears({
  37. start: currentDate,
  38. end: futureDate
  39. }).years + " years";
  40. }();
  41.  
  42. // Effects
  43. useEffect(() => {
  44. if (!authContext.authenticated && (isModalOpen || setCurrentStage("initial"))) {
  45. // Do something when not authenticated
  46. }
  47. }, [isModalOpen, authContext.authenticated]);
  48.  
  49. useEffect(() => {
  50. if (authContext.authenticated) {
  51. let userPhone;
  52. onSuccessCallback && onSuccessCallback((userPhone = authContext.user?.phone?.number) ?? "");
  53. setCurrentStage("success");
  54. }
  55. }, [authContext.authenticated]);
  56.  
  57. useEffect(() => {
  58. if (isGme && !isLoading && !hasError && securitiesFetched) {
  59. setModalOpen(true);
  60. setCurrentStage("gme");
  61. if (userSecurities.length > 0) {
  62. userSecurities.forEach(security => {
  63. if (security.ticker_symbol === "GME") setVerified(true);
  64. });
  65. }
  66. }
  67. }, [isReady, isLoading, hasError, userSecurities, isGme, securitiesFetched]);
  68.  
  69. // Render switch case based on state `currentStage`
  70. let content;
  71. switch (currentStage) {
  72. case "initial":
  73. case "login":
  74. content = <LoginComponent
  75. onSuccess={() => setCurrentStage("code")}
  76. onError={e => {
  77. setCurrentStage("error");
  78. setErrorMessage(e);
  79. }}
  80. />;
  81. break;
  82. case "code":
  83. content = <VerificationCodeComponent
  84. onSuccess={() => {
  85. let userPhone;
  86. setCurrentStage("success");
  87. onSuccessCallback && onSuccessCallback((userPhone = authContext.user?.phone?.number) ?? "");
  88. }}
  89. onError={e => {
  90. setCurrentStage("error");
  91. setErrorMessage(e);
  92. }}
  93. />;
  94. break;
  95. case "error":
  96. content = (
  97. <div className="flex flex-col gap-4 text-center w-full">
  98. <TextComponent
  99. variant="body05"
  100. className="text-red-700"
  101. >
  102. Something went wrong, please try again...
  103. </TextComponent>
  104. <TextComponent
  105. variant="body06"
  106. className="text-red-700"
  107. >
  108. {errorMessage?.message}
  109. </TextComponent>
  110. </div>
  111. );
  112. break;
  113. case "success":
  114. content = (
  115. <div className="flex flex-col gap-4 text-center">
  116. <TextComponent variant="body05">
  117. CONFIRMED
  118. </TextComponent>
  119. <TextComponent variant="body05">
  120. YOU ARE ON THE LIST. WE WILL TEXT YOU IN {yearsUntil2103}.
  121. </TextComponent>
  122. {isGme && (
  123. <ButtonComponent
  124. onClick={() => {
  125. setModalOpen(false);
  126. isOpen();
  127. }}
  128. disabled={!isReady || isLoading}
  129. />
  130. )}
  131. </div>
  132. );
  133. break;
  134. case "gme":
  135. content = (
  136. <div className="flex flex-col gap-4 text-center w-full">
  137. {isVerified ? (
  138. <Fragment>
  139. <TextComponent variant="body05">
  140. VERIFIED HOLDER
  141. </TextComponent>
  142. <TextComponent
  143. variant="body05"
  144. className="text-[32px] text-[#FF0000] animate-dot-blink"
  145. >
  146. GAMESTOP CORPORATION ORDINARY SHARES CLASS A - GME
  147. </TextComponent>
  148. <TextComponent variant="body05">
  149. YOU ARE ON THE LIST FOR REAL NOW.
  150. </TextComponent>
  151. </Fragment>
  152. ) : (
  153. <Fragment>
  154. <TextComponent variant="body05">
  155. NOT A HOLDER
  156. </TextComponent>
  157. <TextComponent
  158. variant="body05"
  159. className="text-lg"
  160. >
  161. 0 GAMESTOP CORPORATION ORDINARY SHARES CLASS A - GME FOUND
  162. </TextComponent>
  163. <TextComponent variant="body05">
  164. WE WILL TEXT YOU IN {yearsUntil2103}. GOODBYE.
  165. </TextComponent>
  166. </Fragment>
  167. )}
  168. </div>
  169. );
  170. break;
  171. default:
  172. content = (
  173. <TextComponent
  174. variant="body05"
  175. className="text-center"
  176. >
  177. Loading...
  178. </TextComponent>
  179. );
  180. }
  181.  
  182. // Conditional rendering based on `isGme` prop
  183. let verifyButton = props.isGme ? (
  184. isFetchingSecurities && !securitiesFetched ? (
  185. <TextComponent
  186. variant="body05"
  187. className="cursor-pointer"
  188. >
  189. VERIFYING...
  190. </TextComponent>
  191. ) : (
  192. <TextComponent
  193. variant="body05"
  194. className="cursor-pointer"
  195. >
  196. ENTER THE{" "}
  197. <TextComponent
  198. variant="body05"
  199. className="text-[#FF0000]"
  200. >
  201. CHAMBER
  202. </TextComponent>
  203. </TextComponent>
  204. )
  205. ) : (
  206. <TextComponent
  207. variant="body05"
  208. className="cursor-pointer"
  209. >
  210. ENTER THE CHAMBER
  211. </TextComponent>
  212. );
  213.  
  214. // Main component return
  215. return (
  216. <ModalComponent
  217. open={isModalOpen}
  218. onOpenChange={e => {
  219. setModalOpen(e);
  220. }}
  221. >
  222. <ModalTrigger asChild={true}>
  223. <Button
  224. variant="outline"
  225. className="focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent border-black px-24 hover:bg-transparent"
  226. onClick={() => trackEvent("EnterChamber")}
  227. >
  228. {verifyButton}
  229. </Button>
  230. </ModalTrigger>
  231. <ModalContent className="h-full flex items-center justify-center max-w-full py-6 px-6 md:py-12 md:px-12 bg-transparent border-none shadow-none">
  232. {authContext.ready ? (
  233. <div className="max-w-[450px] w-[450px] md:w-[525px] md:max-w-[525px]">
  234. {content}
  235. </div>
  236. ) : (
  237. <div className="self-center space-y-2 grow flex flex-col align-middle justify-center gap-2">
  238. <LoadingPlaceholder className="h-4 w-[250px] mx-auto" />
  239. <LoadingPlaceholder className="h-4 w-[200px] mx-auto" />
  240. </div>
  241. )}
  242. </ModalContent>
  243. </ModalComponent>
  244. );
  245. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement