diff --git a/.changeset/fluffy-pigs-hunt.md b/.changeset/fluffy-pigs-hunt.md new file mode 100644 index 000000000..a96086517 --- /dev/null +++ b/.changeset/fluffy-pigs-hunt.md @@ -0,0 +1,7 @@ +--- +"@substrate/light-client-extension-helpers": minor +"@substrate/wallet-template": patch +--- + +- Add `tx-helper` package to light client extension helpers +- Replace usage of internal tx-helper with added package in wallet-template diff --git a/packages/light-client-extension-helpers/README.md b/packages/light-client-extension-helpers/README.md index 550d41030..df85dd19b 100644 --- a/packages/light-client-extension-helpers/README.md +++ b/packages/light-client-extension-helpers/README.md @@ -208,3 +208,7 @@ supervise(client, { onError: console.error }) // Supervise the client client.supervise() ``` + +### tx-helper + +TODO: write usage guide diff --git a/packages/light-client-extension-helpers/package.json b/packages/light-client-extension-helpers/package.json index d82967eea..e3bbca2e7 100644 --- a/packages/light-client-extension-helpers/package.json +++ b/packages/light-client-extension-helpers/package.json @@ -13,6 +13,7 @@ "./extension-page": "./dist/extension-page/extension-page-helper.mjs", "./web-page": "./dist/web-page/web-page-helper.mjs", "./utils": "./dist/utils/index.mjs", + "./tx-helper": "./dist/tx-helper/index.mjs", "./known-chain-specs": "./dist/known-chain-specs/index.mjs", "./known-chain-specs/polkadot": "./dist/known-chain-specs/polkadot.mjs", "./known-chain-specs/ksmcc3": "./dist/known-chain-specs/ksmcc3.mjs", @@ -24,7 +25,7 @@ "dist" ], "scripts": { - "build": "tsc --noEmit && tsup-node src/background/background-helper.ts src/content-script/content-script-helper.ts src/extension-page/extension-page-helper.ts src/web-page/web-page-helper.ts src/known-chain-specs/index.ts src/known-chain-specs/polkadot.ts src/known-chain-specs/ksmcc3.ts src/known-chain-specs/westend2.ts src/known-chain-specs/rococo_v2_2.ts src/utils/index.ts src/smoldot/index.ts --clean --sourcemap --platform neutral --target=es2020 --format esm --dts", + "build": "tsc --noEmit && tsup-node src/background/background-helper.ts src/content-script/content-script-helper.ts src/extension-page/extension-page-helper.ts src/web-page/web-page-helper.ts src/known-chain-specs/index.ts src/known-chain-specs/polkadot.ts src/known-chain-specs/ksmcc3.ts src/known-chain-specs/westend2.ts src/known-chain-specs/rococo_v2_2.ts src/utils/index.ts src/smoldot/index.ts src/tx-helper/index.ts --clean --sourcemap --platform neutral --target=es2020 --format esm --dts", "dev": "pnpm build --watch", "lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"" }, @@ -34,16 +35,32 @@ "trailingComma": "all" }, "devDependencies": { + "@polkadot-api/json-rpc-provider": "~0.0.1", + "@polkadot-api/polkadot-signer": "~0.0.2", "@types/chrome": "^0.0.268" }, "peerDependencies": { + "@polkadot-api/json-rpc-provider": "~0.0", + "@polkadot-api/polkadot-signer": "~0.0", "smoldot": "2.x" }, + "peerDependenciesMeta": { + "@polkadot-api/json-rpc-provider": { + "optional": true + }, + "@polkadot-api/polkadot-signer": { + "optional": true + } + }, "dependencies": { - "@polkadot-api/observable-client": "^0.3.1", - "@polkadot-api/json-rpc-provider": "^0.0.1", + "@polkadot-api/codegen": "^0.6.0", "@polkadot-api/json-rpc-provider-proxy": "^0.1.0", + "@polkadot-api/metadata-builders": "^0.3.0", + "@polkadot-api/observable-client": "^0.3.1", + "@polkadot-api/signer": "~0.0.2", + "@polkadot-api/substrate-bindings": "^0.6.0", "@polkadot-api/substrate-client": "^0.1.4", + "@polkadot-api/utils": "^0.1.0", "@substrate/connect-extension-protocol": "workspace:^", "@substrate/connect-known-chains": "workspace:^", "rxjs": "^7.8.1" diff --git a/packages/light-client-extension-helpers/src/tx-helper/index.ts b/packages/light-client-extension-helpers/src/tx-helper/index.ts new file mode 100644 index 000000000..518a07e48 --- /dev/null +++ b/packages/light-client-extension-helpers/src/tx-helper/index.ts @@ -0,0 +1,76 @@ +import { getObservableClient } from "@polkadot-api/observable-client" +import { createClient } from "@polkadot-api/substrate-client" +import { CreateTxOptions, JsonRpcProvider } from "./types" +import { filter, firstValueFrom, map, mergeMap, take } from "rxjs" +import * as polkadotAPI from "./polkadot-api" + +type UserSignedExtensions = { + CheckMortality?: + | { + mortal: false + } + | { + mortal: true + period: number + } + ChargeTransactionPayment: bigint + ChargeAssetTxPayment: { + tip: bigint + asset?: Uint8Array + } +} + +type UserSignedExtensionName = keyof UserSignedExtensions + +const isUserSignedExtensionName = (s: string): s is UserSignedExtensionName => { + return ( + s === "CheckMortality" || + s === "ChargeTransactionPayment" || + s === "ChargeAssetTxPayment" + ) +} + +export const createTx = + (jsonRpcProvider: JsonRpcProvider) => + async (options: CreateTxOptions): Promise => { + const client = getObservableClient(createClient(jsonRpcProvider)) + const chainHead$ = client.chainHead$() + + const { best: atBlock } = await firstValueFrom( + chainHead$.best$.pipe( + mergeMap((blockInfo) => + chainHead$.getRuntimeContext$(blockInfo.hash).pipe( + take(1), + map(({ metadata }) => + metadata.extrinsic.signedExtensions + .map(({ identifier }) => identifier) + .filter(isUserSignedExtensionName), + ), + map((userSignedExtensionNames) => ({ + best: blockInfo, + userSignedExtensionNames, + })), + ), + ), + filter(Boolean), + ), + ) + + const tx = await firstValueFrom( + polkadotAPI + .createTx( + chainHead$, + options.signer, + options.callData, + atBlock, + options.hinted, + ) + .pipe(filter(Boolean)), + ) + + client.destroy() + + return tx + } + +export type * from "./types" diff --git a/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/index.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/index.ts new file mode 100644 index 000000000..6138fb10f --- /dev/null +++ b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/index.ts @@ -0,0 +1 @@ +export { createTx } from "./tx-helper/create-tx" diff --git a/projects/wallet-template/src/background/tx-helper/README.md b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/README.md similarity index 100% rename from projects/wallet-template/src/background/tx-helper/README.md rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/README.md diff --git a/projects/wallet-template/src/background/tx-helper/create-tx.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/create-tx.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/create-tx.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/create-tx.ts diff --git a/projects/wallet-template/src/background/tx-helper/descriptors.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/descriptors.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/descriptors.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/descriptors.ts diff --git a/projects/wallet-template/src/background/tx-helper/index.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/index.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/index.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/index.ts diff --git a/projects/wallet-template/src/background/tx-helper/runtime.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/runtime.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/runtime.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/runtime.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckGenesis.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckGenesis.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckGenesis.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckGenesis.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckMetadataHash.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckMetadataHash.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckMetadataHash.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckMetadataHash.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckNonce.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckNonce.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckNonce.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckNonce.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckSpecVersion.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckSpecVersion.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckSpecVersion.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckSpecVersion.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckTxVersion.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckTxVersion.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/chain/CheckTxVersion.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/CheckTxVersion.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/chain/index.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/index.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/chain/index.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/chain/index.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/index.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/index.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/index.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/index.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/internal-types.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/internal-types.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/internal-types.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/internal-types.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/user/ChargeAssetTxPayment.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/ChargeAssetTxPayment.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/user/ChargeAssetTxPayment.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/ChargeAssetTxPayment.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/user/ChargeTransactionPayment.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/ChargeTransactionPayment.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/user/ChargeTransactionPayment.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/ChargeTransactionPayment.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/user/CheckMortality.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/CheckMortality.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/user/CheckMortality.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/CheckMortality.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/user/index.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/index.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/user/index.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/user/index.ts diff --git a/projects/wallet-template/src/background/tx-helper/signed-extensions/utils.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/utils.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/signed-extensions/utils.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/signed-extensions/utils.ts diff --git a/projects/wallet-template/src/background/tx-helper/submit-fns.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/submit-fns.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/submit-fns.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/submit-fns.ts diff --git a/projects/wallet-template/src/background/tx-helper/tx.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/tx.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/tx.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/tx.ts diff --git a/projects/wallet-template/src/background/tx-helper/types.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/types.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/types.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/types.ts diff --git a/projects/wallet-template/src/background/tx-helper/utils/continue-with.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/utils/continue-with.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/utils/continue-with.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/utils/continue-with.ts diff --git a/projects/wallet-template/src/background/tx-helper/utils/index.ts b/packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/utils/index.ts similarity index 100% rename from projects/wallet-template/src/background/tx-helper/utils/index.ts rename to packages/light-client-extension-helpers/src/tx-helper/polkadot-api/tx-helper/utils/index.ts diff --git a/packages/light-client-extension-helpers/src/tx-helper/types.ts b/packages/light-client-extension-helpers/src/tx-helper/types.ts new file mode 100644 index 000000000..a785fa9ba --- /dev/null +++ b/packages/light-client-extension-helpers/src/tx-helper/types.ts @@ -0,0 +1,17 @@ +import type { JsonRpcProvider } from "@polkadot-api/json-rpc-provider" +import type { PolkadotSigner } from "@polkadot-api/polkadot-signer" + +export type HintedSignedExtensions = Partial<{ + readonly tip: bigint + readonly mortality: { mortal: false } | { mortal: true; period: number } + readonly asset: Uint8Array + readonly nonce: number +}> + +export type CreateTxOptions = { + readonly signer: PolkadotSigner + readonly callData: Uint8Array + readonly hinted?: HintedSignedExtensions +} + +export type { JsonRpcProvider, PolkadotSigner } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42e150ba8..3e6ecf574 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -301,18 +301,30 @@ importers: packages/light-client-extension-helpers: dependencies: - '@polkadot-api/json-rpc-provider': - specifier: ^0.0.1 - version: 0.0.1 + '@polkadot-api/codegen': + specifier: ^0.6.0 + version: 0.6.1 '@polkadot-api/json-rpc-provider-proxy': specifier: ^0.1.0 version: 0.1.0 + '@polkadot-api/metadata-builders': + specifier: ^0.3.0 + version: 0.3.1 '@polkadot-api/observable-client': specifier: ^0.3.1 version: 0.3.1(@polkadot-api/substrate-client@0.1.4)(rxjs@7.8.1) + '@polkadot-api/signer': + specifier: ~0.0.2 + version: 0.0.2 + '@polkadot-api/substrate-bindings': + specifier: ^0.6.0 + version: 0.6.0 '@polkadot-api/substrate-client': specifier: ^0.1.4 version: 0.1.4 + '@polkadot-api/utils': + specifier: ^0.1.0 + version: 0.1.0 '@substrate/connect-extension-protocol': specifier: workspace:^ version: link:../connect-extension-protocol @@ -326,6 +338,12 @@ importers: specifier: 2.0.29 version: 2.0.29 devDependencies: + '@polkadot-api/json-rpc-provider': + specifier: ~0.0.1 + version: 0.0.1 + '@polkadot-api/polkadot-signer': + specifier: ~0.0.2 + version: 0.0.2 '@types/chrome': specifier: ^0.0.268 version: 0.0.268 @@ -544,11 +562,11 @@ importers: specifier: ^0.3.1 version: 0.3.1(@polkadot-api/substrate-client@0.1.4)(rxjs@7.8.1) '@polkadot-api/polkadot-signer': - specifier: ^0.0.1 - version: 0.0.1 + specifier: ~0.0.2 + version: 0.0.2 '@polkadot-api/signer': - specifier: ^0.0.1 - version: 0.0.1 + specifier: ~0.0.2 + version: 0.0.2 '@polkadot-api/substrate-bindings': specifier: ^0.6.0 version: 0.6.0 @@ -3616,7 +3634,6 @@ packages: /@noble/hashes@1.4.0: resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==} engines: {node: '>= 16'} - dev: false /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} @@ -3754,13 +3771,6 @@ packages: '@polkadot-api/json-rpc-provider-proxy': 0.0.1 dev: false - /@polkadot-api/metadata-builders@0.0.1: - resolution: {integrity: sha512-GCI78BHDzXAF/L2pZD6Aod/yl82adqQ7ftNmKg51ixRL02JpWUA+SpUKTJE5MY1p8kiJJIo09P2um24SiJHxNA==} - dependencies: - '@polkadot-api/substrate-bindings': 0.0.1 - '@polkadot-api/utils': 0.0.1 - dev: false - /@polkadot-api/metadata-builders@0.3.0: resolution: {integrity: sha512-WUxKGy2hzClESEcQWnnDp4IzlYiEXmYgSaa08zW1J3uX7rmLADDeKkfRH9TNRLAMEr9TaFt71W+OzHJtdwR6bw==} dependencies: @@ -3773,7 +3783,6 @@ packages: dependencies: '@polkadot-api/substrate-bindings': 0.6.0 '@polkadot-api/utils': 0.1.0 - dev: false /@polkadot-api/observable-client@0.3.1(@polkadot-api/substrate-client@0.1.4)(rxjs@7.8.1): resolution: {integrity: sha512-ioun8PfDwmr2nRCIFPS3X7qMaJxeyotHT8vep0VNVYU13dUIBojaHQCpe9l4jN8MXoG63h1wAVT9dshGSiTDQw==} @@ -3797,29 +3806,12 @@ packages: '@polkadot-api/utils': 0.1.0 dev: false - /@polkadot-api/polkadot-signer@0.0.1: - resolution: {integrity: sha512-A1axSuurYG3FtM9xY6v/rM4VXoDnk8PqW+Q1+innUcR7kmAIMWZw21uUxF0Iwzu29hKHCHucSF9YJZ1yAP7JNw==} - dependencies: - '@polkadot-api/metadata-builders': 0.0.1 - '@polkadot-api/substrate-bindings': 0.0.1 - '@polkadot-api/utils': 0.0.1 - dev: false - /@polkadot-api/polkadot-signer@0.0.2: resolution: {integrity: sha512-CZzepV/Xtorsv9iFxQio5Hm8ETdX9chYPtrwscjSytqomAN5V1FsxaVrqBfRWqrf3JkfXKmLKBqTCp4oyrE0rQ==} dependencies: '@polkadot-api/metadata-builders': 0.3.1 '@polkadot-api/substrate-bindings': 0.6.0 '@polkadot-api/utils': 0.1.0 - dev: false - - /@polkadot-api/signer@0.0.1: - resolution: {integrity: sha512-TZHGlVKf1TR2IWcSDMPJBAl/Lsp0z5vGGQr4xSwIwVVvuJw60+d2EfpnUltCTSqE9hMRaoBLl6P+dQbxdkPg4Q==} - dependencies: - '@polkadot-api/polkadot-signer': 0.0.1 - '@polkadot-api/substrate-bindings': 0.0.1 - '@polkadot-api/utils': 0.0.1 - dev: false /@polkadot-api/signer@0.0.2: resolution: {integrity: sha512-nWpzsU8KA27jrS1G6gV3yK4s9LxOsHbySFr3GpCQT0Iz61VHPQ9YLqnkR+J4I7myrHijiRchbMlN/iF08EbAQQ==} @@ -3848,15 +3840,6 @@ packages: - utf-8-validate dev: false - /@polkadot-api/substrate-bindings@0.0.1: - resolution: {integrity: sha512-bAe7a5bOPnuFVmpv7y4BBMRpNTnMmE0jtTqRUw/+D8ZlEHNVEJQGr4wu3QQCl7k1GnSV1wfv3mzIbYjErEBocg==} - dependencies: - '@noble/hashes': 1.4.0 - '@polkadot-api/utils': 0.0.1 - '@scure/base': 1.1.6 - scale-ts: 1.6.0 - dev: false - /@polkadot-api/substrate-bindings@0.4.0: resolution: {integrity: sha512-7eaZABXpUp22W5GcXr51pNL4v1d8Pw8w92DbKwWs+eOGzcoZG/btEyUhPWy2OI2k7Oak3wTkvGXLSze1KyrPgQ==} dependencies: @@ -3882,7 +3865,6 @@ packages: '@polkadot-api/utils': 0.1.0 '@scure/base': 1.1.6 scale-ts: 1.6.0 - dev: false /@polkadot-api/substrate-client@0.1.4: resolution: {integrity: sha512-MljrPobN0ZWTpn++da9vOvt+Ex+NlqTlr/XT7zi9sqPtDJiQcYl+d29hFAgpaeTqbeQKZwz3WDE9xcEfLE8c5A==} @@ -6486,7 +6468,6 @@ packages: /@scure/base@1.1.6: resolution: {integrity: sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==} - dev: false /@sinclair/typebox@0.27.8: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} @@ -13884,7 +13865,6 @@ packages: /scale-ts@1.6.0: resolution: {integrity: sha512-Ja5VCjNZR8TGKhUumy9clVVxcDpM+YFjAnkMuwQy68Hixio3VRRvWdE3g8T/yC+HXA0ZDQl2TGyUmtmbcVl40Q==} - dev: false /scheduler@0.23.2: resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} diff --git a/projects/wallet-template/package.json b/projects/wallet-template/package.json index 6535e4034..2c4cd0c37 100644 --- a/projects/wallet-template/package.json +++ b/projects/wallet-template/package.json @@ -61,8 +61,8 @@ "@polkadot-api/json-rpc-provider": "^0.0.1", "@polkadot-api/metadata-builders": "^0.3.0", "@polkadot-api/observable-client": "^0.3.1", - "@polkadot-api/polkadot-signer": "^0.0.1", - "@polkadot-api/signer": "^0.0.1", + "@polkadot-api/polkadot-signer": "~0.0.2", + "@polkadot-api/signer": "~0.0.2", "@polkadot-api/substrate-bindings": "^0.6.0", "@polkadot-api/substrate-client": "^0.1.4", "@polkadot-api/utils": "^0.1.0", diff --git a/projects/wallet-template/src/background/createBackgroundRpc.ts b/projects/wallet-template/src/background/createBackgroundRpc.ts index 52ef2ebbf..0299209e1 100644 --- a/projects/wallet-template/src/background/createBackgroundRpc.ts +++ b/projects/wallet-template/src/background/createBackgroundRpc.ts @@ -5,6 +5,7 @@ import { createRpc, RpcError, } from "@substrate/light-client-extension-helpers/utils" +import { createTx } from "@substrate/light-client-extension-helpers/tx-helper" import { ss58Address, ss58Decode } from "@polkadot-labs/hdkd-helpers" import { toHex, fromHex } from "@polkadot-api/utils" import { getPolkadotSigner } from "@polkadot-api/signer" @@ -15,7 +16,6 @@ import { UserSignedExtensionName } from "../types/UserSignedExtension" import { createClient } from "@polkadot-api/substrate-client" import { getObservableClient } from "@polkadot-api/observable-client" import { filter, firstValueFrom, map, mergeMap, take } from "rxjs" -import { createTx } from "./tx-helper/create-tx" import * as pjs from "./pjs" import { Bytes, Variant } from "@polkadot-api/substrate-bindings" import { InPageRpcSpec } from "../inpage/types" @@ -86,7 +86,7 @@ export const createBackgroundRpc = ( const client = getObservableClient(createClient(chain.provider)) const chainHead$ = client.chainHead$() - const { best: atBlock, userSignedExtensionNames } = await firstValueFrom( + const userSignedExtensionNames = await firstValueFrom( chainHead$.best$.pipe( mergeMap((blockInfo) => chainHead$.getRuntimeContext$(blockInfo.hash).pipe( @@ -96,10 +96,6 @@ export const createBackgroundRpc = ( .map(({ identifier }) => identifier) .filter(isUserSignedExtensionName), ), - map((userSignedExtensionNames) => ({ - best: blockInfo, - userSignedExtensionNames, - })), ), ), filter(Boolean), @@ -166,13 +162,15 @@ export const createBackgroundRpc = ( ? userSignedExtensions.ChargeAssetTxPayment?.tip : userSignedExtensions.ChargeTransactionPayment) ?? 0n - const tx = await firstValueFrom( - createTx(chainHead$, signer, fromHex(callData), atBlock, { + const tx = await createTx(chain.provider)({ + signer, + callData: fromHex(callData), + hinted: { mortality, asset, tip, - }).pipe(filter(Boolean)), - ) + }, + }) return toHex(tx) } finally {