-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show recommend network and previous network
- Loading branch information
Showing
6 changed files
with
79 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Tag, Grid } from '@geist-ui/react' | ||
import { useEffect, useMemo, useState } from 'react' | ||
import { EVM_BOX_PERSIST } from '../constants' | ||
import { useChain } from '../hooks/useChain' | ||
|
||
const ChainIdMap = { | ||
BSC: '56', | ||
HECO: '128', | ||
xDAI: '100', | ||
FTM: '250', | ||
} | ||
const DEFAULT_RECOMMEND = [ | ||
ChainIdMap.BSC, | ||
ChainIdMap.FTM, | ||
ChainIdMap.HECO, | ||
// ChainIdMap.xDAI, | ||
] | ||
|
||
export const useRecommend = (chains: Chain[]): Chain[] => { | ||
const [recommends, setRecommends] = useState<Array<number | string>>(DEFAULT_RECOMMEND) | ||
const recommendChains = useMemo(() => { | ||
return recommends.map(item => chains.find(chain => String(chain.chainId) === item)).filter(Boolean) | ||
}, [recommends]) | ||
|
||
useEffect(() => { | ||
const prevSelect = window.localStorage.getItem(EVM_BOX_PERSIST) || '' | ||
|
||
setRecommends([...prevSelect.split(','), ...DEFAULT_RECOMMEND]) | ||
}, []) | ||
|
||
return recommendChains as Chain[] | ||
} | ||
|
||
export const SearchRecommend: React.FC<{ chains: Chain[] }> = ({ chains }) => { | ||
const recommends = useRecommend(chains) | ||
const [, addEthChain] = useChain() | ||
|
||
return ( | ||
<div className="search-recommends"> | ||
<Grid.Container gap={2}> | ||
<Grid> | ||
<span>{recommends.length > DEFAULT_RECOMMEND.length ? 'Recent' : 'HOT'}: </span> | ||
</Grid> | ||
{ | ||
recommends.filter(Boolean).splice(0, 2).map((chain: Chain) => ( | ||
<Grid key={chain.chainId}> | ||
<Tag type="success" onClick={() => addEthChain(chain)} >{chain.chain}({chain.network})</Tag> | ||
</Grid>), | ||
) | ||
} | ||
</Grid.Container> | ||
<style jsx>{` | ||
.search-recommends { | ||
margin-top: calc(15.25pt + 1px * 0); | ||
} | ||
`}</style> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './ChainItem' | ||
export * from './GithubCorner' | ||
export * from './SearchRecommend' |
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 @@ | ||
export const EVM_BOX_PERSIST = 'evm_box_persist' |
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
40a9c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: