@n1xyz/wallet-widget 0.0.29 → 0.0.30
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 +89 -11
- package/dist/Logic/sessionManager.js +8 -8
- package/dist/Logic/sessionManager.js.map +1 -1
- package/dist/Logic/transactionManager.d.ts +0 -22
- package/dist/Logic/transactionManager.js +0 -189
- package/dist/Logic/transactionManager.js.map +1 -1
- package/dist/Logic/utils.d.ts +3 -7
- package/dist/Logic/utils.js +3 -186
- package/dist/Logic/utils.js.map +1 -1
- package/dist/Modal/LoadingFallback.js +1 -1
- package/dist/Modal/LoadingFallback.js.map +1 -1
- package/dist/Modal/N1WalletModal.d.ts +1 -1
- package/dist/Modal/N1WalletModal.js +50 -205
- package/dist/Modal/N1WalletModal.js.map +1 -1
- package/dist/Modal/NTSFlow/views/CreateSessionView.d.ts +1 -1
- package/dist/Modal/NordFlow/NordFlow.js +44 -17
- package/dist/Modal/NordFlow/NordFlow.js.map +1 -1
- package/dist/Modal/NordFlow/components/ChainButton.d.ts +5 -2
- package/dist/Modal/NordFlow/components/ChainButton.js +16 -13
- package/dist/Modal/NordFlow/components/ChainButton.js.map +1 -1
- package/dist/Modal/NordFlow/components/EVMChainsButton.d.ts +2 -1
- package/dist/Modal/NordFlow/components/EVMChainsButton.js +11 -9
- package/dist/Modal/NordFlow/components/EVMChainsButton.js.map +1 -1
- package/dist/Modal/NordFlow/components/Header.d.ts +3 -1
- package/dist/Modal/NordFlow/components/Header.js +38 -4
- package/dist/Modal/NordFlow/components/Header.js.map +1 -1
- package/dist/Modal/NordFlow/components/ImageWithFallback.js +1 -1
- package/dist/Modal/NordFlow/components/ImageWithFallback.js.map +1 -1
- package/dist/Modal/NordFlow/components/MoreButton.d.ts +1 -1
- package/dist/Modal/NordFlow/components/MoreButton.js +4 -4
- package/dist/Modal/NordFlow/components/MoreButton.js.map +1 -1
- package/dist/Modal/NordFlow/components/TransactionTable.d.ts +1 -1
- package/dist/Modal/NordFlow/components/TransactionTable.js +11 -11
- package/dist/Modal/NordFlow/components/TransactionTable.js.map +1 -1
- package/dist/Modal/NordFlow/components/WaitingMessage.d.ts +3 -1
- package/dist/Modal/NordFlow/components/WaitingMessage.js +14 -3
- package/dist/Modal/NordFlow/components/WaitingMessage.js.map +1 -1
- package/dist/Modal/NordFlow/components/index.d.ts +0 -1
- package/dist/Modal/NordFlow/components/index.js +0 -1
- package/dist/Modal/NordFlow/components/index.js.map +1 -1
- package/dist/Modal/NordFlow/constants.js +12 -48
- package/dist/Modal/NordFlow/constants.js.map +1 -1
- package/dist/Modal/NordFlow/context/DepositContext.js +112 -41
- package/dist/Modal/NordFlow/context/DepositContext.js.map +1 -1
- package/dist/Modal/NordFlow/context/FlowContext.d.ts +1 -0
- package/dist/Modal/NordFlow/context/FlowContext.js +99 -6
- package/dist/Modal/NordFlow/context/FlowContext.js.map +1 -1
- package/dist/Modal/NordFlow/context/WalletConnectContext.js +76 -20
- package/dist/Modal/NordFlow/context/WalletConnectContext.js.map +1 -1
- package/dist/Modal/NordFlow/hoc/withImageFallback.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useTestnetFaucet.d.ts +2 -1
- package/dist/Modal/NordFlow/hooks/useTestnetFaucet.js +26 -7
- package/dist/Modal/NordFlow/hooks/useTestnetFaucet.js.map +1 -1
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.d.ts +1 -1
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.js +10 -15
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/02-ChainSelectionScreen.js +103 -54
- package/dist/Modal/NordFlow/screens/02-ChainSelectionScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/03-AmountInputScreen.d.ts +1 -2
- package/dist/Modal/NordFlow/screens/03-AmountInputScreen.js +284 -60
- package/dist/Modal/NordFlow/screens/03-AmountInputScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/04-DepositProgressScreen.js +2 -2
- package/dist/Modal/NordFlow/screens/04-DepositProgressScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/05-DepositSuccessScreen.js +97 -110
- package/dist/Modal/NordFlow/screens/05-DepositSuccessScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/06-AuthLoadingScreen.js +10 -8
- package/dist/Modal/NordFlow/screens/06-AuthLoadingScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/index.d.ts +5 -9
- package/dist/Modal/NordFlow/screens/index.js +5 -9
- package/dist/Modal/NordFlow/screens/index.js.map +1 -1
- package/dist/Modal/NordFlow/types.d.ts +13 -3
- package/dist/Modal/NordFlow/types.js +4 -3
- package/dist/Modal/NordFlow/types.js.map +1 -1
- package/dist/Modal/NordFlow/utils/depositStorage.d.ts +4 -0
- package/dist/Modal/NordFlow/utils/depositStorage.js +48 -0
- package/dist/Modal/NordFlow/utils/depositStorage.js.map +1 -0
- package/dist/Modal/NordFlow/utils/nordUtils.d.ts +1 -1
- package/dist/Modal/NordFlow/utils/nordUtils.js +1 -1
- package/dist/Modal/NordFlow/utils/nordUtils.js.map +1 -1
- package/dist/Provider/LazyWalletProvider.d.ts +1 -1
- package/dist/Provider/LazyWalletProvider.js +38 -38
- package/dist/Provider/LazyWalletProvider.js.map +1 -1
- package/dist/Provider/N1WalletProvider.d.ts +2 -1
- package/dist/Provider/N1WalletProvider.js +85 -82
- package/dist/Provider/N1WalletProvider.js.map +1 -1
- package/dist/Provider/ShadowRootWrapper.d.ts +1 -1
- package/dist/Provider/WalletErrorBoundary.d.ts +9 -2
- package/dist/Provider/WalletErrorBoundary.js +19 -1
- package/dist/Provider/WalletErrorBoundary.js.map +1 -1
- package/dist/Provider/hooks/useNordUserInitialization.js +87 -35
- package/dist/Provider/hooks/useNordUserInitialization.js.map +1 -1
- package/dist/Provider/icons/CoinbaseWalletIcon.d.ts +1 -1
- package/dist/Provider/icons/ConnectionDotsSVG.d.ts +1 -1
- package/dist/Provider/icons/MetamaskIcon.d.ts +1 -1
- package/dist/Provider/icons/PhantomIcon.d.ts +1 -1
- package/dist/Provider/icons/UserIcon.d.ts +1 -1
- package/dist/Provider/icons/WalletConnectIcon.d.ts +1 -1
- package/dist/Provider/types.d.ts +18 -16
- package/dist/Provider/types.js +8 -2
- package/dist/Provider/types.js.map +1 -1
- package/dist/WidgetButton/N1ConnectButton.d.ts +1 -1
- package/dist/WidgetButton/N1ConnectButton.js +29 -10
- package/dist/WidgetButton/N1ConnectButton.js.map +1 -1
- package/dist/components/Logo.d.ts +2 -1
- package/dist/components/Logo.js +5 -2
- package/dist/components/Logo.js.map +1 -1
- package/dist/components/QRCodeLoader.d.ts +1 -1
- package/dist/components/QRCodeLoader.js +1 -1
- package/dist/components/QRCodeLoader.js.map +1 -1
- package/dist/components/logos/EVMChainsGroup.js +1 -1
- package/dist/components/logos/EVMChainsGroup.js.map +1 -1
- package/dist/components/logos/MoreChainsGroup.js +1 -1
- package/dist/components/logos/MoreChainsGroup.js.map +1 -1
- package/dist/components/logos/index.d.ts +0 -2
- package/dist/components/logos/index.js +0 -2
- package/dist/components/logos/index.js.map +1 -1
- package/dist/config/solana.d.ts +3 -15
- package/dist/config/solana.js +6 -29
- package/dist/config/solana.js.map +1 -1
- package/dist/embedded-main-css.d.ts +1 -1
- package/dist/embedded-main-css.js +1 -1
- package/dist/embedded-main-css.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.css +2 -2
- package/dist/polyfills/windowEthereumGuard.d.ts +6 -0
- package/dist/polyfills/windowEthereumGuard.js +28 -0
- package/dist/polyfills/windowEthereumGuard.js.map +1 -0
- package/package.json +26 -11
- package/dist/utils/dynamicImports.d.ts +0 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DepositContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/DepositContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;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AiB,mBAAA;QACjB,YAAY,cAAA;QACZ,YAAY,cAAA;QACZ,eAAe,iBAAA;QACf,WAAW,aAAA;KACZ,CAAC;IAGF;;OAEG;IACH,SAAS,CAAC;QACR,IAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC;QAE3C,yEAAyE;QACzE,IAAI,OAAO,CAAC,aAAa,KAAK,WAAW,CAAC,aAAa,EAAE,CAAC;YACxD,gBAAgB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;YAC1C,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,OAAO,CAAC,aAAa,KAAK,WAAW,CAAC,aAAa,EAAE,CAAC;YACxD,gBAAgB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC1C,CAAC;QAED,wCAAwC;QACxC,cAAc,CAAC,OAAO,GAAG,OAAO,CAAC;IACnC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAId,OAAO,CACL,KAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YACzC,QAAQ,GACe,CAC3B,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG;IAC/B,IAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport {\n getExplorerUrl,\n TransactionResult,\n} from '../../../Logic/transactionManager';\nimport {\n useN1WalletContext,\n useN1WalletInternalContext,\n} from '../../../Provider/hooks';\nimport { N1SessionMode } from '../../../Provider/types';\nimport { logger } from '../../../utils/logger';\nimport { AVAILABLE_CHAINS } from '../constants';\nimport { FlowState } from '../types';\nimport { isNordConfigured } from '../utils/nordUtils';\nimport { useFlowStateContext } from './FlowContext';\n\n// Define the shape of the deposit context value\nexport interface DepositContextValue {\n amount: string;\n isDepositing: boolean;\n transactionId: string | null;\n transactionResult: TransactionResult | null;\n authStatus: 'loading' | 'success' | 'error';\n authErrorMessage: string | null;\n authStatusMessage: string | null;\n updateAmount: (newAmount: string) => void;\n startDeposit: () => Promise<void>;\n completeDeposit: () => void;\n performAuth: () => Promise<void>;\n}\n\n// Create the context with a default value\nconst DepositContext = createContext<DepositContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface DepositProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the deposit context\n */\nexport const DepositProvider: React.FC<DepositProviderProps> = ({\n children,\n}) => {\n // Get flow state context\n const {\n state,\n context,\n transition,\n updateContext,\n } = useFlowStateContext();\n\n // Get wallet context\n const {\n address,\n nord,\n signMessageWithSessionKey,\n nordUser,\n } = useN1WalletContext();\n const { sessionMode } = useN1WalletInternalContext();\n\n // chain\n const [selectedChain, setSelectedChain] = useState<string | null>(\n context.selectedChain\n );\n\n // transaction & deposit\n const [amount, setAmount] = useState(context.amount);\n const [isDepositing, setIsDepositing] = useState(false);\n const [transactionId, setTransactionId] = useState<string | null>(context.transactionId);\n const [transactionResult, setTransactionResult] = useState<TransactionResult | null>(null);\n\n\n // auth\n const [authStatus, setAuthStatus] = useState<'loading' | 'success' | 'error'>('loading');\n const [authErrorMessage, setAuthErrorMessage] = useState<string | null>(null);\n const [authStatusMessage, setAuthStatusMessage] = useState<string | null>(null);\n\n // Use refs to track previous values\n const prevContextRef = useRef(context);\n\n\n /**\n * Handle an error by transitioning to error state\n */\n const handleError = useCallback(\n (error: Error) => {\n logger.error('Flow error:', error);\n transition(FlowState.ERROR, { error });\n },\n [transition]\n );\n\n /**\n * Authenticate session\n */\n const performAuth = useCallback(async () => {\n try {\n // Step 1: Tell user to sign transaction\n setAuthStatusMessage(\n 'Please sign the transaction to authenticate your session'\n );\n\n if (!nordUser) {\n throw new Error('Nord user is not initialized');\n }\n\n // Step 2: Call nordUser.refreshSession and get sessionId\n setAuthStatusMessage('Session is being authenticated...');\n\n // Get the session public key from the nordUser\n const sessionPubKey = nordUser.sessionPubKey;\n if (!sessionPubKey) {\n throw new Error('Session public key is not available');\n }\n\n // Refresh the session\n await nordUser.refreshSession(sessionPubKey);\n await nordUser.updateAccountId();\n\n // Get the sessionId after refresh\n const sessionId = nordUser.sessionId;\n if (!sessionId) {\n throw new Error('Failed to get session ID after refresh');\n }\n\n logger.debug('Session refreshed successfully', {\n sessionId: sessionId.toString(),\n });\n\n // Step 3: Store sessionId in localStorage\n if (address) {\n const sessionIdKey = `n1_sessionId_${address}`;\n localStorage.setItem(sessionIdKey, sessionId.toString());\n logger.debug('Stored sessionId in localStorage', { key: sessionIdKey });\n }\n\n // Step 4: Update status to success\n setAuthStatus('success');\n\n // updateContext({ hasActiveSession: true });\n setTimeout(() => {\n transition(FlowState.FINAL_SUCCESS, { hasActiveSession: true, hasNordAccount: true });\n }, 100);\n\n } catch (error) {\n console.error('Authentication error:', error);\n setAuthStatus('error');\n setAuthErrorMessage(\n error instanceof Error ? error.message : 'Unknown error occurred'\n );\n }\n }, [updateContext, transition, address, nordUser]);\n\n /**\n * Update amount for deposit\n */\n const updateAmount = useCallback(\n (newAmount: string) => {\n setAmount(newAmount);\n if (state === FlowState.AMOUNT_INPUT) {\n updateContext({ amount: newAmount });\n } else {\n transition(state, { amount: newAmount });\n }\n },\n [state, transition, updateContext]\n );\n\n /**\n * Start deposit process\n */\n const startDeposit = useCallback(async () => {\n if (isDepositing) return;\n\n logger.debug('Starting deposit process');\n\n if (!amount || parseFloat(amount) <= 0) {\n handleError(new Error('Invalid amount'));\n return;\n }\n\n setIsDepositing(true);\n transition(FlowState.DEPOSIT_PROGRESS);\n\n try {\n const usdcToken = nord!.tokens.find((t: any) => t.symbol === 'USDC');\n\n const txId = await nordUser.depositSpl(\n parseFloat(amount),\n usdcToken!.tokenId\n );\n\n let accountInitialized = false;\n for (let i = 0; i < 70; i++) {\n const exists = await nord?.getUser({ pubkey: address });\n if (exists) {\n accountInitialized = true;\n break;\n }\n await new Promise((resolve) => setTimeout(resolve, 5000));\n }\n\n if (!accountInitialized) {\n throw new Error('Account failed to intialize on N1.');\n }\n\n logger.debug('Deposit successful using Nord-TS', txId);\n\n // Create transaction result object immediately after successful deposit\n const result: TransactionResult = {\n success: true,\n transactionId: txId,\n amount,\n tokenSymbol: 'USDC',\n fromAddress: address || 'Your Wallet',\n toAddress: 'Exchange Account',\n networkName: selectedChain!,\n status: 'Completed',\n explorerUrl: getExplorerUrl(txId),\n };\n\n // Update state with transaction result\n setTransactionId(txId);\n setTransactionResult(result);\n logger.debug('Transaction completed successfully');\n transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId, hasNordAccount: true });\n } catch (depositError) {\n logger.warn('Error using depositSpl, falling back to mock implementation:', depositError);\n setIsDepositing(false);\n const errorMessage = depositError instanceof Error\n ? depositError.message\n : 'Failed to process deposit';\n\n transition(FlowState.AMOUNT_INPUT, {\n depositError: errorMessage\n });\n return; // Exit early\n }\n }, [\n isDepositing,\n selectedChain,\n amount,\n address,\n sessionMode,\n transition,\n handleError,\n nord,\n signMessageWithSessionKey,\n nordUser,\n ]);\n\n /**\n * Complete the deposit process and move to the next screen\n */\n const completeDeposit = useCallback(() => {\n // Check if user has an active session to determine the next state\n if (context.hasActiveSession) {\n // If user has an active session, go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });\n } else {\n // Check if there's a sessionId stored in localStorage\n const sessionIdKey = `n1_sessionId_${address}`;\n const storedSessionId = localStorage.getItem(sessionIdKey);\n\n if (storedSessionId !== null) {\n // If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });\n } else {\n // If user doesn't have an active session and no sessionId in localStorage, go to NORD_AUTH\n transition(FlowState.AUTH_LOADING, { hasNordAccount: true });\n }\n }\n }, [context.hasActiveSession, transition, address]);\n\n\n\n\n\n // Create the context value\n const contextValue: DepositContextValue = {\n amount,\n isDepositing,\n transactionId,\n transactionResult,\n authStatus,\n authErrorMessage,\n authStatusMessage,\n updateAmount,\n startDeposit,\n completeDeposit,\n performAuth,\n };\n\n\n /**\n * Update state based on context changes\n */\n useEffect(() => {\n const prevContext = prevContextRef.current;\n\n // Only update state if the relevant context values have actually changed\n if (context.selectedChain !== prevContext.selectedChain) {\n setSelectedChain(context.selectedChain);\n }\n\n if (context.amount !== prevContext.amount) {\n setAmount(context.amount);\n }\n\n if (context.transactionId !== prevContext.transactionId) {\n setTransactionId(context.transactionId);\n }\n\n // Update the ref to the current context\n prevContextRef.current = context;\n }, [context]);\n\n\n\n return (\n <DepositContext.Provider value={contextValue}>\n {children}\n </DepositContext.Provider>\n );\n};\n\n/**\n * Hook to use the deposit context\n */\nexport const useDepositContext = (): DepositContextValue => {\n const context = useContext(DepositContext);\n if (context === undefined) {\n throw new Error('useDepositContext must be used within a DepositProvider');\n }\n return context;\n}; \n"]}
|
|
1
|
+
{"version":3,"file":"DepositContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/DepositContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EACL,cAAc,GAEf,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,O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,YAAY,YACzC,QAAQ,GACe,CAC3B,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG;IAC/B,IAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport {\n getExplorerUrl,\n TransactionResult,\n} from '../../../Logic/transactionManager';\nimport { useN1WalletContext } from '../../../Provider/hooks';\nimport { logger } from '../../../utils/logger';\nimport { AVAILABLE_CHAINS } from '../constants';\nimport { FlowState } from '../types';\nimport { useFlowStateContext } from './FlowContext';\nimport { clearLastDepositRecord, saveLastDepositRecord } from '../utils/depositStorage';\n\n// Define the shape of the deposit context value\nexport interface DepositContextValue {\n amount: string;\n isDepositing: boolean;\n transactionId: string | null;\n transactionResult: TransactionResult | null;\n authStatus: 'loading' | 'success' | 'error';\n authErrorMessage: string | null;\n authStatusMessage: string | null;\n updateAmount: (newAmount: string) => void;\n startDeposit: () => Promise<void>;\n completeDeposit: () => void;\n performAuth: () => Promise<void>;\n}\n\n// Create the context with a default value\nconst DepositContext = createContext<DepositContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface DepositProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the deposit context\n */\nexport const DepositProvider: React.FC<DepositProviderProps> = ({\n children,\n}) => {\n // Get flow state context\n const {\n state,\n context,\n transition,\n updateContext,\n isDebugOverride,\n } = useFlowStateContext();\n\n // Get wallet context\n const {\n address,\n nord,\n nordUser,\n } = useN1WalletContext();\n\n // chain\n const [selectedChain, setSelectedChain] = useState<string | null>(\n context.selectedChain\n );\n\n // transaction & deposit\n const [amount, setAmount] = useState(context.amount);\n const [isDepositing, setIsDepositing] = useState(false);\n const [transactionId, setTransactionId] = useState<string | null>(context.transactionId);\n const [transactionResult, setTransactionResult] = useState<TransactionResult | null>(null);\n\n\n // auth\n const [authStatus, setAuthStatus] = useState<'loading' | 'success' | 'error'>('loading');\n const [authErrorMessage, setAuthErrorMessage] = useState<string | null>(null);\n const [authStatusMessage, setAuthStatusMessage] = useState<string | null>(null);\n\n // Use refs to track previous values\n const prevContextRef = useRef(context);\n\n\n /**\n * Handle an error by transitioning to error state\n */\n const handleError = useCallback(\n (error: Error) => {\n logger.error('Flow error:', error);\n transition(FlowState.ERROR, { error });\n },\n [transition]\n );\n\n const authInFlightRef = useRef(false);\n const waitingForNordUserRef = useRef(false);\n\n /**\n * Authenticate session\n */\n const performAuth = useCallback(async () => {\n if (authInFlightRef.current) {\n return;\n }\n\n authInFlightRef.current = true;\n try {\n // Step 1: Tell user to sign transaction\n setAuthStatusMessage(\n 'Please sign the transaction to authenticate your session'\n );\n\n if (!nordUser) {\n waitingForNordUserRef.current = true;\n setAuthStatus('loading');\n setAuthStatusMessage('Preparing your Nord session…');\n return;\n }\n\n waitingForNordUserRef.current = false;\n\n // Step 2: Call nordUser.refreshSession and get sessionId\n setAuthStatusMessage('Session is being authenticated...');\n\n // Get the session public key from the nordUser\n const sessionPubKey = nordUser.sessionPubKey;\n if (!sessionPubKey) {\n throw new Error('Session public key is not available');\n }\n\n // Refresh the session\n await nordUser.refreshSession();\n await nordUser.updateAccountId();\n\n console.log('nordUser', nordUser);\n\n // Get the sessionId after refresh\n const sessionId = nordUser.sessionId;\n if (!sessionId) {\n throw new Error('Failed to get session ID after refresh');\n }\n\n logger.debug('Session refreshed successfully', {\n sessionId: sessionId.toString(),\n });\n\n // Step 3: Store sessionId in localStorage\n if (address) {\n const sessionIdKey = `n1_sessionId_${address}`;\n localStorage.setItem(sessionIdKey, sessionId.toString());\n logger.debug('Stored sessionId in localStorage', { key: sessionIdKey });\n }\n\n // Step 4: Update status to success\n setAuthStatus('success');\n\n // updateContext({ hasActiveSession: true });\n setTimeout(() => {\n transition(FlowState.FINAL_SUCCESS, { hasActiveSession: true, hasNordAccount: true });\n }, 100);\n\n } catch (error) {\n console.error('Authentication error:', error);\n setAuthStatus('error');\n setAuthErrorMessage(\n error instanceof Error ? error.message : 'Unknown error occurred'\n );\n } finally {\n authInFlightRef.current = false;\n }\n }, [\n updateContext,\n transition,\n address,\n nordUser,\n setAuthStatus,\n setAuthStatusMessage,\n setAuthErrorMessage,\n ]);\n\n useEffect(() => {\n if (waitingForNordUserRef.current && nordUser) {\n performAuth();\n }\n }, [nordUser, performAuth]);\n\n /**\n * Update amount for deposit\n */\n const updateAmount = useCallback(\n (newAmount: string) => {\n setAmount(newAmount);\n if (state === FlowState.AMOUNT_INPUT) {\n updateContext({ amount: newAmount });\n } else {\n transition(state, { amount: newAmount });\n }\n },\n [state, transition, updateContext]\n );\n\n /**\n * Start deposit process\n */\n const startDeposit = useCallback(async () => {\n if (isDepositing) return;\n\n logger.debug('Starting deposit process');\n\n if (!amount || parseFloat(amount) <= 0) {\n handleError(new Error('Invalid amount'));\n return;\n }\n\n setIsDepositing(true);\n transition(FlowState.DEPOSIT_PROGRESS);\n\n try {\n const usdcToken = nord!.tokens.find((t: any) => t.symbol === 'USDC');\n\n const txId = await nordUser.depositSpl(\n parseFloat(amount),\n usdcToken!.tokenId\n );\n\n let accountInitialized = false;\n for (let i = 0; i < 70; i++) {\n const exists = await nord?.getUser({ pubkey: address });\n if (exists) {\n accountInitialized = true;\n break;\n }\n await new Promise((resolve) => setTimeout(resolve, 5000));\n }\n\n if (!accountInitialized) {\n throw new Error('Account failed to intialize on N1.');\n }\n\n logger.debug('Deposit successful using Nord-TS', txId);\n\n // Create transaction result object immediately after successful deposit\n const result: TransactionResult = {\n success: true,\n transactionId: txId,\n amount,\n tokenSymbol: 'USDC',\n fromAddress: address || 'Your Wallet',\n toAddress: 'Exchange Account',\n networkName: selectedChain!,\n status: 'Completed',\n explorerUrl: getExplorerUrl(txId),\n };\n\n const depositRecord = {\n transactionId: txId,\n amount,\n tokenSymbol: 'USDC',\n chainId: context.selectedChainId ?? (selectedChain ?? 'solana'),\n chainName: context.selectedChain ?? (selectedChain ?? 'Solana'),\n chainNetwork: context.selectedChainNetwork ?? null,\n timestamp: Date.now(),\n };\n\n saveLastDepositRecord(address, depositRecord);\n\n // Update state with transaction result\n setTransactionId(txId);\n setTransactionResult(result);\n logger.debug('Transaction completed successfully');\n transition(FlowState.DEPOSIT_SUCCESS, {\n transactionId: txId,\n hasNordAccount: true,\n lastDeposit: depositRecord,\n });\n } catch (depositError) {\n logger.warn('Error using depositSpl, falling back to mock implementation:', depositError);\n setIsDepositing(false);\n const errorMessage = depositError instanceof Error\n ? depositError.message\n : 'Failed to process deposit';\n\n transition(FlowState.AMOUNT_INPUT, {\n depositError: errorMessage\n });\n return; // Exit early\n }\n }, [\n isDepositing,\n selectedChain,\n amount,\n address,\n transition,\n handleError,\n nord,\n nordUser,\n context.selectedChain,\n context.selectedChainId,\n context.selectedChainNetwork,\n ]);\n\n /**\n * Complete the deposit process and move to the next screen\n */\n const completeDeposit = useCallback(() => {\n clearLastDepositRecord(address);\n updateContext({ lastDeposit: null });\n\n if (context.isDepositOnlyFlow) {\n transition(FlowState.FINAL_SUCCESS, {\n hasNordAccount: true,\n hasActiveSession: true,\n isDepositOnlyFlow: false,\n });\n return;\n }\n\n // Check if user has an active session to determine the next state\n if (context.hasActiveSession) {\n // If user has an active session, go directly to FINAL_SUCCESS\n transition(FlowState.FINAL_SUCCESS, {\n hasNordAccount: true,\n hasActiveSession: true,\n isDepositOnlyFlow: false,\n });\n } else {\n // If user doesn't have an active session, go to authentication flow\n transition(FlowState.AUTH_LOADING, { hasNordAccount: true });\n }\n }, [context.hasActiveSession, context.isDepositOnlyFlow, transition, address, updateContext]);\n\n\n\n\n\n // Create the context value\n const contextValue: DepositContextValue = {\n amount,\n isDepositing,\n transactionId,\n transactionResult,\n authStatus,\n authErrorMessage,\n authStatusMessage,\n updateAmount,\n startDeposit,\n completeDeposit,\n performAuth,\n };\n\n\n /**\n * Update state based on context changes\n */\n useEffect(() => {\n const prevContext = prevContextRef.current;\n\n // Only update state if the relevant context values have actually changed\n if (context.selectedChain !== prevContext.selectedChain) {\n setSelectedChain(context.selectedChain);\n }\n\n if (context.amount !== prevContext.amount) {\n setAmount(context.amount);\n }\n\n if (context.transactionId !== prevContext.transactionId) {\n setTransactionId(context.transactionId);\n }\n\n // Update the ref to the current context\n prevContextRef.current = context;\n }, [context]);\n\n useEffect(() => {\n if (!isDebugOverride || state !== FlowState.DEPOSIT_SUCCESS || transactionResult) {\n return;\n }\n\n const mockTransactionId = context.transactionId ?? 'debug-tx-12345';\n const fallbackChain = context.selectedChain ?? AVAILABLE_CHAINS[0]?.name ?? 'Solana';\n setTransactionId(mockTransactionId);\n setTransactionResult({\n success: true,\n transactionId: mockTransactionId,\n amount: context.amount || '1,250',\n tokenSymbol: 'USDC',\n fromAddress: address || 'Debug Wallet',\n toAddress: 'Nord Account',\n networkName: fallbackChain,\n status: 'Completed',\n explorerUrl: getExplorerUrl(mockTransactionId),\n });\n }, [isDebugOverride, state, transactionResult, context, address]);\n\n\n\n return (\n <DepositContext.Provider value={contextValue}>\n {children}\n </DepositContext.Provider>\n );\n};\n\n/**\n * Hook to use the deposit context\n */\nexport const useDepositContext = (): DepositContextValue => {\n const context = useContext(DepositContext);\n if (context === undefined) {\n throw new Error('useDepositContext must be used within a DepositProvider');\n }\n return context;\n}; \n"]}
|
|
@@ -4,6 +4,7 @@ export interface FlowStateContextValue {
|
|
|
4
4
|
state: FlowState;
|
|
5
5
|
context: FlowContextType;
|
|
6
6
|
isClosing: boolean;
|
|
7
|
+
isDebugOverride: boolean;
|
|
7
8
|
transition: (targetState: FlowState, contextUpdates?: Partial<FlowContextType>) => boolean;
|
|
8
9
|
updateContext: (updates: Partial<FlowContextType>) => void;
|
|
9
10
|
}
|
|
@@ -9,12 +9,53 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var _a;
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { createContext, useCallback, useContext, useRef, useState } from 'react';
|
|
14
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
14
15
|
import { FlowState, initialFlowContext } from '../types';
|
|
15
16
|
import { STATE_TRANSITIONS } from '../constants';
|
|
16
17
|
import { logger } from '../../../utils/logger';
|
|
17
18
|
import { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider';
|
|
19
|
+
import { N1ModalViewMode } from '../../../Provider/types';
|
|
20
|
+
import { SolanaNetwork } from '../../../config/solana';
|
|
21
|
+
var buildDebugContext = function (overrides) {
|
|
22
|
+
if (overrides === void 0) { overrides = {}; }
|
|
23
|
+
return (__assign(__assign({}, initialFlowContext), overrides));
|
|
24
|
+
};
|
|
25
|
+
var DEBUG_VIEW_TO_FLOW = (_a = {},
|
|
26
|
+
_a[N1ModalViewMode.Connect] = {
|
|
27
|
+
state: FlowState.CONNECTING_WALLET,
|
|
28
|
+
context: buildDebugContext(),
|
|
29
|
+
},
|
|
30
|
+
_a[N1ModalViewMode.ChainSelection] = {
|
|
31
|
+
state: FlowState.CHAIN_SELECTION,
|
|
32
|
+
context: buildDebugContext({ selectedChain: null }),
|
|
33
|
+
},
|
|
34
|
+
_a[N1ModalViewMode.CreateSession] = {
|
|
35
|
+
state: FlowState.AUTH_LOADING,
|
|
36
|
+
context: buildDebugContext({ hasNordAccount: true, hasActiveSession: false }),
|
|
37
|
+
},
|
|
38
|
+
_a[N1ModalViewMode.Signing] = {
|
|
39
|
+
state: FlowState.DEPOSIT_PROGRESS,
|
|
40
|
+
context: buildDebugContext({ hasNordAccount: false, hasActiveSession: false }),
|
|
41
|
+
},
|
|
42
|
+
_a[N1ModalViewMode.CreatingUser] = {
|
|
43
|
+
state: FlowState.AMOUNT_INPUT,
|
|
44
|
+
context: buildDebugContext({ hasNordAccount: false, hasActiveSession: false }),
|
|
45
|
+
},
|
|
46
|
+
_a[N1ModalViewMode.DepositSuccess] = {
|
|
47
|
+
state: FlowState.DEPOSIT_SUCCESS,
|
|
48
|
+
context: buildDebugContext({
|
|
49
|
+
hasNordAccount: true,
|
|
50
|
+
hasActiveSession: true,
|
|
51
|
+
selectedChain: 'solana-mainnet',
|
|
52
|
+
selectedChainId: 'solana',
|
|
53
|
+
selectedChainNetwork: SolanaNetwork.MAINNET,
|
|
54
|
+
amount: '1,250',
|
|
55
|
+
transactionId: 'debug-tx-12345',
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
_a);
|
|
18
59
|
// Create the context with a default value
|
|
19
60
|
var FlowStateContext = createContext(undefined);
|
|
20
61
|
/**
|
|
@@ -23,12 +64,15 @@ var FlowStateContext = createContext(undefined);
|
|
|
23
64
|
export var FlowStateProvider = function (_a) {
|
|
24
65
|
var children = _a.children;
|
|
25
66
|
// Flow state
|
|
26
|
-
var _b = useState(FlowState.
|
|
67
|
+
var _b = useState(FlowState.CONNECTING_WALLET), state = _b[0], setState = _b[1];
|
|
27
68
|
var _c = useState(initialFlowContext), context = _c[0], setContext = _c[1];
|
|
28
69
|
var _d = useState(false), isClosing = _d[0], setIsClosing = _d[1];
|
|
29
|
-
var
|
|
30
|
-
var
|
|
70
|
+
var _e = useState(false), isDebugOverride = _e[0], setIsDebugOverride = _e[1];
|
|
71
|
+
var _f = useN1WalletContext(), nordUser = _f.nordUser, viewMode = _f.viewMode;
|
|
72
|
+
var _g = useN1WalletInternalContext(), dynamicSdkHasLoaded = _g.dynamicSdkHasLoaded, depositFlowRequestId = _g.depositFlowRequestId;
|
|
31
73
|
var prevContextRef = useRef(initialFlowContext);
|
|
74
|
+
var debugOverrideRef = useRef(false);
|
|
75
|
+
var lastDepositRequestRef = useRef(0);
|
|
32
76
|
// Default handlers
|
|
33
77
|
var handleStateChange = useCallback(function (newState, currState) {
|
|
34
78
|
logger.debug("State changed from ".concat(currState, " to ").concat(newState));
|
|
@@ -37,6 +81,10 @@ export var FlowStateProvider = function (_a) {
|
|
|
37
81
|
* Check if a transition is allowed based on current state and context
|
|
38
82
|
*/
|
|
39
83
|
var canTransition = useCallback(function (targetState, contextData) {
|
|
84
|
+
if (isDebugOverride) {
|
|
85
|
+
logger.debug("Debug override active; blocking transition to ".concat(targetState));
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
40
88
|
if (dynamicSdkHasLoaded)
|
|
41
89
|
return STATE_TRANSITIONS.some(function (transition) {
|
|
42
90
|
var fromMatches = Array.isArray(transition.from)
|
|
@@ -51,7 +99,7 @@ export var FlowStateProvider = function (_a) {
|
|
|
51
99
|
return true;
|
|
52
100
|
});
|
|
53
101
|
return false;
|
|
54
|
-
}, [state, nordUser, dynamicSdkHasLoaded]);
|
|
102
|
+
}, [state, nordUser, dynamicSdkHasLoaded, isDebugOverride]);
|
|
55
103
|
/**
|
|
56
104
|
* Transition to a new state if allowed
|
|
57
105
|
*/
|
|
@@ -61,6 +109,10 @@ export var FlowStateProvider = function (_a) {
|
|
|
61
109
|
if (targetState === state && Object.keys(contextUpdates).length === 0) {
|
|
62
110
|
return true;
|
|
63
111
|
}
|
|
112
|
+
if (isDebugOverride) {
|
|
113
|
+
logger.debug("Transition suppressed (debug override \u2192 ".concat(N1ModalViewMode[viewMode], ")"));
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
64
116
|
if (!canTransition(targetState, __assign(__assign({}, context), contextUpdates))) {
|
|
65
117
|
logger.warn("Transition from ".concat(state, " to ").concat(targetState, " is not allowed"));
|
|
66
118
|
return false;
|
|
@@ -73,7 +125,7 @@ export var FlowStateProvider = function (_a) {
|
|
|
73
125
|
setState(targetState);
|
|
74
126
|
handleStateChange(targetState, state);
|
|
75
127
|
return true;
|
|
76
|
-
}, [canTransition, state, context, handleStateChange]);
|
|
128
|
+
}, [canTransition, state, context, handleStateChange, isDebugOverride, viewMode]);
|
|
77
129
|
/**
|
|
78
130
|
* Update context without state transition
|
|
79
131
|
*/
|
|
@@ -100,11 +152,52 @@ export var FlowStateProvider = function (_a) {
|
|
|
100
152
|
return newContext;
|
|
101
153
|
});
|
|
102
154
|
}, [state]);
|
|
155
|
+
useEffect(function () {
|
|
156
|
+
if (!depositFlowRequestId ||
|
|
157
|
+
depositFlowRequestId === lastDepositRequestRef.current) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
lastDepositRequestRef.current = depositFlowRequestId;
|
|
161
|
+
if (!nordUser || !nordUser.sessionId) {
|
|
162
|
+
logger.warn('Ignoring deposit flow request without an active Nord session');
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
var nextContext = __assign(__assign({}, initialFlowContext), { hasNordAccount: true, hasActiveSession: true, isDepositOnlyFlow: true });
|
|
166
|
+
prevContextRef.current = nextContext;
|
|
167
|
+
setIsDebugOverride(false);
|
|
168
|
+
setContext(nextContext);
|
|
169
|
+
setState(FlowState.CHAIN_SELECTION);
|
|
170
|
+
setIsClosing(false);
|
|
171
|
+
logger.debug('Deposit-only flow activated');
|
|
172
|
+
}, [depositFlowRequestId, nordUser]);
|
|
173
|
+
// Debug-only: allow external callers (e.g. UI playground) to jump to a specific view
|
|
174
|
+
useEffect(function () {
|
|
175
|
+
var debugTarget = viewMode === N1ModalViewMode.Automatic ? undefined : DEBUG_VIEW_TO_FLOW[viewMode];
|
|
176
|
+
if (debugTarget) {
|
|
177
|
+
debugOverrideRef.current = true;
|
|
178
|
+
setIsDebugOverride(true);
|
|
179
|
+
var nextContext = debugTarget.context;
|
|
180
|
+
prevContextRef.current = nextContext;
|
|
181
|
+
setContext(nextContext);
|
|
182
|
+
setState(debugTarget.state);
|
|
183
|
+
logger.debug("Debug view override: ".concat(N1ModalViewMode[viewMode], " \u2192 ").concat(debugTarget.state));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (debugOverrideRef.current) {
|
|
187
|
+
debugOverrideRef.current = false;
|
|
188
|
+
setIsDebugOverride(false);
|
|
189
|
+
setContext(initialFlowContext);
|
|
190
|
+
prevContextRef.current = initialFlowContext;
|
|
191
|
+
setState(FlowState.CONNECTING_WALLET);
|
|
192
|
+
logger.debug('Debug view override cleared; returning to state machine');
|
|
193
|
+
}
|
|
194
|
+
}, [viewMode]);
|
|
103
195
|
// Create the context value
|
|
104
196
|
var contextValue = {
|
|
105
197
|
state: state,
|
|
106
198
|
context: context,
|
|
107
199
|
isClosing: isClosing,
|
|
200
|
+
isDebugOverride: isDebugOverride,
|
|
108
201
|
transition: transition,
|
|
109
202
|
updateContext: updateContext,
|
|
110
203
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/FlowContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAa,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EAAkC,SAAS,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAWnF,0CAA0C;AAC1C,IAAM,gBAAgB,GAAG,aAAa,CAAoC,SAAS,CAAC,CAAC;AAOrF;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAqC,UAAC,EAEnE;QADC,QAAQ,cAAA;IAER,aAAa;IACP,IAAA,KAAoB,QAAQ,CAAY,SAAS,CAAC,IAAI,CAAC,EAAtD,KAAK,QAAA,EAAE,QAAQ,QAAuC,CAAC;IACxD,IAAA,KAAwB,QAAQ,CAAkB,kBAAkB,CAAC,EAApE,OAAO,QAAA,EAAE,UAAU,QAAiD,CAAC;IACtE,IAAA,KAA4B,QAAQ,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C,CAAC;YAEH,sDAAsD;YACtD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC;YACrB,CAAC;YAED,IAAM,UAAU,yBAAQ,WAAW,GAAK,OAAO,CAAE,CAAC;YAClD,cAAc,CAAC,OAAO,GAAG,UAAU,CAAC;YACpC,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,KAAK,CAAC,CACR,CAAC;IAGF,2BAA2B;IAC3B,IAAM,YAAY,GAA0B;QAC1C,KAAK,OAAA;QACL,OAAO,SAAA;QACP,SAAS,WAAA;QACT,UAAU,YAAA;QACV,aAAa,eAAA;KACd,CAAC;IAIF,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG;IACjC,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE7C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport { FlowContext as FlowContextType, FlowState, initialFlowContext } from '../types';\nimport { STATE_TRANSITIONS } from '../constants';\nimport { logger } from '../../../utils/logger';\nimport { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider';\n\n// Define the shape of the context value\nexport interface FlowStateContextValue {\n state: FlowState;\n context: FlowContextType;\n isClosing: boolean;\n transition: (targetState: FlowState, contextUpdates?: Partial<FlowContextType>) => boolean;\n updateContext: (updates: Partial<FlowContextType>) => void;\n}\n\n// Create the context with a default value\nconst FlowStateContext = createContext<FlowStateContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface FlowStateProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the flow state context\n */\nexport const FlowStateProvider: React.FC<FlowStateProviderProps> = ({\n children,\n}) => {\n // Flow state\n const [state, setState] = useState<FlowState>(FlowState.IDLE);\n const [context, setContext] = useState<FlowContextType>(initialFlowContext);\n const [isClosing, setIsClosing] = useState(false);\n\n const { nordUser } = useN1WalletContext();\n const { dynamicSdkHasLoaded } = useN1WalletInternalContext();\n const prevContextRef = useRef<FlowContextType>(initialFlowContext);\n\n\n // Default handlers\n const handleStateChange = useCallback((newState: FlowState, currState: FlowState | null) => {\n logger.debug(`State changed from ${currState} to ${newState}`);\n }, []);\n /**\n * Check if a transition is allowed based on current state and context\n */\n const canTransition = useCallback(\n (targetState: FlowState, contextData: FlowContextType): boolean => {\n if (dynamicSdkHasLoaded)\n return STATE_TRANSITIONS.some((transition) => {\n const fromMatches = Array.isArray(transition.from)\n ? transition.from.includes(state)\n : transition.from === state;\n\n if (!fromMatches || transition.to !== targetState) {\n return false;\n }\n\n if (transition.condition) {\n return transition.condition(contextData);\n }\n\n return true;\n });\n return false;\n },\n [state, nordUser, dynamicSdkHasLoaded]\n );\n\n /**\n * Transition to a new state if allowed\n */\n const transition = useCallback(\n (\n targetState: FlowState,\n contextUpdates: Partial<FlowContextType> = {}\n ): boolean => {\n // Skip if we're already in the target state and no context updates\n if (targetState === state && Object.keys(contextUpdates).length === 0) {\n return true;\n }\n\n if (!canTransition(targetState, { ...context, ...contextUpdates })) {\n logger.warn(\n `Transition from ${state} to ${targetState} is not allowed`\n );\n return false;\n }\n\n\n // Update context first\n setContext((prevContext) => {\n return { ...prevContext, ...contextUpdates };\n });\n\n logger.debug(`Transitioning from ${state} to ${targetState}`);\n setState(targetState);\n\n handleStateChange(targetState, state);\n return true;\n },\n [canTransition, state, context, handleStateChange]\n );\n\n\n\n /**\n * Update context without state transition\n */\n const updateContext = useCallback(\n (updates: Partial<FlowContextType>) => {\n // Skip if no actual updates\n if (Object.keys(updates).length === 0) {\n return;\n }\n\n setContext((prevContext) => {\n // Check if any values are actually changing\n let hasChanges = false;\n\n // Type-safe way to check for changes\n (Object.keys(updates) as Array<keyof Partial<FlowContextType>>).forEach(key => {\n if (updates[key] !== prevContext[key]) {\n hasChanges = true;\n }\n });\n\n // If nothing is changing, return the previous context\n if (!hasChanges) {\n return prevContext;\n }\n\n const newContext = { ...prevContext, ...updates };\n prevContextRef.current = newContext;\n return newContext;\n });\n },\n [state]\n );\n\n\n // Create the context value\n const contextValue: FlowStateContextValue = {\n state,\n context,\n isClosing,\n transition,\n updateContext,\n };\n\n\n\n return (\n <FlowStateContext.Provider value={contextValue}>\n {children}\n </FlowStateContext.Provider>\n );\n};\n\n/**\n * Custom hook to use the flow state context\n * @returns The flow state context value\n * @throws Error if used outside of a FlowStateProvider\n */\nexport const useFlowStateContext = (): FlowStateContextValue => {\n const context = useContext(FlowStateContext);\n\n if (context === undefined) {\n throw new Error('useFlowStateContext must be used within a FlowStateProvider');\n }\n\n return context;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"FlowContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/FlowContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EAAkC,SAAS,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,IAAM,iBAAiB,GAAG,UAAC,SAAwC;IAAxC,0B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AAe,CAAC,QAAQ,CAAC,qBAAM,WAAW,CAAC,KAAK,CAAE,CAC3E,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAC7B,gBAAgB,CAAC,OAAO,GAAG,KAAK,CAAC;YACjC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC1B,UAAU,CAAC,kBAAkB,CAAC,CAAC;YAC/B,cAAc,CAAC,OAAO,GAAG,kBAAkB,CAAC;YAC5C,QAAQ,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAGf,2BAA2B;IAC3B,IAAM,YAAY,GAA0B;QAC1C,KAAK,OAAA;QACL,OAAO,SAAA;QACP,SAAS,WAAA;QACT,eAAe,iBAAA;QACf,UAAU,YAAA;QACV,aAAa,eAAA;KACd,CAAC;IAIF,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG;IACjC,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAE7C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport { FlowContext as FlowContextType, FlowState, initialFlowContext } from '../types';\nimport { STATE_TRANSITIONS } from '../constants';\nimport { logger } from '../../../utils/logger';\nimport { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider';\nimport { N1ModalViewMode } from '../../../Provider/types';\nimport { SolanaNetwork } from '../../../config/solana';\n\nconst buildDebugContext = (overrides: Partial<FlowContextType> = {}) => ({\n ...initialFlowContext,\n ...overrides,\n});\n\nconst DEBUG_VIEW_TO_FLOW: Partial<\n Record<N1ModalViewMode, { state: FlowState; context: FlowContextType }>\n> = {\n [N1ModalViewMode.Connect]: {\n state: FlowState.CONNECTING_WALLET,\n context: buildDebugContext(),\n },\n [N1ModalViewMode.ChainSelection]: {\n state: FlowState.CHAIN_SELECTION,\n context: buildDebugContext({ selectedChain: null }),\n },\n [N1ModalViewMode.CreateSession]: {\n state: FlowState.AUTH_LOADING,\n context: buildDebugContext({ hasNordAccount: true, hasActiveSession: false }),\n },\n [N1ModalViewMode.Signing]: {\n state: FlowState.DEPOSIT_PROGRESS,\n context: buildDebugContext({ hasNordAccount: false, hasActiveSession: false }),\n },\n [N1ModalViewMode.CreatingUser]: {\n state: FlowState.AMOUNT_INPUT,\n context: buildDebugContext({ hasNordAccount: false, hasActiveSession: false }),\n },\n [N1ModalViewMode.DepositSuccess]: {\n state: FlowState.DEPOSIT_SUCCESS,\n context: buildDebugContext({\n hasNordAccount: true,\n hasActiveSession: true,\n selectedChain: 'solana-mainnet',\n selectedChainId: 'solana',\n selectedChainNetwork: SolanaNetwork.MAINNET,\n amount: '1,250',\n transactionId: 'debug-tx-12345',\n }),\n },\n};\n\n// Define the shape of the context value\nexport interface FlowStateContextValue {\n state: FlowState;\n context: FlowContextType;\n isClosing: boolean;\n isDebugOverride: boolean;\n transition: (targetState: FlowState, contextUpdates?: Partial<FlowContextType>) => boolean;\n updateContext: (updates: Partial<FlowContextType>) => void;\n}\n\n// Create the context with a default value\nconst FlowStateContext = createContext<FlowStateContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface FlowStateProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the flow state context\n */\nexport const FlowStateProvider: React.FC<FlowStateProviderProps> = ({\n children,\n}) => {\n // Flow state\n const [state, setState] = useState<FlowState>(FlowState.CONNECTING_WALLET);\n const [context, setContext] = useState<FlowContextType>(initialFlowContext);\n const [isClosing, setIsClosing] = useState(false);\n const [isDebugOverride, setIsDebugOverride] = useState(false);\n\n const { nordUser, viewMode } = useN1WalletContext();\n const { dynamicSdkHasLoaded, depositFlowRequestId } = useN1WalletInternalContext();\n const prevContextRef = useRef<FlowContextType>(initialFlowContext);\n const debugOverrideRef = useRef(false);\n const lastDepositRequestRef = useRef(0);\n\n\n // Default handlers\n const handleStateChange = useCallback((newState: FlowState, currState: FlowState | null) => {\n logger.debug(`State changed from ${currState} to ${newState}`);\n }, []);\n /**\n * Check if a transition is allowed based on current state and context\n */\n const canTransition = useCallback(\n (targetState: FlowState, contextData: FlowContextType): boolean => {\n if (isDebugOverride) {\n logger.debug(\n `Debug override active; blocking transition to ${targetState}`\n );\n return false;\n }\n\n if (dynamicSdkHasLoaded)\n return STATE_TRANSITIONS.some((transition) => {\n const fromMatches = Array.isArray(transition.from)\n ? transition.from.includes(state)\n : transition.from === state;\n\n if (!fromMatches || transition.to !== targetState) {\n return false;\n }\n\n if (transition.condition) {\n return transition.condition(contextData);\n }\n\n return true;\n });\n return false;\n },\n [state, nordUser, dynamicSdkHasLoaded, isDebugOverride]\n );\n\n /**\n * Transition to a new state if allowed\n */\n const transition = useCallback(\n (\n targetState: FlowState,\n contextUpdates: Partial<FlowContextType> = {}\n ): boolean => {\n // Skip if we're already in the target state and no context updates\n if (targetState === state && Object.keys(contextUpdates).length === 0) {\n return true;\n }\n\n if (isDebugOverride) {\n logger.debug(\n `Transition suppressed (debug override → ${N1ModalViewMode[viewMode]})`\n );\n return false;\n }\n\n if (!canTransition(targetState, { ...context, ...contextUpdates })) {\n logger.warn(\n `Transition from ${state} to ${targetState} is not allowed`\n );\n return false;\n }\n\n\n // Update context first\n setContext((prevContext) => {\n return { ...prevContext, ...contextUpdates };\n });\n\n logger.debug(`Transitioning from ${state} to ${targetState}`);\n setState(targetState);\n\n handleStateChange(targetState, state);\n return true;\n },\n [canTransition, state, context, handleStateChange, isDebugOverride, viewMode]\n );\n\n\n\n /**\n * Update context without state transition\n */\n const updateContext = useCallback(\n (updates: Partial<FlowContextType>) => {\n // Skip if no actual updates\n if (Object.keys(updates).length === 0) {\n return;\n }\n\n setContext((prevContext) => {\n // Check if any values are actually changing\n let hasChanges = false;\n\n // Type-safe way to check for changes\n (Object.keys(updates) as Array<keyof Partial<FlowContextType>>).forEach(key => {\n if (updates[key] !== prevContext[key]) {\n hasChanges = true;\n }\n });\n\n // If nothing is changing, return the previous context\n if (!hasChanges) {\n return prevContext;\n }\n\n const newContext = { ...prevContext, ...updates };\n prevContextRef.current = newContext;\n return newContext;\n });\n },\n [state]\n );\n\n useEffect(() => {\n if (\n !depositFlowRequestId ||\n depositFlowRequestId === lastDepositRequestRef.current\n ) {\n return;\n }\n\n lastDepositRequestRef.current = depositFlowRequestId;\n\n if (!nordUser || !nordUser.sessionId) {\n logger.warn('Ignoring deposit flow request without an active Nord session');\n return;\n }\n\n const nextContext: FlowContextType = {\n ...initialFlowContext,\n hasNordAccount: true,\n hasActiveSession: true,\n isDepositOnlyFlow: true,\n };\n\n prevContextRef.current = nextContext;\n setIsDebugOverride(false);\n setContext(nextContext);\n setState(FlowState.CHAIN_SELECTION);\n setIsClosing(false);\n logger.debug('Deposit-only flow activated');\n }, [depositFlowRequestId, nordUser]);\n\n // Debug-only: allow external callers (e.g. UI playground) to jump to a specific view\n useEffect(() => {\n const debugTarget =\n viewMode === N1ModalViewMode.Automatic ? undefined : DEBUG_VIEW_TO_FLOW[viewMode];\n\n if (debugTarget) {\n debugOverrideRef.current = true;\n setIsDebugOverride(true);\n const nextContext = debugTarget.context;\n prevContextRef.current = nextContext;\n setContext(nextContext);\n setState(debugTarget.state);\n logger.debug(\n `Debug view override: ${N1ModalViewMode[viewMode]} → ${debugTarget.state}`\n );\n return;\n }\n\n if (debugOverrideRef.current) {\n debugOverrideRef.current = false;\n setIsDebugOverride(false);\n setContext(initialFlowContext);\n prevContextRef.current = initialFlowContext;\n setState(FlowState.CONNECTING_WALLET);\n logger.debug('Debug view override cleared; returning to state machine');\n }\n }, [viewMode]);\n\n\n // Create the context value\n const contextValue: FlowStateContextValue = {\n state,\n context,\n isClosing,\n isDebugOverride,\n transition,\n updateContext,\n };\n\n\n\n return (\n <FlowStateContext.Provider value={contextValue}>\n {children}\n </FlowStateContext.Provider>\n );\n};\n\n/**\n * Custom hook to use the flow state context\n * @returns The flow state context value\n * @throws Error if used outside of a FlowStateProvider\n */\nexport const useFlowStateContext = (): FlowStateContextValue => {\n const context = useContext(FlowStateContext);\n\n if (context === undefined) {\n throw new Error('useFlowStateContext must be used within a FlowStateProvider');\n }\n\n return context;\n};\n"]}
|
|
@@ -38,8 +38,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
38
38
|
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
39
39
|
import { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider/hooks';
|
|
40
40
|
import { logger } from '../../../utils/logger';
|
|
41
|
-
import {
|
|
41
|
+
import { removeKeysFromLocalStorage } from '../../../Logic/utils';
|
|
42
|
+
import { FLOW_STATE_STORAGE_KEY } from '../constants';
|
|
43
|
+
import { FlowState, initialFlowContext } from '../types';
|
|
42
44
|
import { useFlowStateContext } from './FlowContext';
|
|
45
|
+
import { readLastDepositRecord } from '../utils/depositStorage';
|
|
43
46
|
// Create the context with a default value
|
|
44
47
|
var WalletConnectContext = createContext(undefined);
|
|
45
48
|
/**
|
|
@@ -47,32 +50,49 @@ var WalletConnectContext = createContext(undefined);
|
|
|
47
50
|
*/
|
|
48
51
|
export var WalletConnectProvider = function (_a) {
|
|
49
52
|
var children = _a.children;
|
|
50
|
-
var _b = useN1WalletContext(), nord = _b.nord, nordUser = _b.nordUser;
|
|
53
|
+
var _b = useN1WalletContext(), nord = _b.nord, nordUser = _b.nordUser, address = _b.address;
|
|
51
54
|
var _c = useN1WalletInternalContext(), showDynamicWidget = _c.showDynamicWidget, dynamicWallet = _c.dynamicWallet, setIsConnected = _c.setIsConnected, dynamicSdkHasLoaded = _c.dynamicSdkHasLoaded;
|
|
52
55
|
var dynamicHandleLogOut = useN1WalletInternalContext().dynamicHandleLogOut;
|
|
53
56
|
// Get flow context
|
|
54
|
-
var _d = useFlowStateContext(), state = _d.state, transition = _d.transition, updateContext = _d.updateContext;
|
|
57
|
+
var _d = useFlowStateContext(), state = _d.state, context = _d.context, transition = _d.transition, updateContext = _d.updateContext;
|
|
55
58
|
var _e = useState(false), isConnecting = _e[0], setIsConnecting = _e[1];
|
|
56
59
|
// Use refs to track previous values
|
|
57
60
|
var processedWalletAddressRef = useRef(null);
|
|
58
61
|
var prevNordUserRef = useRef(nordUser);
|
|
59
62
|
var prevStateRef = useRef(state);
|
|
63
|
+
var clearWalletCache = useCallback(function () {
|
|
64
|
+
if (typeof window === 'undefined') {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (address) {
|
|
69
|
+
var sessionIdKey = "n1_sessionId_".concat(address);
|
|
70
|
+
window.localStorage.removeItem(sessionIdKey);
|
|
71
|
+
removeKeysFromLocalStorage(address);
|
|
72
|
+
}
|
|
73
|
+
window.localStorage.removeItem(FLOW_STATE_STORAGE_KEY);
|
|
74
|
+
updateContext(initialFlowContext);
|
|
75
|
+
logger.debug('Cleared wallet cache for address', { address: address });
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger.warn('Failed to clear wallet cache', error);
|
|
79
|
+
}
|
|
80
|
+
}, [address, updateContext]);
|
|
60
81
|
/**
|
|
61
82
|
* Disconnect wallet
|
|
62
83
|
*/
|
|
63
84
|
var disconnectWallet = useCallback(function () {
|
|
64
85
|
logger.debug('Disconnecting wallet');
|
|
65
86
|
try {
|
|
66
|
-
|
|
87
|
+
clearWalletCache();
|
|
88
|
+
dynamicHandleLogOut === null || dynamicHandleLogOut === void 0 ? void 0 : dynamicHandleLogOut();
|
|
67
89
|
}
|
|
68
|
-
catch (
|
|
69
|
-
|
|
90
|
+
catch (error) {
|
|
91
|
+
logger.warn('Error during wallet disconnect', error);
|
|
70
92
|
}
|
|
71
93
|
processedWalletAddressRef.current = null;
|
|
72
|
-
updateContext({ walletType: null });
|
|
73
|
-
// todo: delete sessionId from localStorage
|
|
74
94
|
window.location.reload();
|
|
75
|
-
}, [
|
|
95
|
+
}, [clearWalletCache, dynamicHandleLogOut]);
|
|
76
96
|
/**
|
|
77
97
|
* Connect wallet using Dynamic widget
|
|
78
98
|
*/
|
|
@@ -96,21 +116,60 @@ export var WalletConnectProvider = function (_a) {
|
|
|
96
116
|
case 3:
|
|
97
117
|
error_1 = _a.sent();
|
|
98
118
|
setIsConnecting(false);
|
|
99
|
-
updateContext({ walletType: null });
|
|
100
119
|
logger.error('Error showing Dynamic widget:', error_1);
|
|
101
120
|
return [3 /*break*/, 4];
|
|
102
121
|
case 4: return [2 /*return*/];
|
|
103
122
|
}
|
|
104
123
|
});
|
|
105
|
-
}); }, [isConnecting, showDynamicWidget,
|
|
124
|
+
}); }, [isConnecting, showDynamicWidget, dynamicSdkHasLoaded]);
|
|
106
125
|
// Process nordUser changes
|
|
107
126
|
useEffect(function () {
|
|
108
127
|
if (!dynamicSdkHasLoaded)
|
|
109
128
|
return;
|
|
129
|
+
// If the wallet is connected but NordUser hasn't been created yet,
|
|
130
|
+
// move the flow forward so the user can continue with onboarding.
|
|
131
|
+
if (dynamicWallet && !nordUser) {
|
|
132
|
+
logger.debug('Dynamic wallet detected but NordUser not ready yet, moving to chain selection flow');
|
|
133
|
+
updateContext({
|
|
134
|
+
hasNordAccount: false,
|
|
135
|
+
hasActiveSession: false,
|
|
136
|
+
});
|
|
137
|
+
if (state === FlowState.CONNECTING_WALLET) {
|
|
138
|
+
// Only force the transition while we are still on the initial connect screen
|
|
139
|
+
try {
|
|
140
|
+
var lastDepositRecord = context.isDepositOnlyFlow
|
|
141
|
+
? null
|
|
142
|
+
: readLastDepositRecord(dynamicWallet.address);
|
|
143
|
+
if (lastDepositRecord) {
|
|
144
|
+
transition(FlowState.DEPOSIT_SUCCESS, {
|
|
145
|
+
hasNordAccount: true,
|
|
146
|
+
hasActiveSession: false,
|
|
147
|
+
selectedChain: lastDepositRecord.chainName,
|
|
148
|
+
selectedChainId: lastDepositRecord.chainId,
|
|
149
|
+
selectedChainNetwork: lastDepositRecord.chainNetwork,
|
|
150
|
+
transactionId: lastDepositRecord.transactionId,
|
|
151
|
+
amount: lastDepositRecord.amount,
|
|
152
|
+
lastDeposit: lastDepositRecord,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
transition(FlowState.CHAIN_SELECTION, {
|
|
157
|
+
hasNordAccount: false,
|
|
158
|
+
hasActiveSession: false,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
logger.error('Error transitioning while waiting for NordUser:', error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
setIsConnecting(false);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
110
169
|
var currentNordUser = nordUser;
|
|
111
170
|
var prevNordUser = prevNordUserRef.current;
|
|
112
171
|
// Only run if nordUser has changed and we have processed a wallet
|
|
113
|
-
if (currentNordUser && currentNordUser !== prevNordUser) {
|
|
172
|
+
if (currentNordUser && currentNordUser !== prevNordUser && dynamicWallet) {
|
|
114
173
|
logger.debug('NordUser changed, checking account status');
|
|
115
174
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
175
|
var nordAccount, hasNordAccount_1, sessionId, hasActiveSession_1, transitionDestination_1, error_2;
|
|
@@ -118,8 +177,6 @@ export var WalletConnectProvider = function (_a) {
|
|
|
118
177
|
switch (_a.label) {
|
|
119
178
|
case 0:
|
|
120
179
|
_a.trys.push([0, 2, , 3]);
|
|
121
|
-
if (!dynamicWallet)
|
|
122
|
-
return [2 /*return*/];
|
|
123
180
|
return [4 /*yield*/, nord.getUser({ pubkey: dynamicWallet.address })];
|
|
124
181
|
case 1:
|
|
125
182
|
nordAccount = _a.sent();
|
|
@@ -140,7 +197,6 @@ export var WalletConnectProvider = function (_a) {
|
|
|
140
197
|
try {
|
|
141
198
|
logger.debug('Attempting transition to ' + transitionDestination_1);
|
|
142
199
|
transition(transitionDestination_1, {
|
|
143
|
-
walletType: 'solana',
|
|
144
200
|
hasNordAccount: hasNordAccount_1,
|
|
145
201
|
hasActiveSession: hasActiveSession_1,
|
|
146
202
|
});
|
|
@@ -164,17 +220,17 @@ export var WalletConnectProvider = function (_a) {
|
|
|
164
220
|
});
|
|
165
221
|
}); })();
|
|
166
222
|
}
|
|
167
|
-
|
|
168
|
-
transition(FlowState.CONNECTING_WALLET);
|
|
169
|
-
}
|
|
170
|
-
// Update ref
|
|
223
|
+
// Update ref so we don't re-run unless nordUser changes again
|
|
171
224
|
prevNordUserRef.current = currentNordUser;
|
|
172
225
|
}, [
|
|
173
226
|
nordUser,
|
|
174
227
|
dynamicWallet,
|
|
175
228
|
updateContext,
|
|
176
229
|
transition,
|
|
177
|
-
setIsConnected
|
|
230
|
+
setIsConnected,
|
|
231
|
+
state,
|
|
232
|
+
dynamicSdkHasLoaded,
|
|
233
|
+
context.isDepositOnlyFlow,
|
|
178
234
|
]);
|
|
179
235
|
// Handle connecting state changes in a separate effect
|
|
180
236
|
useEffect(function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WalletConnectContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/WalletConnectContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAEzF,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,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AQ;QACR,aAAa;QACb,aAAa;QACb,UAAU;QACV,cAAc;KACf,CAAC,CAAC;IAKH,uDAAuD;IACvD,SAAS,CAAC;QACR,IAAM,YAAY,GAAG,KAAK,CAAC;QAC3B,IAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QAEvC,gCAAgC;QAChC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,YAAY,KAAK,SAAS,CAAC,iBAAiB,IAAI,YAAY,EAAE,CAAC;gBACjE,wEAAwE;gBACxE,eAAe,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YAED,aAAa;YACb,YAAY,CAAC,OAAO,GAAG,YAAY,CAAC;QACtC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAE1B,2BAA2B;IAC3B,IAAM,YAAY,GAA8B;QAC9C,YAAY,cAAA;QACZ,aAAa,eAAA;QACb,gBAAgB,kBAAA;KACjB,CAAC;IAEF,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC/C,QAAQ,GACqB,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,uBAAuB,GAAG;IACrC,IAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider/hooks';\nimport { N1SessionMode } from '../../../Provider/types';\nimport { logger } from '../../../utils/logger';\nimport { FlowState, initialFlowContext } from '../types';\nimport { useFlowStateContext } from './FlowContext';\n\n// Define the shape of the context value\nexport interface WalletConnectContextValue {\n isConnecting: boolean;\n connectWallet: () => Promise<void>;\n disconnectWallet: () => void;\n}\n\n// Create the context with a default value\nconst WalletConnectContext = createContext<WalletConnectContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface WalletConnectProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the wallet connect context\n */\nexport const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({\n children,\n}) => {\n const { nord, nordUser } = useN1WalletContext();\n const { showDynamicWidget, dynamicWallet, setIsConnected, dynamicSdkHasLoaded } = useN1WalletInternalContext();\n const { dynamicHandleLogOut } = useN1WalletInternalContext();\n\n // Get flow context\n const {\n state,\n transition,\n updateContext,\n } = useFlowStateContext();\n\n const [isConnecting, setIsConnecting] = useState(false);\n\n // Use refs to track previous values\n const processedWalletAddressRef = useRef<string | null>(null);\n const prevNordUserRef = useRef(nordUser);\n const prevStateRef = useRef(state);\n\n\n /**\n * Disconnect wallet\n */\n const disconnectWallet = useCallback(() => {\n logger.debug('Disconnecting wallet');\n try {\n dynamicHandleLogOut()\n } catch (_) {\n // \n }\n processedWalletAddressRef.current = null;\n updateContext({ walletType: null });\n // todo: delete sessionId from localStorage\n window.location.reload();\n }, [updateContext]);\n\n /**\n * Connect wallet using Dynamic widget\n */\n const connectWallet = useCallback(async () => {\n if (isConnecting || !showDynamicWidget || !dynamicSdkHasLoaded) return;\n\n setIsConnecting(true);\n logger.debug('Starting wallet connection process');\n\n try {\n await showDynamicWidget(true);\n logger.debug('Dynamic widget shown');\n } catch (error) {\n setIsConnecting(false);\n updateContext({ walletType: null });\n logger.error('Error showing Dynamic widget:', error);\n }\n }, [isConnecting, showDynamicWidget, updateContext, dynamicSdkHasLoaded]);\n\n // Process nordUser changes\n useEffect(() => {\n if (!dynamicSdkHasLoaded) return\n\n const currentNordUser = nordUser;\n const prevNordUser = prevNordUserRef.current;\n\n // Only run if nordUser has changed and we have processed a wallet\n if (currentNordUser && currentNordUser !== prevNordUser) {\n logger.debug('NordUser changed, checking account status');\n\n (async () => {\n try {\n if (!dynamicWallet) return;\n\n const nordAccount = await nord!.getUser({ pubkey: dynamicWallet.address });\n const hasNordAccount = nordAccount != null;\n const sessionId = currentNordUser.sessionId;\n const hasActiveSession = sessionId != null;\n\n updateContext({ hasNordAccount, hasActiveSession });\n\n const transitionDestination = hasNordAccount\n ? sessionId != null\n ? FlowState.FINAL_SUCCESS\n : FlowState.AUTH_LOADING\n : FlowState.CHAIN_SELECTION;\n\n if (hasNordAccount && sessionId != null) {\n setIsConnected(true);\n }\n\n // Force a small delay to ensure UI updates properly\n setTimeout(() => {\n try {\n logger.debug('Attempting transition to ' + transitionDestination);\n transition(transitionDestination, {\n walletType: 'solana',\n hasNordAccount,\n hasActiveSession,\n });\n logger.debug(\n 'Transition to ' + transitionDestination + ' completed'\n );\n } catch (error) {\n logger.error('Error during transition:', error);\n } finally {\n setIsConnecting(false);\n }\n }, 100);\n } catch (error) {\n logger.error('Error checking account status:', error);\n setIsConnecting(false);\n }\n })();\n }else{\n transition(FlowState.CONNECTING_WALLET)\n }\n\n // Update ref\n prevNordUserRef.current = currentNordUser;\n }, [\n nordUser,\n dynamicWallet,\n updateContext,\n transition,\n setIsConnected\n ]);\n\n\n\n\n // Handle connecting state changes in a separate effect\n useEffect(() => {\n const currentState = state;\n const prevState = prevStateRef.current;\n\n // Only run if state has changed\n if (currentState !== prevState) {\n if (currentState !== FlowState.CONNECTING_WALLET && isConnecting) {\n // If we're no longer in the connecting state, reset the connecting flag\n setIsConnecting(false);\n }\n\n // Update ref\n prevStateRef.current = currentState;\n }\n }, [state, isConnecting]);\n\n // Create the context value\n const contextValue: WalletConnectContextValue = {\n isConnecting,\n connectWallet,\n disconnectWallet,\n };\n\n return (\n <WalletConnectContext.Provider value={contextValue}>\n {children}\n </WalletConnectContext.Provider>\n );\n};\n\n/**\n * Custom hook to use the wallet connect context\n * @returns The wallet connect context value\n * @throws Error if used outside of a WalletConnectProvider\n */\nexport const useWalletConnectContext = (): WalletConnectContextValue => {\n const context = useContext(WalletConnectContext);\n\n if (context === undefined) {\n throw new Error('useWalletConnectContext must be used within a WalletConnectProvider');\n }\n\n return context;\n}; "]}
|
|
1
|
+
{"version":3,"file":"WalletConnectContext.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/context/WalletConnectContext.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAc,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAShE,0CAA0C;AAC1C,IAAM,oBAAoB,GAAG,aAAa,CAAwC,SAAS,CAAC,CAAC;AAO7F;;GAEG;AACH,MAAM,CAAC,IAAM,qBAAqB,GAAyC,UAAC,EAE3E;QADC,QAAQ,cAAA;IAEF,IAAA,KAA8B,kBAAkB,EAAE,EAAhD,IAAI,UAAA,EAAE,QAAQ,cAAA,EAAE,OAAO,aAAyB,CAAC;IACnD,IAAA,KAA4E,0BAA0B,EAAE,EAAtG,iBAAiB,uBAAA,EAAE,aAAa,mBAAA,EAAE,cAAc,oBAAA,EAAE,mBAAmB,yBAAiC,CAAC;IACvG,IAAA,mBAAmB,GAAK,0BAA0B,EAAE,oBAAjC,CAAkC;IAE7D,mBAAmB;IACb,IAAA,KAKF,mBAAmB,EAAE,EAJvB,KAAK,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AO,CAAC,iBAAiB;KAC1B,CAAC,CAAC;IAKH,uDAAuD;IACvD,SAAS,CAAC;QACR,IAAM,YAAY,GAAG,KAAK,CAAC;QAC3B,IAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QAEvC,gCAAgC;QAChC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,IAAI,YAAY,KAAK,SAAS,CAAC,iBAAiB,IAAI,YAAY,EAAE,CAAC;gBACjE,wEAAwE;gBACxE,eAAe,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YAED,aAAa;YACb,YAAY,CAAC,OAAO,GAAG,YAAY,CAAC;QACtC,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAE1B,2BAA2B;IAC3B,IAAM,YAAY,GAA8B;QAC9C,YAAY,cAAA;QACZ,aAAa,eAAA;QACb,gBAAgB,kBAAA;KACjB,CAAC;IAEF,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC/C,QAAQ,GACqB,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,IAAM,uBAAuB,GAAG;IACrC,IAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport { useN1WalletContext, useN1WalletInternalContext } from '../../../Provider/hooks';\nimport { logger } from '../../../utils/logger';\nimport { removeKeysFromLocalStorage } from '../../../Logic/utils';\nimport { FLOW_STATE_STORAGE_KEY } from '../constants';\nimport { FlowState, initialFlowContext } from '../types';\nimport { useFlowStateContext } from './FlowContext';\nimport { readLastDepositRecord } from '../utils/depositStorage';\n\n// Define the shape of the context value\nexport interface WalletConnectContextValue {\n isConnecting: boolean;\n connectWallet: () => Promise<void>;\n disconnectWallet: () => void;\n}\n\n// Create the context with a default value\nconst WalletConnectContext = createContext<WalletConnectContextValue | undefined>(undefined);\n\n// Props for the provider component\ninterface WalletConnectProviderProps {\n children: React.ReactNode;\n}\n\n/**\n * Provider component for the wallet connect context\n */\nexport const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({\n children,\n}) => {\n const { nord, nordUser, address } = useN1WalletContext();\n const { showDynamicWidget, dynamicWallet, setIsConnected, dynamicSdkHasLoaded } = useN1WalletInternalContext();\n const { dynamicHandleLogOut } = useN1WalletInternalContext();\n\n // Get flow context\n const {\n state,\n context,\n transition,\n updateContext,\n } = useFlowStateContext();\n\n const [isConnecting, setIsConnecting] = useState(false);\n\n // Use refs to track previous values\n const processedWalletAddressRef = useRef<string | null>(null);\n const prevNordUserRef = useRef(nordUser);\n const prevStateRef = useRef(state);\n\n\n const clearWalletCache = useCallback(() => {\n if (typeof window === 'undefined') {\n return;\n }\n\n try {\n if (address) {\n const sessionIdKey = `n1_sessionId_${address}`;\n window.localStorage.removeItem(sessionIdKey);\n removeKeysFromLocalStorage(address);\n }\n\n window.localStorage.removeItem(FLOW_STATE_STORAGE_KEY);\n updateContext(initialFlowContext);\n logger.debug('Cleared wallet cache for address', { address });\n } catch (error) {\n logger.warn('Failed to clear wallet cache', error);\n }\n }, [address, updateContext]);\n\n /**\n * Disconnect wallet\n */\n const disconnectWallet = useCallback(() => {\n logger.debug('Disconnecting wallet');\n try {\n clearWalletCache();\n dynamicHandleLogOut?.();\n } catch (error) {\n logger.warn('Error during wallet disconnect', error);\n }\n processedWalletAddressRef.current = null;\n window.location.reload();\n }, [clearWalletCache, dynamicHandleLogOut]);\n\n /**\n * Connect wallet using Dynamic widget\n */\n const connectWallet = useCallback(async () => {\n if (isConnecting || !showDynamicWidget || !dynamicSdkHasLoaded) return;\n\n setIsConnecting(true);\n logger.debug('Starting wallet connection process');\n\n try {\n await showDynamicWidget(true);\n logger.debug('Dynamic widget shown');\n } catch (error) {\n setIsConnecting(false);\n logger.error('Error showing Dynamic widget:', error);\n }\n }, [isConnecting, showDynamicWidget, dynamicSdkHasLoaded]);\n\n // Process nordUser changes\n useEffect(() => {\n if (!dynamicSdkHasLoaded) return;\n\n // If the wallet is connected but NordUser hasn't been created yet,\n // move the flow forward so the user can continue with onboarding.\n if (dynamicWallet && !nordUser) {\n logger.debug(\n 'Dynamic wallet detected but NordUser not ready yet, moving to chain selection flow'\n );\n updateContext({\n hasNordAccount: false,\n hasActiveSession: false,\n });\n if (state === FlowState.CONNECTING_WALLET) {\n // Only force the transition while we are still on the initial connect screen\n try {\n const lastDepositRecord = context.isDepositOnlyFlow\n ? null\n : readLastDepositRecord(dynamicWallet.address);\n\n if (lastDepositRecord) {\n transition(FlowState.DEPOSIT_SUCCESS, {\n hasNordAccount: true,\n hasActiveSession: false,\n selectedChain: lastDepositRecord.chainName,\n selectedChainId: lastDepositRecord.chainId,\n selectedChainNetwork: lastDepositRecord.chainNetwork,\n transactionId: lastDepositRecord.transactionId,\n amount: lastDepositRecord.amount,\n lastDeposit: lastDepositRecord,\n });\n } else {\n transition(FlowState.CHAIN_SELECTION, {\n hasNordAccount: false,\n hasActiveSession: false,\n });\n }\n } catch (error) {\n logger.error('Error transitioning while waiting for NordUser:', error);\n }\n }\n setIsConnecting(false);\n return;\n }\n\n const currentNordUser = nordUser;\n const prevNordUser = prevNordUserRef.current;\n\n // Only run if nordUser has changed and we have processed a wallet\n if (currentNordUser && currentNordUser !== prevNordUser && dynamicWallet) {\n logger.debug('NordUser changed, checking account status');\n\n (async () => {\n try {\n const nordAccount = await nord!.getUser({ pubkey: dynamicWallet.address });\n const hasNordAccount = nordAccount != null;\n const sessionId = currentNordUser.sessionId;\n const hasActiveSession = sessionId != null;\n\n updateContext({ hasNordAccount, hasActiveSession });\n\n const transitionDestination = hasNordAccount\n ? sessionId != null\n ? FlowState.FINAL_SUCCESS\n : FlowState.AUTH_LOADING\n : FlowState.CHAIN_SELECTION;\n\n if (hasNordAccount && sessionId != null) {\n setIsConnected(true);\n }\n\n // Force a small delay to ensure UI updates properly\n setTimeout(() => {\n try {\n logger.debug('Attempting transition to ' + transitionDestination);\n transition(transitionDestination, {\n hasNordAccount,\n hasActiveSession,\n });\n logger.debug(\n 'Transition to ' + transitionDestination + ' completed'\n );\n } catch (error) {\n logger.error('Error during transition:', error);\n } finally {\n setIsConnecting(false);\n }\n }, 100);\n } catch (error) {\n logger.error('Error checking account status:', error);\n setIsConnecting(false);\n }\n })();\n }\n\n // Update ref so we don't re-run unless nordUser changes again\n prevNordUserRef.current = currentNordUser;\n }, [\n nordUser,\n dynamicWallet,\n updateContext,\n transition,\n setIsConnected,\n state,\n dynamicSdkHasLoaded,\n context.isDepositOnlyFlow,\n ]);\n\n\n\n\n // Handle connecting state changes in a separate effect\n useEffect(() => {\n const currentState = state;\n const prevState = prevStateRef.current;\n\n // Only run if state has changed\n if (currentState !== prevState) {\n if (currentState !== FlowState.CONNECTING_WALLET && isConnecting) {\n // If we're no longer in the connecting state, reset the connecting flag\n setIsConnecting(false);\n }\n\n // Update ref\n prevStateRef.current = currentState;\n }\n }, [state, isConnecting]);\n\n // Create the context value\n const contextValue: WalletConnectContextValue = {\n isConnecting,\n connectWallet,\n disconnectWallet,\n };\n\n return (\n <WalletConnectContext.Provider value={contextValue}>\n {children}\n </WalletConnectContext.Provider>\n );\n};\n\n/**\n * Custom hook to use the wallet connect context\n * @returns The wallet connect context value\n * @throws Error if used outside of a WalletConnectProvider\n */\nexport const useWalletConnectContext = (): WalletConnectContextValue => {\n const context = useContext(WalletConnectContext);\n\n if (context === undefined) {\n throw new Error('useWalletConnectContext must be used within a WalletConnectProvider');\n }\n\n return context;\n}; \n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withImageFallback.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/hoc/withImageFallback.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"withImageFallback.js","sourceRoot":"","sources":["../../../../src/Modal/NordFlow/hoc/withImageFallback.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,gBAAkC;IAElC,2DAA2D;IAC3D,IAAM,iBAAiB,GAAgB,UAAC,KAAK;QAC3C,iDAAiD;QACjD,IAAM,WAAW,GAAG,UAAC,IAAqB;YACxC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,IAAM,OAAO,GAAG,IAA0B,CAAC;YAE3C,4DAA4D;YAC5D,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBAC3B,IAAM,KAAkD,OAAO,CAAC,KAAK,EAA7D,GAAG,SAAA,EAAE,GAAG,SAAA,EAAE,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,SAAS,eAAA,EAAK,IAAI,cAA7C,8CAA+C,CAAgB,CAAC;gBAEtE,OAAO,CACL,KAAC,iBAAiB,aAChB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,IAAI,OAAO,EACnB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,IAChB,IAAI,EACR,CACH,CAAC;YACJ,CAAC;YAED,+CAA+C;YAC/C,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAC5C,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CACjC,OAAO,CAAC,KAAK,CAAC,QAAQ,EACtB,WAAW,CACZ,CAAC;gBAEF,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,eAAO,OAAO,CAAC,KAAK,GAAI,QAAQ,CAAC,CAAC;YACrE,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;QAEF,sDAAsD;QACtD,IAAM,iBAAiB,GAAG,KAAC,gBAAgB,eAAK,KAAK,EAAI,CAAC;QAC1D,OAAO,WAAW,CAAC,iBAAiB,CAAuB,CAAC;IAC9D,CAAC,CAAC;IAEF,iCAAiC;IACjC,IAAM,oBAAoB,GACxB,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;IACvE,iBAAiB,CAAC,WAAW,GAAG,4BAAqB,oBAAoB,MAAG,CAAC;IAE7E,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import React, { ComponentType } from 'react';\nimport { ImageWithFallback } from '../components';\n\n/**\n * A Higher-Order Component (HOC) that adds image fallback functionality to a component\n * @param WrappedComponent The component to wrap\n * @returns A new component with image fallback functionality\n */\nexport function withImageFallback<P extends object>(\n WrappedComponent: ComponentType<P>\n): React.FC<P> {\n // Create a new component that wraps the original component\n const WithImageFallback: React.FC<P> = (props) => {\n // Function to recursively process React elements\n const processNode = (node: React.ReactNode): React.ReactNode => {\n if (!React.isValidElement(node)) {\n return node;\n }\n\n const element = node as React.ReactElement;\n\n // If it's an img element, replace it with ImageWithFallback\n if (element.type === 'img') {\n const { src, alt, width, height, className, ...rest } = element.props;\n\n return (\n <ImageWithFallback\n src={src}\n alt={alt || 'Image'}\n width={width}\n height={height}\n className={className}\n {...rest}\n />\n );\n }\n\n // If it has children, process them recursively\n if (element.props && element.props.children) {\n const children = React.Children.map(\n element.props.children,\n processNode\n );\n\n return React.cloneElement(element, { ...element.props }, children);\n }\n\n return element;\n };\n\n // Render the wrapped component and process its output\n const renderedComponent = <WrappedComponent {...props} />;\n return processNode(renderedComponent) as React.ReactElement;\n };\n\n // Set display name for debugging\n const wrappedComponentName =\n WrappedComponent.displayName || WrappedComponent.name || 'Component';\n WithImageFallback.displayName = `withImageFallback(${wrappedComponentName})`;\n\n return WithImageFallback;\n}\n"]}
|
|
@@ -2,6 +2,7 @@ interface UseTestnetFaucetParams {
|
|
|
2
2
|
enabled: boolean;
|
|
3
3
|
balance: number;
|
|
4
4
|
minDeposit: number;
|
|
5
|
+
onBalanceRefresh?: () => Promise<void>;
|
|
5
6
|
}
|
|
6
7
|
interface UseTestnetFaucetResult {
|
|
7
8
|
isFaucetLoading: boolean;
|
|
@@ -13,5 +14,5 @@ interface UseTestnetFaucetResult {
|
|
|
13
14
|
/**
|
|
14
15
|
* Centralizes the faucet orchestration logic so it can be toggled from the widget entry point.
|
|
15
16
|
*/
|
|
16
|
-
export declare function useTestnetFaucet({ enabled, balance, minDeposit, }: UseTestnetFaucetParams): UseTestnetFaucetResult;
|
|
17
|
+
export declare function useTestnetFaucet({ enabled, balance, minDeposit, onBalanceRefresh, }: UseTestnetFaucetParams): UseTestnetFaucetResult;
|
|
17
18
|
export {};
|