Skip to content

Commit

Permalink
Merge pull request kodadot#7408 from hassnian/issue-7405
Browse files Browse the repository at this point in the history
  • Loading branch information
yangwao authored Sep 29, 2023
2 parents 9b53dc7 + 8b8aa6d commit 89dc314
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/shared/AddressChecker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
isEthereumAddress,
} from '@polkadot/util-crypto'
import correctFormat from '@/utils/ss58Format'
import { isValidAddress } from '@/utils/account'
import { CHAINS } from '@/libs/static/src/chains'
import InfoBox from '@/components/shared/view/InfoBox.vue'
import { NeoButton } from '@kodadot1/brick'
Expand All @@ -89,6 +90,7 @@ const props = defineProps<{
address: string
}>()
const { $i18n } = useNuxtApp()
const { chainProperties } = useChain()
const { urlPrefix } = usePrefix()
const currentChainName = computed(() => chainNames[urlPrefix.value])
Expand Down Expand Up @@ -142,6 +144,16 @@ const getAddressCheck = (value: string): AddressCheck => {
}
}
const isValid = isValidAddress(value)
if (isValid) {
return {
valid: false,
type: AddressType.WRONG_NETWORK_ADDRESS,
value: $i18n.t('transfers.invalidAddress.wrongNetwork'),
}
}
return { valid: false, type: AddressType.UNKNOWN }
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"transferable": "Transferable",
"networkFee": "Network fee",
"invalidAddress": {
"wrongNetwork": "wrong network",
"changeToChainAddress": "Change to {selectedChain} address",
"addressChanged": {
"title": "Changed to {selectedChain} address",
Expand Down
9 changes: 9 additions & 0 deletions utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ export function accountToPublicKey(account: string): `0x${string}` {
return u8aToHex(decoded)
}

export const isValidAddress = (address: string): boolean => {
try {
encodeAddress(decodeAddress(address))
return true
} catch (error) {
return false
}
}

export default passwordRequired

0 comments on commit 89dc314

Please sign in to comment.