Skip to content

Commit

Permalink
Merge pull request #17 from polkadot-api/validate-ss58
Browse files Browse the repository at this point in the history
add ss58 validation
  • Loading branch information
voliva authored Aug 21, 2024
2 parents 0b9c547 + bd842e9 commit 683636a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/actions/send/SendAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { truncateAddress } from "@/utils/address.ts"
import { Field, Label, Radio, RadioGroup } from "@headlessui/react"
import { state, useStateObservable } from "@react-rxjs/core"
import { merge } from "rxjs"
import { formatCurrencyWithSymbol } from "../../utils/format-currency.ts"
import { formatCurrencyWithSymbol } from "@/utils/format-currency.ts"
import { getSs58AddressInfo } from "polkadot-api"

import {
accountsWithSufficientBalance$,
Expand Down Expand Up @@ -36,10 +37,11 @@ export default function SendAction() {
const transferAmount = useStateObservable(transferAmount$)
const recipient = useStateObservable(recipient$)
const token = useStateObservable(token$)
const info = getSs58AddressInfo(recipient ?? "")

if (!recipientChainData) return "No valid recipient chain"
if (!transferAmount) return "Specify Transfer Amount"
if (!recipient) return "No valid recipient"
if (!recipient || !info.isValid) return "No valid recipient"
if (!token) return "No valid token"

const decimals = tokenDecimals[token as SupportedTokens]
Expand Down
2 changes: 2 additions & 0 deletions src/actions/send/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const chains$ = state(
)
const chainCurrencies: Partial<Record<ChainId, SupportedTokens[]>> = {
polkadotAssetHub: ["USDC", "USDT"],
rococoAssetHub: ["WND"],
westendAssetHub: ["ROC"],
}

const [chainSelected$, selectChain] = createSignal<ChainId | null>()
Expand Down
10 changes: 9 additions & 1 deletion src/actions/send/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
catchError,
combineLatest,
defer,
EMPTY,
filter,
map,
materialize,
Expand Down Expand Up @@ -215,7 +216,14 @@ export const feeEstimation$ = state(
.tx(recipient, transferAmount)
.getEstimatedFees(selectedAccount.address),
),
).pipe(map((v) => v.reduce((a, b) => a + b, 0n)))
).pipe(
map((v) => v.reduce((a, b) => a + b, 0n)),
catchError((e) => {
console.error(e)
errorToast("Error when getting estimated fees: " + e.message)
return EMPTY
}),
)
: [null]
},
),
Expand Down

0 comments on commit 683636a

Please sign in to comment.