Skip to content

Commit 7c549d2

Browse files
authored
feat(refactor): Use dedot for address formatting (#217)
1 parent 52d2e43 commit 7c549d2

File tree

8 files changed

+478
-62
lines changed

8 files changed

+478
-62
lines changed

library/hooks/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@w3ux/hooks-source",
33
"license": "GPL-3.0-only",
4-
"version": "2.0.4",
4+
"version": "2.1.0",
55
"type": "module",
66
"scripts": {
77
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
@@ -22,7 +22,7 @@
2222
"typescript": "^5.8.2"
2323
},
2424
"dependencies": {
25-
"@w3ux/utils": "^2.0.6",
25+
"@w3ux/utils": "^2.0.8",
2626
"date-fns": "^4.1.0"
2727
}
2828
}

library/react-connect-kit/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@w3ux/react-connect-kit-source",
33
"license": "GPL-3.0-only",
4-
"version": "3.0.5",
4+
"version": "3.1.0",
55
"type": "module",
66
"scripts": {
77
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
88
"build": "gulp --silent"
99
},
1010
"dependencies": {
11-
"@w3ux/extension-assets": "^2.1.0",
11+
"@w3ux/extension-assets": "^2.2.0",
1212
"@w3ux/hooks": "^2.0.4",
13-
"@w3ux/utils": "^2.0.6"
13+
"@w3ux/utils": "^2.0.8"
1414
},
1515
"devDependencies": {
1616
"@types/react": "^19.0.12",

library/react-polkicon/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@w3ux/react-polkicon-source",
33
"license": "GPL-3.0-only",
4-
"version": "3.0.0",
4+
"version": "3.1.1",
55
"type": "module",
66
"scripts": {
77
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
88
"build": "gulp --silent"
99
},
1010
"dependencies": {
11-
"@polkadot-api/substrate-bindings": "^0.11.1",
1211
"@w3ux/crypto": "1.0.0",
13-
"@w3ux/utils": "^2.0.6"
12+
"@w3ux/utils": "^2.0.8",
13+
"dedot": "^0.8.1"
1414
},
1515
"devDependencies": {
1616
"@types/react": "^19.0.12",

library/react-polkicon/src/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* @license Copyright 2024 w3ux authors & contributors
22
SPDX-License-Identifier: GPL-3.0-only */
33

4-
import { AccountId } from '@polkadot-api/substrate-bindings'
54
import { blake2AsU8a } from '@w3ux/crypto'
5+
import { encodeAddress } from 'dedot/utils'
66
import { PolkiconCenter, SCHEMA } from './consts'
77
import type { Coordinate, Scheme } from './types'
88

@@ -141,7 +141,7 @@ const addressToId = (address: string): Uint8Array => {
141141
const zeroHash = blake2AsU8a(new Uint8Array(32))
142142

143143
// Get the encoded and decoded representation of the address, then hash it.
144-
const pubKeyHash = blake2AsU8a(AccountId().dec(AccountId().enc(address)))
144+
const pubKeyHash = blake2AsU8a(encodeAddress(address))
145145

146146
// Adjust each byte in the hash relative to zeroHash and return as a Uint8Array.
147147
return pubKeyHash.map((x, i) => (x + 256 - zeroHash[i]) % 256)

library/utils/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "@w3ux/utils-source",
33
"license": "GPL-3.0-only",
4-
"version": "2.0.7-alpha.2",
4+
"version": "2.0.8",
55
"type": "module",
66
"scripts": {
77
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo",
88
"test": "vitest run",
99
"build": "tsup src/**/* --format esm,cjs --target es2022 --dts --no-splitting"
1010
},
1111
"dependencies": {
12-
"@polkadot-api/substrate-bindings": "^0.11.1"
12+
"dedot": "^0.8.1"
1313
},
1414
"devDependencies": {
1515
"@types/react": "^19.0.12",

library/utils/src/base.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @license Copyright 2024 w3ux authors & contributors
22
SPDX-License-Identifier: GPL-3.0-only */
33

4-
import { AccountId } from '@polkadot-api/substrate-bindings'
4+
import { encodeAddress } from 'dedot/utils'
55

66
/**
77
* Ensures a number has at least the specified number of decimal places, retaining commas in the output if they are present in the input.
@@ -231,8 +231,7 @@ export const formatAccountSs58 = (
231231
ss58Prefix: number
232232
): string | null => {
233233
try {
234-
const codec = AccountId(ss58Prefix)
235-
return codec.dec(codec.enc(address))
234+
return encodeAddress(address, ss58Prefix)
236235
} catch (e) {
237236
return null
238237
}

library/utils/src/unit.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @license Copyright 2024 w3ux authors & contributors
22
SPDX-License-Identifier: GPL-3.0-only */
33

4-
import { AccountId } from '@polkadot-api/substrate-bindings'
4+
import { decodeAddress } from 'dedot/utils'
55
import type { MutableRefObject, RefObject } from 'react'
66
import { rmCommas, rmDecimals } from './base'
77
import type { AnyObject } from './types'
@@ -169,8 +169,7 @@ export const localStorageOrDefault = <T>(
169169
*/
170170
export const isValidAddress = (address: string): boolean => {
171171
try {
172-
const codec = AccountId()
173-
codec.dec(codec.enc(address))
172+
decodeAddress(address)
174173
return true
175174
} catch (e) {
176175
return false

0 commit comments

Comments
 (0)