Skip to content

Commit

Permalink
Merge pull request #414 from terra-money/feat/display-chains-error-ha…
Browse files Browse the repository at this point in the history
…ndling

feat: display chains error handling
  • Loading branch information
terran6 authored Jun 3, 2023
2 parents 0a9ca6f + cebf863 commit 9b44387
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
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

0 comments on commit 9b44387

Please sign in to comment.