From bffb85ff0b226fb58ae0e197ad25ba34c2bb5037 Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Mon, 10 Jun 2024 16:10:31 +0200 Subject: [PATCH 1/6] fix(spaceward): use BigInt instead of Long --- spaceward/package.json | 1 - spaceward/pnpm-lock.yaml | 4 --- spaceward/src/components/SendEth.tsx | 3 +- spaceward/src/features/assets/Assets.tsx | 15 ++++------ spaceward/src/features/home/HomeAssets.tsx | 12 ++++---- .../src/features/home/TotalAssetValue.tsx | 5 ++-- spaceward/src/features/keys/Keys.tsx | 6 ++-- .../features/metamask/AddToMetaMaskButton.tsx | 3 +- .../features/metamask/MetaMaskRequests.tsx | 17 +++++------ .../src/features/spaces/SpaceSelector.tsx | 30 +++++++++---------- .../features/walletconnect/WalletConnect.tsx | 5 ++-- 11 files changed, 40 insertions(+), 61 deletions(-) diff --git a/spaceward/package.json b/spaceward/package.json index 65536d623..213b66604 100644 --- a/spaceward/package.json +++ b/spaceward/package.json @@ -79,7 +79,6 @@ "html5-qrcode": "^2.3.8", "js-sha256": "^0.10.1", "localforage": "^1.10.0", - "long": "^5.2.3", "lucide-react": "^0.368.0", "match-sorter": "^6.3.1", "next": "^14.1.0", diff --git a/spaceward/pnpm-lock.yaml b/spaceward/pnpm-lock.yaml index d6c95432a..6aa4af750 100644 --- a/spaceward/pnpm-lock.yaml +++ b/spaceward/pnpm-lock.yaml @@ -219,9 +219,6 @@ importers: localforage: specifier: ^1.10.0 version: 1.10.0 - long: - specifier: ^5.2.3 - version: 5.2.3 lucide-react: specifier: ^0.368.0 version: 0.368.0(react@18.2.0) @@ -11489,7 +11486,6 @@ snapshots: '@cosmjs/tendermint-rpc': 0.32.3(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@cosmology/lcd': 0.13.3 '@tanstack/react-query': 4.36.1(react-dom@18.2.0(react@18.2.0))(react@18.2.0) - long: 5.2.3 protobufjs: 7.2.6 transitivePeerDependencies: - bufferutil diff --git a/spaceward/src/components/SendEth.tsx b/spaceward/src/components/SendEth.tsx index 362c563d1..4f45ce522 100644 --- a/spaceward/src/components/SendEth.tsx +++ b/spaceward/src/components/SendEth.tsx @@ -1,4 +1,3 @@ -import Long from "long"; import { useQuery } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { ethers } from "ethers"; @@ -51,7 +50,7 @@ function SendEth() { const q = useKeyById({ request: { - id: Long.fromString(keyId), + id: BigInt(keyId), deriveAddresses: [AddressType.ADDRESS_TYPE_ETHEREUM], }, options: { diff --git a/spaceward/src/features/assets/Assets.tsx b/spaceward/src/features/assets/Assets.tsx index e2f5640e6..935f4f782 100644 --- a/spaceward/src/features/assets/Assets.tsx +++ b/spaceward/src/features/assets/Assets.tsx @@ -1,5 +1,3 @@ -import React from "react"; -import Long from "long"; import { Skeleton } from "@/components/ui/skeleton"; import AddressAvatar from "@/components/AddressAvatar"; import { ethers } from "ethers"; @@ -14,7 +12,6 @@ import { Copy } from "@/components/ui/copy"; import { NewKeyButton } from "@/features/keys"; import { useQueryHooks } from "@/hooks/useClient"; import { PageRequest } from "@wardenprotocol/wardenjs/codegen/cosmos/base/query/v1beta1/pagination"; -import { base64FromBytes } from "@wardenprotocol/wardenjs/codegen/helpers"; import { AddressType } from "@wardenprotocol/wardenjs/codegen/warden/warden/v1beta2/key"; import { getProvider } from "@/lib/eth"; @@ -42,13 +39,13 @@ export function Assets({ spaceId }: { spaceId: string }) { const { useKeysBySpaceId, isReady } = useQueryHooks(); const query = useKeysBySpaceId({ request: { - spaceId: Long.fromString(spaceId), + spaceId: BigInt(spaceId), deriveAddresses: [ AddressType.ADDRESS_TYPE_ETHEREUM, AddressType.ADDRESS_TYPE_OSMOSIS, ], pagination: PageRequest.fromPartial({ - limit: Long.fromInt(10), + limit: BigInt(10), }), }, options: { @@ -78,7 +75,7 @@ export function Assets({ spaceId }: { spaceId: string }) { {query.data?.keys?.map((key) => (
@@ -88,7 +85,7 @@ export function Assets({ spaceId }: { spaceId: string }) { - Key #{key.key.id.toNumber()} + Key #{key.key.id.toString()}
@@ -120,7 +117,7 @@ function Address({ }: { address: string; type: AddressType; - keyId: Long; + keyId: bigint; }) { if (type !== AddressType.ADDRESS_TYPE_ETHEREUM) { return null; @@ -165,7 +162,7 @@ function Address({ ); } -function Sepolia({ address, keyId }: { address: string; keyId: Long }) { +function Sepolia({ address, keyId }: { address: string; keyId: bigint }) { const { currency } = useCurrency(); const query = useQuery({ queryKey: ["eth-balance", address], diff --git a/spaceward/src/features/home/HomeAssets.tsx b/spaceward/src/features/home/HomeAssets.tsx index 6874316eb..1fc5bf775 100644 --- a/spaceward/src/features/home/HomeAssets.tsx +++ b/spaceward/src/features/home/HomeAssets.tsx @@ -1,5 +1,3 @@ -import React from "react"; -import Long from "long"; import { Skeleton } from "@/components/ui/skeleton"; import AddressAvatar from "@/components/AddressAvatar"; import { ethers } from "ethers"; @@ -28,13 +26,13 @@ export function HomeAssets() { const { useKeysBySpaceId, isReady } = useQueryHooks(); const query = useKeysBySpaceId({ request: { - spaceId: Long.fromString(spaceId || ""), + spaceId: BigInt(spaceId || ""), deriveAddresses: [ AddressType.ADDRESS_TYPE_ETHEREUM, AddressType.ADDRESS_TYPE_OSMOSIS, ], pagination: PageRequest.fromPartial({ - limit: Long.fromInt(10), + limit: BigInt(10), }), }, options: { @@ -68,7 +66,7 @@ export function HomeAssets() { {query.data?.keys?.map((key) => (
@@ -100,7 +98,7 @@ function Address({ }: { address: string; type: AddressType; - keyId: Long; + keyId: bigint; }) { // if (type != AddressType.ADDRESS_TYPE_ETHEREUM) { // return null; @@ -139,7 +137,7 @@ function Address({ ); } -function Sepolia({ address, keyId }: { address: string; keyId: Long }) { +function Sepolia({ address, keyId }: { address: string; keyId: bigint }) { const query = useQuery({ queryKey: ["eth-balance", address], queryFn: () => getEthBalance(address), diff --git a/spaceward/src/features/home/TotalAssetValue.tsx b/spaceward/src/features/home/TotalAssetValue.tsx index 5770c3114..ef111cccf 100644 --- a/spaceward/src/features/home/TotalAssetValue.tsx +++ b/spaceward/src/features/home/TotalAssetValue.tsx @@ -1,4 +1,3 @@ -import Long from "long"; import { formatEther } from "ethers"; import { useSpaceId } from "@/hooks/useSpaceId"; import { useCurrency } from "@/hooks/useCurrency"; @@ -37,10 +36,10 @@ export function TotalAssetValue() { const { useKeysBySpaceId, isReady } = useQueryHooks(); const keysQ = useKeysBySpaceId({ request: { - spaceId: Long.fromString(spaceId || ""), + spaceId: BigInt(spaceId || ""), deriveAddresses: [AddressType.ADDRESS_TYPE_ETHEREUM], pagination: PageRequest.fromPartial({ - limit: Long.fromInt(10), + limit: BigInt(10), }), }, options: { diff --git a/spaceward/src/features/keys/Keys.tsx b/spaceward/src/features/keys/Keys.tsx index 8f1a85159..6d9f12d52 100644 --- a/spaceward/src/features/keys/Keys.tsx +++ b/spaceward/src/features/keys/Keys.tsx @@ -1,4 +1,3 @@ -import Long from "long"; import { prettyKeyType } from "@/utils/formatting"; import { Link } from "react-router-dom"; import { Button } from "@/components/ui/button"; @@ -9,7 +8,6 @@ import { AccordionTrigger, } from "@/components/ui/accordion"; import AddressAvatar from "@/components/AddressAvatar"; -import { Avatar, AvatarImage } from "@/components/ui/avatar"; import { Copy } from "@/components/ui/copy"; import { ReceiveAssetButton } from "@/features/assets"; import { MoveUpRight, KeyIcon } from "lucide-react"; @@ -28,13 +26,13 @@ export function Keys({ spaceId }: { spaceId: string }) { const { useKeysBySpaceId, isReady } = useQueryHooks(); const query = useKeysBySpaceId({ request: { - spaceId: Long.fromString(spaceId), + spaceId: BigInt(spaceId), deriveAddresses: [ AddressType.ADDRESS_TYPE_ETHEREUM, AddressType.ADDRESS_TYPE_OSMOSIS, ], pagination: PageRequest.fromPartial({ - limit: Long.fromInt(10), + limit: BigInt(10), }), }, options: { diff --git a/spaceward/src/features/metamask/AddToMetaMaskButton.tsx b/spaceward/src/features/metamask/AddToMetaMaskButton.tsx index 6564835b5..d03bc1013 100644 --- a/spaceward/src/features/metamask/AddToMetaMaskButton.tsx +++ b/spaceward/src/features/metamask/AddToMetaMaskButton.tsx @@ -1,4 +1,3 @@ -import Long from "long"; import { isLocalSnap } from "@/lib/metamask"; import { Button } from "@/components/ui/button"; import { useMetaMask } from "@/hooks/useMetaMask"; @@ -12,7 +11,7 @@ export function AddToMetaMaskButton({ keyId, address, }: { - keyId: Long; + keyId: bigint; address: string; }) { const { isFlask, snapsDetected, installedSnap } = useMetaMask(); diff --git a/spaceward/src/features/metamask/MetaMaskRequests.tsx b/spaceward/src/features/metamask/MetaMaskRequests.tsx index c59917957..452deefea 100644 --- a/spaceward/src/features/metamask/MetaMaskRequests.tsx +++ b/spaceward/src/features/metamask/MetaMaskRequests.tsx @@ -1,5 +1,4 @@ import { useState } from "react"; -import Long from "long"; import * as Popover from "@radix-ui/react-popover"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; @@ -21,7 +20,7 @@ import { import { useMetaMask } from "@/hooks/useMetaMask"; import { useEthereumTx } from "@/hooks/useEthereumTx"; -async function buildSignTransaction(data: { +interface SignTransactionParams { chainId: string; data: string; from: string; @@ -32,7 +31,9 @@ async function buildSignTransaction(data: { to: string; type: string; value: string; -}) { +} + +async function buildSignTransaction(data: SignTransactionParams) { return ethers.Transaction.from({ chainId: data.chainId, data: data.data, @@ -91,11 +92,7 @@ export function MetaMaskRequests() { const handleApproveRequest = async (req: KeyringRequest) => { const account = await keyringSnapClient.getAccount(req.account); - const keyIdInt = parseInt(account.options.keyId?.valueOf() as string, 10); - if (!keyIdInt || isNaN(keyIdInt)) { - throw new Error("Account has no keyId"); - } - const keyId = Long.fromNumber(keyIdInt); + const keyId = BigInt(account.options.keyId?.valueOf() as string); switch (req.request.method) { case "personal_sign": { @@ -130,7 +127,7 @@ export function MetaMaskRequests() { ) { throw new Error("wrong params length"); } - const txParam = req.request.params[0]?.valueOf() as any; + const txParam = req.request.params[0]?.valueOf() as SignTransactionParams; const tx = await buildSignTransaction(txParam); const signedTx = await signEthereumTx(keyId, tx); if (!signedTx || !signedTx.signature) { @@ -157,7 +154,7 @@ export function MetaMaskRequests() { throw new Error("wrong params length"); } const data = - req.request.params[1]?.valueOf() as TypedMessage; + req.request.params[1]?.valueOf() as TypedMessage; const toSign = TypedDataUtils.eip712Hash( data, SignTypedDataVersion.V4, diff --git a/spaceward/src/features/spaces/SpaceSelector.tsx b/spaceward/src/features/spaces/SpaceSelector.tsx index ccadbb9e1..6e81e7eb9 100644 --- a/spaceward/src/features/spaces/SpaceSelector.tsx +++ b/spaceward/src/features/spaces/SpaceSelector.tsx @@ -1,4 +1,3 @@ -import Long from "long"; import { Button } from "@/components/ui/button"; import { ChevronsUpDown } from "lucide-react"; import { @@ -11,7 +10,6 @@ import { useAddressContext } from "@/hooks/useAddressContext"; import useWardenWardenV1Beta2 from "@/hooks/useWardenWardenV1Beta2"; import { useSpaceId } from "@/hooks/useSpaceId"; import { useTx } from "@/hooks/useClient"; -import { useToast } from "@/components/ui/use-toast"; import cn from "clsx"; import { Plus } from "lucide-react"; import { useMediaQuery } from "@uidotdev/usehooks"; @@ -20,17 +18,17 @@ import { warden } from "@wardenprotocol/wardenjs"; interface SpacesQueryResult { pageParam: number; pagination?: - | { next_key?: string | undefined; total?: string | undefined } - | undefined; + | { next_key?: string | undefined; total?: string | undefined } + | undefined; spaces?: - | { - id?: string | undefined; - creator?: string | undefined; - owners?: string[] | undefined; - admin_intent_id?: string | undefined; - sign_intent_id?: string | undefined; - }[] - | undefined; + | { + id?: string | undefined; + creator?: string | undefined; + owners?: string[] | undefined; + admin_intent_id?: string | undefined; + sign_intent_id?: string | undefined; + }[] + | undefined; } export function SpaceSelector() { @@ -45,8 +43,8 @@ export function SpaceSelector() { [ newSpace({ creator: address, - signIntentId: Long.fromNumber(0), - adminIntentId: Long.fromNumber(0), + signIntentId: BigInt(0), + adminIntentId: BigInt(0), // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore: telescope generated code doesn't handle empty array correctly, use `undefined` instead of `[]` additionalOwners: undefined, @@ -110,8 +108,8 @@ export function SpaceSelector() {
{( (spacesQuery as any)?.pages[0] as - | SpacesQueryResult - | undefined + | SpacesQueryResult + | undefined )?.spaces?.map((space) => (
({ @@ -272,7 +271,7 @@ async function findKeyByAddress(spaceId: string, address: string) { const client = await getClient(); const queryKeys = client.warden.warden.v1beta2.keysBySpaceId; const res = await queryKeys({ - spaceId: Long.fromString(spaceId), + spaceId: BigInt(spaceId), deriveAddresses: [ AddressType.ADDRESS_TYPE_ETHEREUM, AddressType.ADDRESS_TYPE_OSMOSIS, From 030d73659c632ee183462206cf629f82d7d004ae Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Mon, 10 Jun 2024 16:10:50 +0200 Subject: [PATCH 2/6] fix(spaceward): remove unused eslint storybook plugin --- spaceward/.eslintrc.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spaceward/.eslintrc.cjs b/spaceward/.eslintrc.cjs index 4b7b5a44c..83c4584e7 100644 --- a/spaceward/.eslintrc.cjs +++ b/spaceward/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { env: { browser: true, es2020: true }, - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended', 'plugin:storybook/recommended'], + extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended'], parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, plugins: ['react-refresh'], From 14c97c3e8cf9723d008ba0895492d5f93e4a0b25 Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Mon, 10 Jun 2024 16:11:23 +0200 Subject: [PATCH 3/6] fix(spaceward): implement React Query queryHashFn that supports BigInts --- spaceward/src/App.tsx | 2 + spaceward/src/utils/queryKeyHash.ts | 72 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 spaceward/src/utils/queryKeyHash.ts diff --git a/spaceward/src/App.tsx b/spaceward/src/App.tsx index 683e0adb6..d95e45555 100644 --- a/spaceward/src/App.tsx +++ b/spaceward/src/App.tsx @@ -53,11 +53,13 @@ import { StakingPage, } from "./pages"; import { GovernancePage } from "./pages/Governance.tsx"; +import { hashQueryKey } from "./utils/queryKeyHash.ts"; const queryClient = new QueryClient({ defaultOptions: { queries: { refetchInterval: 1000, + queryKeyHashFn: hashQueryKey, }, }, }); diff --git a/spaceward/src/utils/queryKeyHash.ts b/spaceward/src/utils/queryKeyHash.ts new file mode 100644 index 000000000..2e655e059 --- /dev/null +++ b/spaceward/src/utils/queryKeyHash.ts @@ -0,0 +1,72 @@ +export type QueryKey = string | readonly unknown[] +export type EnsuredQueryKey = T extends string + ? [T] + : Exclude + +export function hashQueryKey(queryKey: QueryKey): string { + const asArray = ensureQueryKeyArray(queryKey) + return stableValueHash(asArray) +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function stableValueHash(value: any): string { + return JSON.stringify(value, (_, val) => + isBigInt(val) + ? val.toString() + : isPlainObject(val) + ? Object.keys(val) + .sort() + .reduce((result, key) => { + result[key] = val[key] + return result + // eslint-disable-next-line @typescript-eslint/no-explicit-any + }, {} as any) + : val + ) +} + +function isBigInt(value: unknown): value is bigint { + return typeof value === 'bigint' +} + +export function ensureQueryKeyArray( + value: T +): EnsuredQueryKey { + return (Array.isArray(value) + ? value + : ([value] as unknown)) as EnsuredQueryKey +} + +// Copied from: https://github.com/jonschlinkert/is-plain-object +// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types +export function isPlainObject(o: any): o is Object { + if (!hasObjectPrototype(o)) { + return false + } + + // If has modified constructor + const ctor = o.constructor + if (typeof ctor === 'undefined') { + return true + } + + // If has modified prototype + const prot = ctor.prototype + if (!hasObjectPrototype(prot)) { + return false + } + + // If constructor does not have an Object-specific method + // eslint-disable-next-line no-prototype-builtins + if (!prot.hasOwnProperty('isPrototypeOf')) { + return false + } + + // Most likely a plain Object + return true +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function hasObjectPrototype(o: any): boolean { + return Object.prototype.toString.call(o) === '[object Object]' +} From 38152975748c127f0d0b6ece4fff1446b9f3b70e Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Mon, 10 Jun 2024 16:18:54 +0200 Subject: [PATCH 4/6] fix(spaceward): use Proto instead of Amino for signatures The current state of wardenjs + Keplr/Leap/... doesn't play well with BigInts, when using Amino. Switch back to Protobuf encoding for better support. --- spaceward/src/hooks/useClient.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spaceward/src/hooks/useClient.ts b/spaceward/src/hooks/useClient.ts index 307d3246a..01c17bea3 100755 --- a/spaceward/src/hooks/useClient.ts +++ b/spaceward/src/hooks/useClient.ts @@ -54,7 +54,7 @@ export enum TxStatus { } export function useTx() { - const { address, getOfflineSigner } = useChain(env.cosmoskitChainName); + const { address, getOfflineSignerDirect: getOfflineSigner } = useChain(env.cosmoskitChainName); const { toast } = useToast(); const tx = async (msgs: EncodeObject[], options: TxOptions) => { @@ -116,6 +116,7 @@ export function useTx() { update({ id, title: TxStatus.Failed, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore description: err?.message, duration: 10000, From c0615a167c13e0ec265210473b6a4af0ee894e02 Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Mon, 10 Jun 2024 16:19:53 +0200 Subject: [PATCH 5/6] feat(spaceward): add useAction hook for creating new Actions This hook is convenient for sending new MsgNewAction transactions. --- spaceward/src/hooks/useAction.ts | 31 +++++++++++++++++++++++++ spaceward/src/hooks/useModuleAccount.ts | 14 +++++++++++ spaceward/src/utils/any.ts | 15 ++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 spaceward/src/hooks/useAction.ts create mode 100644 spaceward/src/hooks/useModuleAccount.ts create mode 100644 spaceward/src/utils/any.ts diff --git a/spaceward/src/hooks/useAction.ts b/spaceward/src/hooks/useAction.ts new file mode 100644 index 000000000..d8ea0bd49 --- /dev/null +++ b/spaceward/src/hooks/useAction.ts @@ -0,0 +1,31 @@ +import { TxOptions, useTx } from "./useClient"; +import { useAddressContext } from "./useAddressContext"; +import { useModuleAccount } from "./useModuleAccount"; +import { Msg, packAny } from "@/utils/any"; +import { warden } from "@wardenprotocol/wardenjs"; + +const { newAction: newActionMsg } = warden.intent.MessageComposer.withTypeUrl; + +export function useNewAction(msg: Msg) { + const { address } = useAddressContext(); + const { tx } = useTx(); + + const { account: authorityAccount } = useModuleAccount("intent"); + const authority = authorityAccount?.baseAccount?.address; + + async function newAction(data: Data, opts: TxOptions, actionTimeoutHeight = 0) { + const m = newActionMsg({ + creator: address, + message: packAny(msg, data), + actionTimeoutHeight: BigInt(actionTimeoutHeight), + }); + const res = await tx([m], opts); + return res; + } + + return { + newAction, + authority, + }; +} + diff --git a/spaceward/src/hooks/useModuleAccount.ts b/spaceward/src/hooks/useModuleAccount.ts new file mode 100644 index 000000000..47711c04c --- /dev/null +++ b/spaceward/src/hooks/useModuleAccount.ts @@ -0,0 +1,14 @@ +import { ModuleAccount } from "@wardenprotocol/wardenjs/codegen/cosmos/auth/v1beta1/auth"; +import { useQueryHooks } from "./useClient"; + +export function useModuleAccount(name: string) { + const { cosmos } = useQueryHooks(); + const { data, status } = cosmos.auth.v1beta1.useModuleAccounts({ + options: { staleTime: Infinity }, + }); + const account = data?.accounts + .filter((a) => a.typeUrl === "/cosmos.auth.v1beta1.ModuleAccount") + .map((a) => ModuleAccount.decode(a.value)) + .find((a) => a.name === name); + return { account, status }; +} diff --git a/spaceward/src/utils/any.ts b/spaceward/src/utils/any.ts new file mode 100644 index 000000000..56277792c --- /dev/null +++ b/spaceward/src/utils/any.ts @@ -0,0 +1,15 @@ +import { BinaryWriter, google } from "@wardenprotocol/wardenjs"; +import { Any } from "cosmjs-types/google/protobuf/any"; + +export interface Msg { + typeUrl: string; + fromPartial: (data: Partial) => Data; + encode: (data: Data) => BinaryWriter; +} + +export function packAny(msg: Msg, data: Data): Any { + return google.protobuf.Any.fromPartial({ + typeUrl: msg.typeUrl, + value: msg.encode(msg.fromPartial(data)).finish(), + }) +} From e499063b9867ed5195d1f9f6bca1c10c74c92caf Mon Sep 17 00:00:00 2001 From: Antonio Pitasi Date: Mon, 10 Jun 2024 16:31:31 +0200 Subject: [PATCH 6/6] fix(spaceward): use new useAction hook when required --- spaceward/src/features/keys/NewKeyButton.tsx | 42 +++++------- .../src/features/owners/AddSpaceOwnerForm.tsx | 41 +++++------- spaceward/src/hooks/useEthereumTx.tsx | 5 +- spaceward/src/hooks/useRequestKey.ts | 66 +++++++++---------- spaceward/src/hooks/useRequestSignature.ts | 61 ++++++++--------- spaceward/src/pages/Intents.tsx | 43 ++++++------ spaceward/src/pages/Owners.tsx | 42 +++++------- 7 files changed, 134 insertions(+), 166 deletions(-) diff --git a/spaceward/src/features/keys/NewKeyButton.tsx b/spaceward/src/features/keys/NewKeyButton.tsx index 435184216..b29ea7039 100644 --- a/spaceward/src/features/keys/NewKeyButton.tsx +++ b/spaceward/src/features/keys/NewKeyButton.tsx @@ -27,23 +27,21 @@ import useKeychainId from "@/hooks/useKeychainId"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { useAddressContext } from "@/hooks/useAddressContext"; -import useWardenWardenV1Beta2 from "@/hooks/useWardenWardenV1Beta2"; import { KeyRequestDialog } from "./KeyRequestDialog"; import useRequestKey from "@/hooks/useRequestKey"; import { KeyIcon } from "lucide-react"; +import { useQueryHooks } from "@/hooks/useClient"; const FormSchema = z.object({}); export function NewKeyButton() { - const { address } = useAddressContext(); const [keychainId, setKeychainId] = useKeychainId(); const { spaceId } = useSpaceId(); const { state, error, keyRequest, requestKey, reset } = useRequestKey(); - const { QueryKeychains } = useWardenWardenV1Beta2(); - const q = QueryKeychains({}, {}, 10); + const { warden } = useQueryHooks(); + const q = warden.warden.v1beta2.useKeychains({}); const form = useForm>({ resolver: zodResolver(FormSchema), @@ -92,24 +90,15 @@ export function NewKeyButton() { - {q.data?.pages.flatMap( - (page) => - page.keychains?.map( - (kr) => ( - - { - kr.description - } - - ), - ), + {q.data?.keychains?.map( + (kr) => ( + + {kr.description} + + ), )} @@ -125,9 +114,10 @@ export function NewKeyButton() {