setError("Error loading file")}
- onLoaded={setValue}
+ onLoaded={(value) => setValue(value.asBytes())}
/>
@@ -182,4 +186,6 @@ const BinaryEditModalContent: FC<
}
const parseInput = (value: string | Uint8Array) =>
- value instanceof Uint8Array ? value : fromHex(value)
+ value instanceof Uint8Array
+ ? Binary.fromBytes(value)
+ : Binary.fromHex(value.startsWith("0x") ? value : `0x${value}`)
diff --git a/src/components/BinaryInput.tsx b/src/components/BinaryInput.tsx
index 3c71c90..2b2cb40 100644
--- a/src/components/BinaryInput.tsx
+++ b/src/components/BinaryInput.tsx
@@ -7,18 +7,17 @@ import { twMerge } from "tailwind-merge"
import { SwitchBinary } from "./Icons"
import { TextInputField } from "./TextInputField"
import { useGenericSynchronizeInput } from "./useSynchroniseInput"
-import { fromHex, toHex } from "polkadot-api/utils"
export const BinaryInput: React.FC<{
- encodedValue: Uint8Array | NOTIN
- onValueChanged: (newValue: Uint8Array | NOTIN) => boolean
+ encodedValue: Binary | NOTIN
+ onValueChanged: (newValue: Binary | NOTIN) => boolean
len?: number
}> = ({ encodedValue, onValueChanged, len }) => {
const [localInput, setLocalInput] = useGenericSynchronizeInput(
encodedValue,
onValueChanged,
(value) => validate(parseValue(value), len),
- "" as string | Uint8Array,
+ "" as string | Binary,
serializeValue,
checkEqualInputBinary,
)
@@ -45,7 +44,7 @@ export const BinaryInput: React.FC<{
}
const parsed = parseValue(inputValue)
- const length = parsed === NOTIN ? null : parsed.length
+ const length = parsed === NOTIN ? null : parsed.asBytes().length
const oddHexLength =
typeof localInput === "string" &&
@@ -83,9 +82,9 @@ export const BinaryInput: React.FC<{
type="button"
onClick={() => {
if (inputValue.startsWith("0x")) {
- setLocalInput(serializeValue(fromHex(inputValue)))
+ setLocalInput(serializeValue(Binary.fromHex(inputValue)))
} else {
- setLocalInput(toHex(Binary.fromText(inputValue)))
+ setLocalInput(Binary.fromText(inputValue).asHex())
}
}}
>
@@ -111,7 +110,7 @@ export const BinaryInput: React.FC<{
export const BinaryFileInput: FC<{
validate: (file: File) => boolean
- onLoaded: (value: Uint8Array) => void
+ onLoaded: (value: Binary) => void
onError: () => void
}> = ({ validate, onLoaded, onError }) => {
const loadFile = async (file: File) => {
@@ -125,7 +124,7 @@ export const BinaryFileInput: FC<{
reader.onerror = reject
reader.readAsArrayBuffer(file)
})
- onLoaded(new Uint8Array(buffer))
+ onLoaded(Binary.fromBytes(new Uint8Array(buffer)))
} catch (ex) {
console.error(ex)
onError()
@@ -144,22 +143,19 @@ export const BinaryFileInput: FC<{
)
}
-const validate = (
- value: Uint8Array | NOTIN,
- len?: number,
-): Uint8Array | NOTIN => {
+const validate = (value: Binary | NOTIN, len?: number): Binary | NOTIN => {
if (!len || value === NOTIN) return value
- return value.length !== len ? NOTIN : value
+ return value.asBytes().length !== len ? NOTIN : value
}
-const parseValue = (value: string | Uint8Array): Uint8Array | NOTIN => {
- if (value instanceof Uint8Array) return value
+const parseValue = (value: string | Binary): Binary | NOTIN => {
+ if (value instanceof Binary) return value
if (value.trim() === "") return Binary.fromText("")
if (value.startsWith("0x")) {
try {
- return fromHex(value)
+ return Binary.fromHex(value)
} catch (_) {
return NOTIN
}
@@ -168,35 +164,40 @@ const parseValue = (value: string | Uint8Array): Uint8Array | NOTIN => {
return Binary.fromText(value)
}
-const serializeValue = (value: Uint8Array): string | Uint8Array => {
- if (value.length === 0) return ""
- if (value.length > 5 * 1024 * 1024) return value
+const serializeValue = (value: Binary): string | Binary => {
+ const bytes = value.asBytes()
+ if (bytes.length === 0) return ""
+ if (bytes.length > 5 * 1024 * 1024) return value
return bytesToString(value)
}
const textDecoder = new TextDecoder("utf-8", { fatal: true })
-export const getBytesFormat = (value: Uint8Array) => {
+export const getBytesFormat = (value: Binary) => {
try {
- if (value.slice(0, 5).every((b) => b < 32)) throw null
+ const bytes = value.asBytes()
+ if (bytes.slice(0, 5).every((b) => b < 32)) throw null
return {
type: "text",
- value: textDecoder.decode(value),
+ value: textDecoder.decode(bytes),
}
} catch (_) {
return {
type: "hex",
- value: toHex(value),
+ value: value.asHex(),
}
}
}
-export const bytesToString = (value: Uint8Array) => getBytesFormat(value).value
+export const bytesToString = (value: Binary) => getBytesFormat(value).value
export const checkEqualInputBinary = (
- input: string | Uint8Array,
- value: Uint8Array | typeof NOTIN,
+ input: string | Binary,
+ value: Binary | typeof NOTIN,
) => {
const parsed = parseValue(input)
if (parsed === NOTIN || value === NOTIN) return true
- return byteArraysAreEqual(parsed, value)
+ const inputBytes = parsed.asBytes()
+ const valueBytes = value.asBytes()
+
+ return byteArraysAreEqual(inputBytes, valueBytes)
}
diff --git a/src/components/JsonDisplay.tsx b/src/components/JsonDisplay.tsx
index 7fcf06e..4f7d16c 100644
--- a/src/components/JsonDisplay.tsx
+++ b/src/components/JsonDisplay.tsx
@@ -1,4 +1,5 @@
import { bytesToString } from "@/components/BinaryInput"
+import { Binary } from "@polkadot-api/substrate-bindings"
import { FC } from "react"
import ReactJson from "react18-json-view"
import "react18-json-view/src/dark.css"
@@ -17,14 +18,14 @@ export const JsonDisplay: FC<{
src={src}
dark={theme === "dark"}
theme="a11y"
- replacer={(v) => (v instanceof Uint8Array ? bytesToString(v) : v)}
+ replacer={(v) => (v instanceof Binary ? bytesToString(v) : v)}
customizeCopy={(v) =>
JSON.stringify(
v,
(_, v) =>
typeof v === "bigint"
? `${v}n`
- : v instanceof Uint8Array
+ : v instanceof Binary
? bytesToString(v)
: v,
2,
diff --git a/src/pages/Accounts/AccountList.tsx b/src/pages/Accounts/AccountList.tsx
index 6ce7e3f..1965cae 100644
--- a/src/pages/Accounts/AccountList.tsx
+++ b/src/pages/Accounts/AccountList.tsx
@@ -12,7 +12,6 @@ import {
} from "@react-rxjs/core"
import { Send } from "lucide-react"
import { CompatibilityLevel, SS58String } from "polkadot-api"
-import { toHex } from "polkadot-api/utils"
import {
Account,
ledgerProviderId,
@@ -78,7 +77,7 @@ const AccountCard: FC<{
@@ -128,7 +127,7 @@ const balance$ = state(
typedApi.query.System.Account.watchValue(accountId),
),
map((account) => {
- const { reserved, free, frozen } = account.value.data
+ const { reserved, free, frozen } = account.data
const total = reserved + free
// TODO ED
@@ -157,12 +156,12 @@ const getTransferCallData$ = state(
const tokenDecimals = chainProperties?.tokenDecimals
if (tokenDecimals == null) return null
-
- const staticApis = await typedApi.getStaticApis()
+ const token = await typedApi.compatibilityToken
if (
- !staticApis.compat.tx.Balances.transfer_keep_alive.isCompatible(
+ !typedApi.tx.Balances.transfer_keep_alive.isCompatible(
CompatibilityLevel.BackwardsCompatible,
+ token,
)
) {
return null
@@ -171,12 +170,12 @@ const getTransferCallData$ = state(
return (dest: SS58String) => {
const value = 10n ** BigInt(tokenDecimals)
- return toHex(
- staticApis.tx.Balances.transfer_keep_alive.getCallData({
- dest: MultiAddress.Id(dest),
- value,
- }),
- )
+ return typedApi.tx.Balances.transfer_keep_alive({
+ dest: MultiAddress.Id(dest),
+ value,
+ })
+ .getEncodedData(token)
+ .asHex()
}
}),
),
diff --git a/src/pages/Explorer/Detail/BlockBody.tsx b/src/pages/Explorer/Detail/BlockBody.tsx
index 5134c94..673b0b6 100644
--- a/src/pages/Explorer/Detail/BlockBody.tsx
+++ b/src/pages/Explorer/Detail/BlockBody.tsx
@@ -14,7 +14,7 @@ import { BlockStorageDiff } from "./BlockStorageDiff"
import { ApplyExtrinsicEvent, Extrinsic } from "./Extrinsic"
import { getHashParams } from "@/hashParams"
import { Blake2256 } from "@polkadot-api/substrate-bindings"
-import { toHex } from "polkadot-api/utils"
+import { fromHex, toHex } from "@polkadot-api/utils"
const blockExtrinsics$ = state((hash: string) => {
const body$ = blockInfoState$(hash).pipe(
@@ -31,7 +31,7 @@ const blockExtrinsics$ = state((hash: string) => {
map(([body, { txDecoder }]) =>
body.map((raw, idx) => ({
idx,
- hash: toHex(Blake2256(raw)),
+ hash: toHex(Blake2256(fromHex(raw))),
...txDecoder(raw),
})),
),
diff --git a/src/pages/Explorer/Detail/BlockStorageDiff.tsx b/src/pages/Explorer/Detail/BlockStorageDiff.tsx
index 5897be7..361702d 100644
--- a/src/pages/Explorer/Detail/BlockStorageDiff.tsx
+++ b/src/pages/Explorer/Detail/BlockStorageDiff.tsx
@@ -19,7 +19,7 @@ import {
u8,
Vector,
} from "@polkadot-api/substrate-bindings"
-import { toHex } from "polkadot-api/utils"
+import { toHex } from "@polkadot-api/utils"
import { state, useStateObservable } from "@react-rxjs/core"
import { Binary, Codec } from "polkadot-api"
import { FC } from "react"
@@ -37,12 +37,12 @@ const blockDiff$ = state(
const palletKeys = Object.fromEntries(
lookup.metadata.pallets.map((pallet) => [
- toHex(Twox128(Binary.fromText(pallet.name))).slice(2),
+ toHex(Twox128(Binary.fromText(pallet.name).asBytes())).slice(2),
{
name: pallet.name,
entries: Object.fromEntries(
pallet.storage?.items.map((item) => [
- toHex(Twox128(Binary.fromText(item.name))).slice(2),
+ toHex(Twox128(Binary.fromText(item.name).asBytes())).slice(2),
item.name,
]) ?? [],
),
@@ -149,7 +149,7 @@ export const BlockStorageDiff: FC<{
? `(${JSON.stringify(v, (_, v) =>
typeof v === "bigint"
? `${v}n`
- : v instanceof Uint8Array
+ : v instanceof Binary
? bytesToString(v)
: v,
)})`
@@ -176,7 +176,7 @@ export const BlockStorageDiff: FC<{
)
}
-const strToHex = (v: string) => toHex(Binary.fromText(v))
+const strToHex = (v: string) => Binary.fromText(v).asHex()
const wellKnownKeys: Record<
string,
{
diff --git a/src/pages/Explorer/Detail/Extrinsic.tsx b/src/pages/Explorer/Detail/Extrinsic.tsx
index 97a5a7c..bfe259f 100644
--- a/src/pages/Explorer/Detail/Extrinsic.tsx
+++ b/src/pages/Explorer/Detail/Extrinsic.tsx
@@ -9,8 +9,7 @@ import { shortStr } from "@/utils"
import { SystemEvent } from "@polkadot-api/observable-client"
import { DecodedExtrinsic } from "@polkadot-api/tx-utils"
import { Dot, Edit } from "lucide-react"
-import { Enum, HexString, SS58String } from "polkadot-api"
-import { toHex } from "polkadot-api/utils"
+import { Binary, Enum, HexString, SS58String } from "polkadot-api"
import { FC, useEffect, useRef, useState } from "react"
import { twMerge } from "tailwind-merge"
@@ -42,13 +41,13 @@ export const Extrinsic: FC<{
{extrinsic.idx}. {extrinsic.call.type}.{extrinsic.call.value.type}
-
- {extrinsic.callData.length > 1024 ? (
+
+ {extrinsic.callData.asBytes().length > 1024 ? (
) : (
-
+
)}
@@ -108,7 +107,7 @@ const SignedExtensions: FC<{ extra: Record }> = ({
const SignedExtension: FC<{ id: string; value: unknown }> = ({ id, value }) => {
const [expanded, setExpanded] = useState(false)
const inlineJson = JSON.stringify(value, (_, v) =>
- typeof v === "bigint" ? String(v) : v instanceof Uint8Array ? toHex(v) : v,
+ typeof v === "bigint" ? String(v) : v instanceof Binary ? v.asHex() : v,
)
if (!inlineJson || inlineJson.length < 40) {
diff --git a/src/pages/Explorer/EpochTime.tsx b/src/pages/Explorer/EpochTime.tsx
index 3985cf9..7c19245 100644
--- a/src/pages/Explorer/EpochTime.tsx
+++ b/src/pages/Explorer/EpochTime.tsx
@@ -50,7 +50,7 @@ const epochFromCall$ = runtimeCtx$.pipe(
}
return (
getFromApi("BabeApi", "configuration")?.then((r) =>
- Number((r as any).epoch_length),
+ Number(r.epoch_length),
) ?? of(null)
)
}),
@@ -72,7 +72,7 @@ const epochStartBlock$ = state(
? client
.getUnsafeApi()
.query[pallet][entry].watchValue()
- .pipe(map(({ value }) => Number((value as any)[1])))
+ .pipe(map(([, duration]) => Number(duration)))
: of(null)
}),
),
diff --git a/src/pages/Explorer/block.state.ts b/src/pages/Explorer/block.state.ts
index 7dfd438..9760113 100644
--- a/src/pages/Explorer/block.state.ts
+++ b/src/pages/Explorer/block.state.ts
@@ -1,16 +1,16 @@
import { chopsticksInstance$ } from "@/chopsticks/chopsticks"
import { chainClient$, client$ } from "@/state/chains/chain.state"
import { SystemEvent } from "@polkadot-api/observable-client"
-import { blockHeader, SizedHex } from "@polkadot-api/substrate-bindings"
+import { blockHeader } from "@polkadot-api/substrate-bindings"
import { liftSuspense, state } from "@react-rxjs/core"
import { combineKeys, partitionByKey } from "@react-rxjs/utils"
import {
BlockHeader,
+ FixedSizeBinary,
HexString,
PolkadotClient,
BlockInfo as RawBlockInfo,
} from "polkadot-api"
-import { fromHex } from "polkadot-api/utils"
import {
catchError,
combineLatest,
@@ -56,7 +56,7 @@ export interface BlockInfo {
hash: string
parent: string
number: number
- body: Uint8Array[] | null
+ body: string[] | null
events: SystemEvent[] | null
header: BlockHeader | null
status: BlockState
@@ -93,7 +93,7 @@ export const [blockInfo$, recordedBlocks$] = partitionByKey(
hash: of(hash),
parent: of(parent),
number: of(number),
- body: client.getBlockBody$(hash).pipe(
+ body: client.watchBlockBody(hash).pipe(
startWith(null),
catchError((err) => {
console.error("fetch body failed", err)
@@ -103,7 +103,7 @@ export const [blockInfo$, recordedBlocks$] = partitionByKey(
events: from(
client.getUnsafeApi().query.System.Events.getValue({
at: hash,
- }) as Promise,
+ }),
).pipe(
startWith(null),
catchError((err) => {
@@ -154,10 +154,10 @@ const getUnpinnedBlockInfo$ = (hash: string): Observable =>
),
),
),
- body: client.getBlockBody$(hash),
+ body: client.watchBlockBody(hash),
events: client.getUnsafeApi().query.System.Events.getValue({
at: hash,
- }) as Promise,
+ }),
}).pipe(
map(({ headerAndStatus: { header, status }, body, events }) => ({
hash: hash,
@@ -221,7 +221,7 @@ const getUnpinnedBlockInfoFallback$ = (
({ block: { extrinsics, header }, status, number }): BlockInfo => ({
hash,
parent: header.parentHash,
- body: extrinsics.map(fromHex),
+ body: extrinsics,
events: null,
header: {
digests: header.digest.logs
@@ -254,7 +254,7 @@ export const inMemoryBlocks$ = state(
)
inMemoryBlocks$.pipe(liftSuspense()).subscribe()
-export const blockHash$ = (hashOrHeight: string): Observable> =>
+export const blockHash$ = (hashOrHeight: string) =>
hashOrHeight.length > 63
? of(hashOrHeight.startsWith("0x") ? hashOrHeight : `0x${hashOrHeight}`)
: client$.pipe(
@@ -268,13 +268,11 @@ export const blockHash$ = (hashOrHeight: string): Observable> =>
if (x.length) return x[0]
throw null
}),
- catchError(
- () =>
- client
- .getUnsafeApi()
- .query.System.BlockHash.getValue(
- Number(hashOrHeight),
- ) as Promise>,
+ catchError(() =>
+ client
+ .getUnsafeApi()
+ .query.System.BlockHash.getValue(Number(hashOrHeight))
+ .then((x: FixedSizeBinary<32>) => x.asHex()),
),
),
),
diff --git a/src/pages/Explorer/blockTime.state.ts b/src/pages/Explorer/blockTime.state.ts
index bd8c2bb..81c491d 100644
--- a/src/pages/Explorer/blockTime.state.ts
+++ b/src/pages/Explorer/blockTime.state.ts
@@ -36,7 +36,7 @@ const fromCall$ = runtimeCtx$.pipe(
return (
getFromApi("AuraApi", "slot_duration")?.then((r) => Number(r)) ??
getFromApi("BabeApi", "configuration")?.then((r) =>
- Number((r as any).slot_duration),
+ Number(r.slot_duration),
) ??
of(null)
)
diff --git a/src/pages/Extrinsics/Extrinsics.tsx b/src/pages/Extrinsics/Extrinsics.tsx
index 7f015b9..24a4949 100644
--- a/src/pages/Extrinsics/Extrinsics.tsx
+++ b/src/pages/Extrinsics/Extrinsics.tsx
@@ -8,7 +8,8 @@ import {
CodecComponentType,
CodecComponentValue,
} from "@polkadot-api/react-builder"
-import { fromHex, toHex } from "polkadot-api/utils"
+import { Binary } from "@polkadot-api/substrate-bindings"
+import { toHex } from "@polkadot-api/utils"
import { state, useStateObservable } from "@react-rxjs/core"
import { useLayoutEffect, useState } from "react"
import { useLocation } from "react-router-dom"
@@ -142,7 +143,7 @@ export const Extrinsics = withSubscribe(
void }> = ({
new Uint8Array([4]),
data,
])
- trackUnsignedTx(unsignedTx)
+ trackUnsignedTx(toHex(unsignedTx))
onClose()
}}
className="flex gap-2 items-center justify-center"
diff --git a/src/pages/Storage/StorageQuery.tsx b/src/pages/Storage/StorageQuery.tsx
index fdf8f9d..8e3a193 100644
--- a/src/pages/Storage/StorageQuery.tsx
+++ b/src/pages/Storage/StorageQuery.tsx
@@ -14,9 +14,10 @@ import {
NOTIN,
} from "@polkadot-api/react-builder"
import { Twox128 } from "@polkadot-api/substrate-bindings"
-import { fromHex, toHex } from "polkadot-api/utils"
+import { toHex } from "@polkadot-api/utils"
import { state, useStateObservable, withDefault } from "@react-rxjs/core"
import { createSignal } from "@react-rxjs/utils"
+import { Binary } from "polkadot-api"
import { FC } from "react"
import {
combineLatest,
@@ -77,13 +78,11 @@ export const StorageQuery: FC = () => {
const hash$ = single
? chainClient$.pipe(
switchMap(({ chainHead }) =>
- chainHead
- .storage$(hash, "hash", (ctx) =>
- ctx.dynamicBuilder
- .buildStorage(entry!.pallet, entry!.entry)
- .keys.enc(...args),
- )
- .pipe(map(({ value }) => value)),
+ chainHead.storage$(hash, "hash", (ctx) =>
+ ctx.dynamicBuilder
+ .buildStorage(entry!.pallet, entry!.entry)
+ .keys.enc(...args),
+ ),
),
)
: of(null)
@@ -367,7 +366,7 @@ const StorageKeyInput: FC<{
setKeyValue({ idx, value })}
@@ -442,7 +441,7 @@ export const KeyDisplay: FC = () => {
) => {
let newKeysEnabled = keysEnabled
if (
@@ -519,7 +518,9 @@ const decodeKey = (
? []
: item.type.value.hashers.map((x) => hashersToLength[x.tag])
- let argsRemaining = fromHex(keyRemaining.replace(twoxHash(item.name), "0x"))
+ let argsRemaining = Binary.fromHex(
+ keyRemaining.replace(twoxHash(item.name), "0x"),
+ ).asBytes()
const args: any[] = []
const argsLen = codec.args.inner.length
diff --git a/src/pages/Storage/StorageSet.tsx b/src/pages/Storage/StorageSet.tsx
index 650e33c..54de680 100644
--- a/src/pages/Storage/StorageSet.tsx
+++ b/src/pages/Storage/StorageSet.tsx
@@ -3,7 +3,7 @@ import { Chopsticks } from "@/components/Icons"
import { Button } from "@/components/ui/button"
import { chainClient$, client$, lookup$ } from "@/state/chains/chain.state"
import { getTypeComplexity } from "@/utils"
-import { fromHex, toHex } from "polkadot-api/utils"
+import { fromHex, toHex } from "@polkadot-api/utils"
import { state, useStateObservable } from "@react-rxjs/core"
import { createSignal } from "@react-rxjs/utils"
import { FC, useState } from "react"
@@ -31,7 +31,7 @@ const currentValue$ = state(
),
withLatestFrom(lookup$, selectedEntry$.pipe(filter((v) => v != null))),
map(([v, lookup, entry]) => {
- if (v != null) return v.value
+ if (v != null) return v
const pallet = lookup.metadata.pallets.find(
(p) => p.name == entry.pallet,
)!
diff --git a/src/pages/Storage/StorageSubscriptions.tsx b/src/pages/Storage/StorageSubscriptions.tsx
index c094935..f9f3036 100644
--- a/src/pages/Storage/StorageSubscriptions.tsx
+++ b/src/pages/Storage/StorageSubscriptions.tsx
@@ -17,7 +17,7 @@ import { CodecComponentType, NOTIN } from "@polkadot-api/react-builder"
import { Button } from "@polkahub/ui-components"
import { useStateObservable } from "@react-rxjs/core"
import { ChevronLeft, ChevronRight, StopCircle, Trash2 } from "lucide-react"
-import { Enum } from "polkadot-api"
+import { Binary, Enum } from "polkadot-api"
import { FC, MouseEvent, ReactNode, useMemo, useState } from "react"
import { Virtuoso } from "react-virtuoso"
import { BlockState } from "../Explorer/block.state"
@@ -30,7 +30,6 @@ import {
storageSubscriptionKeys$,
StorageSubscriptionValue,
} from "./storage.state"
-import { fromHex } from "polkadot-api/utils"
export const StorageSubscriptions: FC = () => {
const keys = useStateObservable(storageSubscriptionKeys$)
@@ -461,7 +460,7 @@ const KeyDisplay: FC<{
}> = ({ value, keyCodec }) => {
const binaryValue = (() => {
try {
- return keyCodec ? fromHex(keyCodec.enc(...value)) : null
+ return keyCodec ? Binary.fromHex(keyCodec.enc(...value)).asBytes() : null
} catch (_) {
return null
}
diff --git a/src/pages/Storage/storage.state.ts b/src/pages/Storage/storage.state.ts
index 585a459..06339a6 100644
--- a/src/pages/Storage/storage.state.ts
+++ b/src/pages/Storage/storage.state.ts
@@ -14,7 +14,7 @@ import {
partitionByKey,
toKeySet,
} from "@react-rxjs/utils"
-import { Enum, HexString } from "polkadot-api"
+import { Binary, Enum, HexString } from "polkadot-api"
import {
catchError,
combineLatest,
@@ -416,7 +416,10 @@ export const storageSubscription$ = state(
export const stringifyArg = (value: unknown) => {
if (typeof value === "object" && value !== null) {
- return value instanceof Uint8Array ? bytesToString(value) : "arg"
+ if (value instanceof Binary) {
+ return bytesToString(value)
+ }
+ return "arg"
}
return String(value)
}
diff --git a/src/pages/Transactions/Transaction.tsx b/src/pages/Transactions/Transaction.tsx
index 9bd9fb1..79b47ed 100644
--- a/src/pages/Transactions/Transaction.tsx
+++ b/src/pages/Transactions/Transaction.tsx
@@ -5,7 +5,7 @@ import { TxBroadcastEvent } from "polkadot-api"
import * as React from "react"
import { dismissTransaction, onGoingEvents } from "./transactions.state"
import { Trash2 } from "lucide-react"
-import { jsonSerialize } from "polkadot-api/utils"
+import { jsonPrint } from "@polkadot-api/utils"
export const Transaction: React.FC<{
event:
@@ -23,11 +23,7 @@ export const Transaction: React.FC<{
case "error":
return There was an unexpected error.
case "invalid":
- return (
-
- Invalid transaction. {JSON.stringify(event.value, jsonSerialize)}
-
- )
+ return Invalid transaction. {jsonPrint(event.value)}
case "txBestBlocksState": {
return event.found ? (
@@ -62,7 +58,7 @@ export const Transaction: React.FC<{
{event.ok
? "."
- : `, but it failed: ${JSON.stringify(event.dispatchError, jsonSerialize)}.`}
+ : `, but it failed: ${jsonPrint(event.dispatchError)}.`}
)
}
diff --git a/src/pages/Transactions/transactions.state.ts b/src/pages/Transactions/transactions.state.ts
index 19e84bf..8b81084 100644
--- a/src/pages/Transactions/transactions.state.ts
+++ b/src/pages/Transactions/transactions.state.ts
@@ -6,12 +6,13 @@ import {
mergeWithKey,
partitionByKey,
} from "@react-rxjs/utils"
-import { InvalidTxError } from "polkadot-api"
+import { HexString, InvalidTxError, TxBroadcastEvent } from "polkadot-api"
import {
catchError,
filter,
merge,
mergeMap,
+ Observable,
of,
skip,
takeUntil,
@@ -19,8 +20,8 @@ import {
withLatestFrom,
} from "rxjs"
-const [signedTx$, trackSignedTx] = createSignal()
-const [unsignedTx$, trackUnsignedTx] = createSignal()
+const [signedTx$, trackSignedTx] = createSignal()
+const [unsignedTx$, trackUnsignedTx] = createSignal()
export { trackSignedTx, trackUnsignedTx }
export const [dismissTransaction$, dismissTransaction] = createSignal()
@@ -28,8 +29,14 @@ export const [dismissTransaction$, dismissTransaction] = createSignal()
const transactions$ = mergeWithKey({ signedTx$, unsignedTx$ }).pipe(
withLatestFrom(chainClient$),
mergeMap(([tx, { client }]) => {
+ const submitAndWatch = client.submitAndWatch as (
+ tx: HexString,
+ at: string,
+ withSigned?: boolean,
+ ) => Observable
+
let txHash: string = ""
- return client.submitAndWatch(tx.payload, "finalized").pipe(
+ return submitAndWatch(tx.payload, "finalized", true).pipe(
tap((e) => {
txHash = e.txHash
}),
diff --git a/src/smoldot.ts b/src/smoldot.ts
new file mode 100644
index 0000000..e69de29
diff --git a/src/state/chains/chain.state.ts b/src/state/chains/chain.state.ts
index 595d348..bbbf1cc 100644
--- a/src/state/chains/chain.state.ts
+++ b/src/state/chains/chain.state.ts
@@ -1,4 +1,7 @@
-import { createChopsticksProvider } from "@/chopsticks/chopsticks"
+import {
+ chopsticksInstance$,
+ createChopsticksProvider,
+} from "@/chopsticks/chopsticks"
import { getHashParams, setHashParams } from "@/hashParams"
import { getDynamicBuilder, getLookupFn } from "@polkadot-api/metadata-builders"
import {
@@ -7,7 +10,7 @@ import {
unifyMetadata,
} from "@polkadot-api/substrate-bindings"
import { getExtrinsicDecoder } from "@polkadot-api/tx-utils"
-import { fromHex, toHex } from "polkadot-api/utils"
+import { fromHex, toHex } from "@polkadot-api/utils"
import { liftSuspense, sinkSuspense, state, SUSPENSE } from "@react-rxjs/core"
import { createSignal } from "@react-rxjs/utils"
import { get, update } from "idb-keyval"
@@ -72,6 +75,9 @@ console.log("You can enable JSON-RPC logs by calling `setRpcLogsEnabled(true)`")
;(window as any).setRpcLogsEnabled = setRpcLogsEnabled
export const getProvider = (source: ChainSource) => {
+ // TODO bug: provider is not getting disconnected
+ chopsticksInstance$.next(null)
+
const provider =
source.type === "websocket"
? source.withChopsticks
diff --git a/src/state/chains/chainspecs/kusama.ts b/src/state/chains/chainspecs/kusama.ts
index 89724b7..6dfef7d 100644
--- a/src/state/chains/chainspecs/kusama.ts
+++ b/src/state/chains/chainspecs/kusama.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/kusama"
+export { chainSpec } from "polkadot-api/chains/ksmcc3"
diff --git a/src/state/chains/chainspecs/kusama_asset_hub.ts b/src/state/chains/chainspecs/kusama_asset_hub.ts
index 806f2f8..4d52897 100644
--- a/src/state/chains/chainspecs/kusama_asset_hub.ts
+++ b/src/state/chains/chainspecs/kusama_asset_hub.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/kusama_asset_hub"
+export { chainSpec } from "polkadot-api/chains/ksmcc3_asset_hub"
diff --git a/src/state/chains/chainspecs/kusama_coretime.ts b/src/state/chains/chainspecs/kusama_coretime.ts
index 18d52fa..db6d7ad 100644
--- a/src/state/chains/chainspecs/kusama_coretime.ts
+++ b/src/state/chains/chainspecs/kusama_coretime.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/kusama_coretime"
+export { chainSpec } from "polkadot-api/chains/ksmcc3_coretime"
diff --git a/src/state/chains/chainspecs/kusama_encointer.ts b/src/state/chains/chainspecs/kusama_encointer.ts
index 2ec57f6..c70cc04 100644
--- a/src/state/chains/chainspecs/kusama_encointer.ts
+++ b/src/state/chains/chainspecs/kusama_encointer.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/kusama_encointer"
+export { chainSpec } from "polkadot-api/chains/ksmcc3_encointer"
diff --git a/src/state/chains/chainspecs/kusama_people.ts b/src/state/chains/chainspecs/kusama_people.ts
index 28cb23a..9cda110 100644
--- a/src/state/chains/chainspecs/kusama_people.ts
+++ b/src/state/chains/chainspecs/kusama_people.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/kusama_people"
+export { chainSpec } from "polkadot-api/chains/ksmcc3_people"
diff --git a/src/state/chains/chainspecs/westend.ts b/src/state/chains/chainspecs/westend.ts
index f747596..e15af60 100644
--- a/src/state/chains/chainspecs/westend.ts
+++ b/src/state/chains/chainspecs/westend.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/westend"
+export { chainSpec } from "polkadot-api/chains/westend2"
diff --git a/src/state/chains/chainspecs/westend_asset_hub.ts b/src/state/chains/chainspecs/westend_asset_hub.ts
index 393ec8b..c6ba4bf 100644
--- a/src/state/chains/chainspecs/westend_asset_hub.ts
+++ b/src/state/chains/chainspecs/westend_asset_hub.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/westend_asset_hub"
+export { chainSpec } from "polkadot-api/chains/westend2_asset_hub"
diff --git a/src/state/chains/chainspecs/westend_collectives.ts b/src/state/chains/chainspecs/westend_collectives.ts
index 1339f61..e3602e3 100644
--- a/src/state/chains/chainspecs/westend_collectives.ts
+++ b/src/state/chains/chainspecs/westend_collectives.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/westend_collectives"
+export { chainSpec } from "polkadot-api/chains/westend2_collectives"
diff --git a/src/state/chains/chainspecs/westend_people.ts b/src/state/chains/chainspecs/westend_people.ts
index 24a77df..5214c1a 100644
--- a/src/state/chains/chainspecs/westend_people.ts
+++ b/src/state/chains/chainspecs/westend_people.ts
@@ -1 +1 @@
-export { chainSpec } from "polkadot-api/chains/westend_people"
+export { chainSpec } from "polkadot-api/chains/westend2_people"
diff --git a/src/state/chains/smoldot.ts b/src/state/chains/smoldot.ts
index ffad31c..62e01f8 100644
--- a/src/state/chains/smoldot.ts
+++ b/src/state/chains/smoldot.ts
@@ -1,13 +1,14 @@
-import type { JsonRpcProvider } from "polkadot-api"
import { getSmProvider } from "polkadot-api/sm-provider"
+import { Chain } from "polkadot-api/smoldot"
import { startFromWorker } from "polkadot-api/smoldot/from-worker"
import SmWorker from "polkadot-api/smoldot/worker?worker"
+import type { JsonRpcProvider } from "polkadot-api/ws-provider/web"
const [dotChainSpec, ksmChainSpec, paseoChainSpec, westendChainSpec] = [
import("polkadot-api/chains/polkadot"),
- import("polkadot-api/chains/kusama"),
+ import("polkadot-api/chains/ksmcc3"),
import("polkadot-api/chains/paseo"),
- import("polkadot-api/chains/westend"),
+ import("polkadot-api/chains/westend2"),
].map((x) => x.then((y) => y.chainSpec))
const smoldot = startFromWorker(new SmWorker(), {
logCallback: (level, target, message) => {
@@ -19,12 +20,22 @@ const smoldot = startFromWorker(new SmWorker(), {
},
forbidWs: true,
})
-
-const relayChains: Record> = {
- polkadot: dotChainSpec,
- kusama: ksmChainSpec,
- paseo: paseoChainSpec,
- westend: westendChainSpec,
+const relayChains: Record<
+ string,
+ { chainSpec: Promise; chain: Promise | null }
+> = {
+ polkadot: { chainSpec: dotChainSpec, chain: null },
+ kusama: { chainSpec: ksmChainSpec, chain: null },
+ paseo: { chainSpec: paseoChainSpec, chain: null },
+ westend: { chainSpec: westendChainSpec, chain: null },
+}
+const getRelayChain = async (name: string) => {
+ if (!relayChains[name].chain) {
+ relayChains[name].chain = smoldot.addChain({
+ chainSpec: await relayChains[name].chainSpec,
+ })
+ }
+ return relayChains[name].chain
}
export interface SmoldotSource {
@@ -41,12 +52,11 @@ export async function createSmoldotSource(
relayChain?: string,
): Promise {
if (id in relayChains) {
- const chainSpec = await relayChains[id]
- return {
+ return relayChains[id].chainSpec.then((chainSpec) => ({
id,
type: "chainSpec",
value: { chainSpec },
- }
+ }))
}
const { chainSpec } = await import(`./chainspecs/${id}.ts`)
const parsed = JSON.parse(chainSpec)
@@ -61,15 +71,16 @@ export async function createSmoldotSource(
}
export function getSmoldotProvider(source: SmoldotSource): JsonRpcProvider {
- const chainFactory = () =>
- source.value.relayChain
- ? relayChains[source.value.relayChain].then(async (chainSpec) =>
- smoldot.addChain({
- chainSpec: source.value.chainSpec,
- potentialRelayChains: [await smoldot.addChain({ chainSpec })],
- }),
- )
- : smoldot.addChain({ chainSpec: source.value.chainSpec })
+ const chain = source.value.relayChain
+ ? getRelayChain(source.value.relayChain).then((chain) =>
+ smoldot.addChain({
+ chainSpec: source.value.chainSpec,
+ potentialRelayChains: [chain],
+ }),
+ )
+ : smoldot.addChain({
+ chainSpec: source.value.chainSpec,
+ })
- return getSmProvider(chainFactory)
+ return getSmProvider(chain)
}
diff --git a/src/state/chains/websocket.ts b/src/state/chains/websocket.ts
index 07e0d86..baac979 100644
--- a/src/state/chains/websocket.ts
+++ b/src/state/chains/websocket.ts
@@ -1,5 +1,5 @@
-import type { JsonRpcProvider } from "polkadot-api"
-import { getWsProvider } from "polkadot-api/ws"
+import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat"
+import { getWsProvider, JsonRpcProvider } from "polkadot-api/ws-provider"
export interface WebsocketSource {
type: "websocket"
@@ -17,5 +17,5 @@ export async function createWebsocketSource(
}
export function getWebsocketProvider(source: WebsocketSource): JsonRpcProvider {
- return getWsProvider(source.endpoint)
+ return withPolkadotSdkCompat(getWsProvider(source.endpoint))
}
diff --git a/src/state/identity.state.ts b/src/state/identity.state.ts
index cfe9d9f..49a14c1 100644
--- a/src/state/identity.state.ts
+++ b/src/state/identity.state.ts
@@ -9,7 +9,6 @@ import { state } from "@react-rxjs/core"
import { Binary, createClient, SS58String } from "polkadot-api"
import { catchError, from, of, tap } from "rxjs"
import { getProvider } from "./chains/chain.state"
-import { fromHex } from "polkadot-api/utils"
export interface Identity {
displayName: string
@@ -52,16 +51,14 @@ export const getAddressName = async (
if (!id) {
const sup = await typedApi.query.Identity.SuperOf.getValue(addr)
if (!sup) return null
- const supData = readIdentityData(sup[1])
- const subDisplay = supData && Binary.toText(supData)
+ const subDisplay = readIdentityData(sup[1])?.asText() || ""
if (!subDisplay) return null
subIdStr = ` (${subDisplay})`
id = await typedApi.query.Identity.IdentityOf.getValue(sup[0])
if (!id) return null
}
- const displayData = readIdentityData(id.info.display)
- const displayName = displayData && Binary.toText(displayData)
+ const displayName = readIdentityData(id.info.display)?.asText()
return displayName
? {
displayName: `${displayName}${subIdStr}`,
@@ -91,8 +88,9 @@ export const identity$ = state(
(address) => cache.getValue()[address] ?? null,
)
-const readIdentityData = (identityData: IdentityData): Uint8Array | null => {
+const readIdentityData = (identityData: IdentityData): Binary | null => {
if (identityData.type === "None" || identityData.type === "Raw0") return null
- if (identityData.type === "Raw1") return new Uint8Array(identityData.value)
- return fromHex(identityData.value)
+ if (identityData.type === "Raw1")
+ return Binary.fromBytes(new Uint8Array(identityData.value))
+ return identityData.value
}