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