Skip to content

Commit

Permalink
St 307 add guard clause to common x is undefined cases (#287)
Browse files Browse the repository at this point in the history
* fix: type error

* fix: guard close for prefix property
  • Loading branch information
ericHgorski authored Feb 28, 2023
1 parent 8a8d88d commit ab867ba
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app/sections/LCDSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const LCDSetting = () => {
() =>
Object.values(networks[network] ?? {})
.sort((a, b) => {
if (a.prefix === "terra") return -1
if (b.prefix === "terra") return 1
if (a?.prefix === "terra") return -1
if (b?.prefix === "terra") return 1
return 0
})
.map(({ chainID }) => chainID),
Expand Down
2 changes: 1 addition & 1 deletion src/auth/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const useAuth = () => {
const { words } = wallet
const address = addressFromWords(
words[networks[txOptions.chainID].coinType] ?? "",
networks[txOptions.chainID].prefix
networks[txOptions.chainID]?.prefix
)

return await lcd.tx.create([{ address }], txOptions)
Expand Down
5 changes: 4 additions & 1 deletion src/components/token/Read.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const Read = forwardRef(

const lessThanFloor = fixed && Math.pow(10, -fixed)
const lessThanFixed =
amount && lessThanFloor && amount > 0 && amount < lessThanFloor
amount &&
lessThanFloor &&
Number(amount) > 0 &&
Number(amount) < lessThanFloor

const config = { ...props, comma, fixed }
const [integer, decimal] = readAmount(amount, config).split(".")
Expand Down
8 changes: 4 additions & 4 deletions src/data/queries/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function useIBCChannels() {
const isCW20 = AccAddress.validate(tokenAddress)

// from Terra to other chains
if (networks[from].prefix === "terra") {
if (networks[from]?.prefix === "terra") {
// non-CW20 ICS transfer
if (!!icsChannel && networks[to].ibc?.ics?.fromTerra === icsChannel) {
return icsChannel
Expand All @@ -85,7 +85,7 @@ export function useIBCChannels() {
networks[to].ibc?.fromTerra

// from other chains to Terra
} else if (networks[to].prefix === "terra") {
} else if (networks[to]?.prefix === "terra") {
// non-CW20 ICS transfer
if (
!!icsChannel &&
Expand All @@ -108,9 +108,9 @@ export function useIBCChannels() {
from: string
to: string
}): string | undefined => {
if (networks[from].prefix === "terra") {
if (networks[from]?.prefix === "terra") {
return networks[to].ibc?.icsFromTerra?.contract
} else if (networks[to].prefix === "terra") {
} else if (networks[to]?.prefix === "terra") {
return networks[from].ibc?.ics?.contract
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/pages/wallet/SendPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ const SendPage = () => {
availableAssets
.find(({ denom }) => denom === (asset ?? defaultAsset))
?.chains.sort((a, b) => {
if (networks[a].prefix === "terra") return -1
if (networks[b].prefix === "terra") return 1
if (networks[a]?.prefix === "terra") return -1
if (networks[b]?.prefix === "terra") return 1
return 0
}),
[asset, availableAssets, defaultAsset, networks]
Expand Down
8 changes: 4 additions & 4 deletions src/pages/wallet/TransferPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ const TransferPage = () => {
availableAssets
.find(({ denom }) => denom === (asset ?? defaultAsset))
?.chains.sort((a, b) => {
if (networks[a].prefix === "terra") return -1
if (networks[b].prefix === "terra") return 1
if (networks[a]?.prefix === "terra") return -1
if (networks[b]?.prefix === "terra") return 1
return 0
}),
[asset, availableAssets, defaultAsset, networks]
Expand All @@ -120,8 +120,8 @@ const TransferPage = () => {
Object.keys(networks)
.filter((chainID) => chainID !== chain)
.sort((a, b) => {
if (networks[a].prefix === "terra") return -1
if (networks[b].prefix === "terra") return 1
if (networks[a]?.prefix === "terra") return -1
if (networks[b]?.prefix === "terra") return 1
return 0
}),
[networks, availableChains, chain] // eslint-disable-line
Expand Down
2 changes: 1 addition & 1 deletion src/txs/gov/SubmitProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const SubmitProposalForm = ({ chain }: { chain: string }) => {
{({ max, fee, submit }) => (
<Form onSubmit={handleSubmit(submit.fn)}>
<Grid gap={4}>
{networks[chain].prefix === "terra" && (
{networks[chain]?.prefix === "terra" && (
<FormHelp>
Upload proposal only after forum discussion on{" "}
<ExternalLink href="https://agora.terra.money">
Expand Down

0 comments on commit ab867ba

Please sign in to comment.