1- < < << << < HEAD
2- import { Spinner , Text } from '@0xsequence/design-system'
3- import { useEffect , useRef } from 'react'
4- = === ===
5- import { useProjectAccessKey } from '@0xsequence/connect'
61import { Button , Spinner , Text } from '@0xsequence/design-system'
7- import { useEffect , useRef , useState } from 'react'
8- > >>> >>> 51730908 ( feat ( onramp ) : add optional Transak alternate flow with default and windowed modes )
2+ import { useEffect , useRef } from 'react'
93
104import { HEADER_HEIGHT } from '../constants/index.js'
115import type { AddFundsSettings } from '../contexts/AddFundsModal.js'
126import { useAddFundsModal } from '../hooks/index.js'
13- < << << << HEAD
147import { useTransakWidgetUrl } from '../hooks/useTransakWidgetUrl.js'
15- = === ===
16- import { getTransakLink , getTransakLinkFromSequenceApi } from '../utils/transak.js'
17- > >>> >>> 51730908 ( feat ( onramp ) : add optional Transak alternate flow with default and windowed modes )
188
199const EventTypeOrderCreated = 'TRANSAK_ORDER_CREATED'
2010const EventTypeOrderSuccessful = 'TRANSAK_ORDER_SUCCESSFUL'
@@ -27,12 +17,12 @@ export const AddFundsContent = () => {
2717
2818export const AddFundsContentTransak = ( ) => {
2919 const { addFundsSettings = { } as AddFundsSettings } = useAddFundsModal ( )
30- << < < << < HEAD
3120
3221 const {
3322 data : transakLinkData ,
3423 isLoading : isLoadingTransakLink ,
35- error : errorTransakLink
24+ isError : isErrorTransakLink ,
25+ refetch : refetchTransakLink
3626 } = useTransakWidgetUrl ( {
3727 referrerDomain : window . location . origin ,
3828 walletAddress : addFundsSettings . walletAddress ,
@@ -43,13 +33,7 @@ export const AddFundsContentTransak = () => {
4333 defaultCryptoCurrency : addFundsSettings ?. defaultCryptoCurrency || 'USDC' ,
4434 cryptoCurrencyList : addFundsSettings ?. cryptoCurrencyList
4535 } )
46- === = ===
47- const { transakApiUrl, transakApiKey, sequenceTransakApiUrl } = useEnvironmentContext ( )
48- >>> > >>> 51730908 ( feat ( onramp ) : add optional Transak alternate flow with default and windowed modes )
4936 const iframeRef = useRef < HTMLIFrameElement | null > ( null )
50- const projectAccessKey = useProjectAccessKey ( )
51- const [ isLoading , setIsLoading ] = useState ( false )
52- const [ creationLinkFailed , setCreationLinkFailed ] = useState ( false )
5337 const { transakOnRampKind = 'default' } = addFundsSettings
5438 const isTransakOnRampKindWindowed = transakOnRampKind === 'windowed'
5539
@@ -82,71 +66,16 @@ export const AddFundsContentTransak = () => {
8266
8367 const link = transakLinkData ?. url
8468
85- if ( isLoadingTransakLink ) {
86- return (
87- < div className = "flex items-center justify-center w-full px-4 pb-4 h-[200px]" >
88- < Spinner />
89- </ div >
90- )
91- }
92-
93- if ( errorTransakLink ) {
94- return (
95- < div className = "flex items-center justify-center w-full px-4 pb-4 h-[200px]" >
96- < Text color = "text100" > An error has occurred</ Text >
97- </ div >
98- )
99- }
100-
101- async function handleTransakLink ( {
102- addFundsSettings,
103- sequenceTransakApiUrl,
104- projectAccessKey,
105- setCreationLinkFailed,
106- setIsLoading
107- } : {
108- addFundsSettings : AddFundsSettings
109- sequenceTransakApiUrl : string
110- projectAccessKey : string
111- setCreationLinkFailed : ( value : boolean ) = > void
112- setIsLoading : ( value : boolean ) = > void
113- } ) {
114- try {
115- setCreationLinkFailed ( false )
116- setIsLoading ( true )
117- const link = await getTransakLinkFromSequenceApi ( addFundsSettings , sequenceTransakApiUrl , projectAccessKey )
118-
119- if ( link ) {
120- window . open ( link , '_blank' )
121- } else {
122- setCreationLinkFailed ( true )
123- }
124- setIsLoading ( false )
125- } catch ( error ) {
126- console . error ( `The creation of the Transak link has failed. Error: ` , error )
127- setCreationLinkFailed ( true )
128- setIsLoading ( false )
129- }
130- }
131-
13269 useEffect ( ( ) => {
133- if ( ! isTransakOnRampKindWindowed ) {
134- return
70+ if ( isTransakOnRampKindWindowed && ! isLoadingTransakLink && link ) {
71+ window . open ( link , '_blank' , 'noopener' )
13572 }
73+ } , [ isTransakOnRampKindWindowed , isLoadingTransakLink , link ] )
13674
137- handleTransakLink ( { addFundsSettings, sequenceTransakApiUrl, projectAccessKey, setIsLoading, setCreationLinkFailed } )
138- } , [ ] )
139-
140- if ( isLoading ) {
75+ if ( isLoadingTransakLink ) {
14176 return (
142- < div
143- className = "flex items-center justify-center w-full px-4 pb-4 h-full"
144- style = { {
145- height : '600px' ,
146- paddingTop : HEADER_HEIGHT
147- } }
148- >
149- < Spinner size = "lg" />
77+ < div className = "flex items-center justify-center w-full px-4 pb-4 h-[200px]" >
78+ < Spinner />
15079 </ div >
15180 )
15281 }
@@ -160,33 +89,36 @@ export const AddFundsContentTransak = () => {
16089 paddingTop : HEADER_HEIGHT
16190 } }
16291 >
163- { creationLinkFailed ? (
92+ { isErrorTransakLink ? (
16493 < div className = "flex flex-col gap-2 items-center" >
16594 < Text color = "text100" > The creation of the Transak link failed.</ Text >
16695 < Button
16796 className = "w-fit"
16897 onClick = { ( ) => {
169- handleTransakLink ( {
170- addFundsSettings,
171- sequenceTransakApiUrl,
172- projectAccessKey,
173- setIsLoading,
174- setCreationLinkFailed
175- } )
98+ // @ts -ignore-next-line
99+ refetchTransakLink ( )
176100 } }
177101 >
178102 Try Again
179103 </ Button >
180104 </ div >
181105 ) : (
182106 < div className = "flex gap-2 items-center text-center" >
183- < Text color = "text100" > Once you've added funds, you can close this window and try buying with crypto again. </ Text >
107+ < Text color = "text100" > { addFundsSettings ?. windowedOnRampMessage || 'Funds will be added from another window.' } </ Text >
184108 </ div >
185109 ) }
186110 </ div >
187111 )
188112 }
189113
114+ if ( isErrorTransakLink ) {
115+ return (
116+ < div className = "flex items-center justify-center w-full px-4 pb-4 h-[200px]" >
117+ < Text color = "text100" > An error has occurred</ Text >
118+ </ div >
119+ )
120+ }
121+
190122 return (
191123 < div
192124 className = "flex items-center w-full px-4 pb-4 h-full"
0 commit comments