Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display chains error handling #414

Merged
merged 1 commit into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/app/sections/DisplayChainsSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const DisplayChainsSetting = () => {

const onChange = (value: string) => {
if (isTerraChain(value)) return
const newDisplayChains = displayChains.includes(value)
? displayChains.filter((chainID) => chainID !== value)
: [...displayChains, value]
const newDisplayChains = displayChains?.includes(value)
? displayChains?.filter((chainID) => chainID !== value)
: [...(displayChains || []), value]
changeDisplayChains(newDisplayChains)
if (value === selectedDisplayChain) {
changeSelectedDisplayChain(undefined)
Expand All @@ -42,7 +42,7 @@ const DisplayChainsSetting = () => {
)
.map((chainID) => ({
value: chainID,
selected: displayChains.includes(chainID),
selected: displayChains?.includes(chainID),
label: network[chainID].name,
icon: network[chainID].icon,
}))
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/ChainFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ChainFilter = ({
() =>
sortedDisplayChains
.map((id) => network[id])
.filter((n) => displayChains.includes(n?.chainID)),
.filter((n) => displayChains?.includes(n?.chainID)),
[network, sortedDisplayChains, displayChains]
)

Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/OtherChainsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const OtherChainsButton = ({ list, handleSetChain }: Props) => {
const closePopover = () => setKey((key) => key + 1)

const onClick = (chainID: string) => {
if (displayChains.includes(chainID)) {
if (displayChains?.includes(chainID)) {
changeSelectedDisplayChain(chainID)
handleSetChain(chainID)
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/components/layout/SimpleChainList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const cx = classNames.bind(styles)
const SimpleChainList = ({ list, onClick }: Props) => {
const { displayChains } = useDisplayChains()
const sortedList = list.sort((a, b) =>
displayChains.includes(a.chainID) && !displayChains.includes(b.chainID)
displayChains?.includes(a.chainID) && !displayChains?.includes(b.chainID)
? -1
: !displayChains.includes(a.chainID) && displayChains.includes(b.chainID)
: !displayChains?.includes(a.chainID) &&
displayChains?.includes(b.chainID)
? 1
: 0
)
Expand All @@ -25,7 +26,7 @@ const SimpleChainList = ({ list, onClick }: Props) => {
<button
key={chainID}
className={cx(styles.button, {
[styles.active]: displayChains.includes(chainID),
[styles.active]: displayChains?.includes(chainID),
})}
onClick={() => onClick(chainID)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const useSortedDisplayChains = () => {
const chains = useChainsByAssetValue()
const { displayChains } = useDisplayChains()
const sorted = chains
.filter((c) => displayChains.includes(c.chain))
.filter((c) => displayChains?.includes(c.chain))
.filter((c) => isTerraChain(c.chain))
.concat(
chains.filter((c) => isOsmosisChain(c.chain)),
Expand Down
7 changes: 5 additions & 2 deletions src/utils/localStorage/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ export const useDisplayChains = () => {
const [displayChains, setDisplayChains] = useRecoilState(displayChainsState)
const changeDisplayChains = useCallback(
(newChains: string[]) => {
const newDisplayChains = { ...displayChains, [networkName]: newChains }
const newDisplayChains = {
...(displayChains || []),
[networkName]: newChains,
}
setLocalSetting(SettingKey.DisplayChains, newDisplayChains)
setDisplayChains(newDisplayChains)
},
[setDisplayChains, networkName, displayChains]
)
return {
all: displayChains,
displayChains: displayChains[networkName].filter((c) => c !== ""),
displayChains: displayChains[networkName]?.filter((c) => c !== ""),
changeDisplayChains,
}
}
Expand Down