-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create links and make them beautiful (#146)
Co-authored-by: Thibaut Sardan <[email protected]> Co-authored-by: Thibaut Sardan <[email protected]>
- Loading branch information
1 parent
289b88b
commit 228fc48
Showing
7 changed files
with
159 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useDelegates } from '@/contexts/DelegatesContext' | ||
import { isSupportedNetwork, useNetwork } from '@/contexts/NetworkContext' | ||
import { Loader2 } from 'lucide-react' | ||
import { useEffect, useState } from 'react' | ||
import { Navigate, useParams } from 'react-router-dom' | ||
|
||
export const RedirectByName = () => { | ||
const { name, network } = useParams() | ||
const { getDelegateByName, isLoading: isDelegateLoading } = useDelegates() | ||
const [isDelegateMissing, setIsDelegateMissing] = useState(false) | ||
const [address, setAddress] = useState('') | ||
const { selectNetwork } = useNetwork() | ||
|
||
useEffect(() => { | ||
if (!network || !isSupportedNetwork(network)) { | ||
setIsDelegateMissing(true) | ||
|
||
return | ||
} | ||
|
||
selectNetwork(network) | ||
}, [network, selectNetwork]) | ||
|
||
useEffect(() => { | ||
if (!name) { | ||
setIsDelegateMissing(true) | ||
return | ||
} | ||
|
||
if (isDelegateLoading) return | ||
|
||
const delegate = getDelegateByName(name) | ||
|
||
if (!delegate) { | ||
setIsDelegateMissing(true) | ||
} else { | ||
setAddress(delegate.address) | ||
} | ||
}, [getDelegateByName, isDelegateLoading, name, network, selectNetwork]) | ||
|
||
if (address && !!network && isSupportedNetwork(network)) { | ||
return <Navigate to={`/delegate/${address}?network=${network}`} /> | ||
} | ||
|
||
if (!isDelegateMissing) { | ||
return <Loader2 className="mx-auto h-8 w-8 animate-spin" /> | ||
} | ||
|
||
return ( | ||
<div className="flex h-full w-full items-center justify-center"> | ||
Delegate not found for name:{' '} | ||
<span className="mx-2 font-bold">{name}</span> and network:{' '} | ||
<span className="mx-2 font-bold">{network}</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters