Skip to content

Commit

Permalink
fix(spaceward): use uint64 Keychain and Space IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Mar 8, 2024
1 parent 3436404 commit 6f636a5
Show file tree
Hide file tree
Showing 32 changed files with 161 additions and 172 deletions.
10 changes: 5 additions & 5 deletions spaceward/src/components/account-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { Fragment, useState } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { Button } from "./ui/button";
import { Link } from "react-router-dom";
import useKeychainAddress from "@/hooks/useKeychainAddress";
import KeychainAddress from "./keychain-address";
import useKeychainId from "@/hooks/useKeychainId";
import KeychainId from "./keychain-address";

function AccountInfo() {

const [open, setOpen] = useState(false)

const { address } = useAddressContext();
const [keychainAddress, _] = useKeychainAddress();
const [keychainId, _] = useKeychainId();
const bq = useQuery({ queryKey: ["balances", address], queryFn: () => balances(address) });
const denom = bq.data?.balances.find((b) => b.denom === "uward")?.amount || "0";
const ward = parseInt(denom) / 10 ** 6;
Expand Down Expand Up @@ -102,8 +102,8 @@ function AccountInfo() {
<div className="flex flex-col items-start justify-center">
<p className="text-xs">Active keychain</p>
<p className="text-lg tracking-normal font-display">
{ keychainAddress ? (
<KeychainAddress onClick={() => setOpen(false)} address={keychainAddress} />
{ keychainId ? (
<KeychainId onClick={() => setOpen(false)} address={keychainId} />
) : (
<span className="text-gray-400">None</span>
) }
Expand Down
4 changes: 2 additions & 2 deletions spaceward/src/components/add-keychain-party-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useClient } from "@/hooks/useClient";
import { monitorTx } from "@/hooks/keplr";
import { useToast } from "./ui/use-toast";

function AddKeychainPartyForm({ addr, keychainAddr }: { addr: string, keychainAddr: string }) {
function AddKeychainPartyForm({ addr, keychainId }: { addr: string, keychainId: string }) {
const { toast } = useToast();
const client = useClient();
const sendMsgAddKeychainParty = client.WardenWarden.tx.sendMsgAddKeychainParty;
Expand All @@ -17,7 +17,7 @@ function AddKeychainPartyForm({ addr, keychainAddr }: { addr: string, keychainAd
await monitorTx(sendMsgAddKeychainParty({
value: {
creator: addr,
keychainAddr,
keychainId,
party: newParty,
}
}), toast);
Expand Down
6 changes: 3 additions & 3 deletions spaceward/src/components/add-space-owner-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { shapes } from "@dicebear/collection";

function AddSpaceOwnerForm({
addr,
spaceAddr,
spaceId,
}: {
addr: string;
spaceAddr: string;
spaceId: string;
}) {
const { toast } = useToast();
const client = useClient();
Expand Down Expand Up @@ -54,7 +54,7 @@ function AddSpaceOwnerForm({
sendMsgAddSpaceOwner({
value: {
creator: addr,
spaceAddr,
spaceId,
newOwner,
btl: 0,
},
Expand Down
4 changes: 2 additions & 2 deletions spaceward/src/components/assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ async function getEthBalance(address: string) {
return balance;
}

function Assets({ spaceAddr }: { spaceAddr: string }) {
function Assets({ spaceId }: { spaceId: string }) {
const { QueryKeys } = useWardenWarden();
const query = QueryKeys(
{
type: WalletType.WALLET_TYPE_ETH,
space_addr: spaceAddr,
space_id: spaceId,
},
{},
10
Expand Down
12 changes: 6 additions & 6 deletions spaceward/src/components/choose-keychain-button.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import useKeychainAddress from "@/hooks/useKeychainAddress";
import useKeychainId from "@/hooks/useKeychainId";
import { Button } from "./ui/button";

function ChooseKeychainButton({ keychainAddress: newKeychainAddress }: { keychainAddress: string }) {
const [keychainAddress, setKeychainAddress] = useKeychainAddress();
function ChooseKeychainButton({ keychainId: newKeychainId }: { keychainId: string }) {
const [keychainId, setKeychainId] = useKeychainId();

return (
<Button disabled={newKeychainAddress === keychainAddress} onClick={() => {
setKeychainAddress(newKeychainAddress);
<Button disabled={newKeychainId === keychainId} onClick={() => {
setKeychainId(newKeychainId);
}}>
{keychainAddress === newKeychainAddress ? "In use" : "Use this keychain"}
{keychainId === newKeychainId ? "In use" : "Use this keychain"}
</Button>
);
}
Expand Down
14 changes: 7 additions & 7 deletions spaceward/src/components/choose-space-button.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useSpaceAddress } from "@/hooks/useSpaceAddress";
import { useSpaceId } from "@/hooks/useSpaceId";
import { Button } from "./ui/button";

function ChooseSpaceButton({
spaceAddress: newSpaceAddress,
spaceId: newSpaceId,
}: {
spaceAddress: string;
spaceId: string;
}) {
const [spaceAddress, setSpaceAddress] = useSpaceAddress();
const [spaceId, setSpaceId] = useSpaceId();

return (
<Button
disabled={newSpaceAddress === spaceAddress}
disabled={newSpaceId === spaceId}
onClick={() => {
setSpaceAddress(newSpaceAddress);
setSpaceId(newSpaceId);
}}
>
{spaceAddress === newSpaceAddress ? "In use" : "Use this space"}
{spaceId === newSpaceId ? "In use" : "Use this space"}
</Button>
);
}
Expand Down
6 changes: 3 additions & 3 deletions spaceward/src/components/home-assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useQuery } from "@tanstack/react-query";
import { Button } from "./ui/button";
import { MoveDownLeft, MoveUpRight, KeyIcon } from "lucide-react";
import { Link } from "react-router-dom";
import { useSpaceAddress } from "@/hooks/useSpaceAddress";
import { useSpaceId } from "@/hooks/useSpaceId";
import NewKeyButton from "./new-key-button";
import ReceiveAssetButton from "@/components/receive-asset-button";
import { Copy } from "@/components/ui/copy";
Expand All @@ -21,13 +21,13 @@ async function getEthBalance(address: string) {
}

function HomeAssets() {
const { spaceAddress } = useSpaceAddress();
const { spaceId } = useSpaceId();

const { QueryKeys } = useWardenWarden();
const query = QueryKeys(
{
type: WalletType.WALLET_TYPE_ETH,
space_addr: spaceAddress,
space_id: spaceId,
},
{},
10
Expand Down
6 changes: 3 additions & 3 deletions spaceward/src/components/intents.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Intent from "./intent";
import useWardenIntent from "@/hooks/useWardenIntent";
import SpaceIntentCard from "./space-intent-card";
import { useSpaceAddress } from "@/hooks/useSpaceAddress";
import { useSpaceId } from "@/hooks/useSpaceId";
import { Space as SpaceModel } from "warden-protocol-wardenprotocol-client-ts/lib/warden.warden/rest";
import useWardenWarden from "@/hooks/useWardenWarden";

function Intents() {
const { spaceAddress } = useSpaceAddress();
const { spaceId } = useSpaceId();
const { QuerySpaceByAddress } = useWardenWarden();
const wsQuery = QuerySpaceByAddress({ address: spaceAddress }, {});
const wsQuery = QuerySpaceByAddress({ address: spaceId }, {});
const space = wsQuery.data?.space as Required<SpaceModel>;
const { QueryIntents } = useWardenIntent();
const intentsQ = QueryIntents({}, {}, 10);
Expand Down
8 changes: 4 additions & 4 deletions spaceward/src/components/keychain-address.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Link, LinkProps } from "react-router-dom";
import Address from "./address";

function KeychainAddress({ address, ...props }: { address: string } & Partial<LinkProps>) {
function KeychainId({ id, ...props }: { id: string } & Partial<LinkProps>) {
return (
<Link to={`/keychains/${address}`} {...props}>
<Address address={address} hideAvatar />
<Link to={`/keychains/${id}`} {...props}>
<Address address={id} hideAvatar />
</Link>
);
}

export default KeychainAddress;
export default KeychainId;
10 changes: 5 additions & 5 deletions spaceward/src/components/keys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import ReceiveAssetButton from "./receive-asset-button";
import { MoveUpRight, KeyIcon } from "lucide-react";
import NewKeyButton from "./new-key-button";

export default function Keys({ spaceAddr }: { spaceAddr: string }) {
export default function Keys({ spaceId }: { spaceId: string }) {
const { QueryKeys } = useWardenWarden();
const query = QueryKeys({ space_addr: spaceAddr }, {}, 10);
const query = QueryKeys({ space_id: spaceId }, {}, 10);

if (query.status === "loading") {
return <div>Loading...</div>;
Expand Down Expand Up @@ -85,7 +85,7 @@ function Key({
Keychain
</span>
<span className="text-sm">
<Copy value={keyData.keychain_addr} split />
<Copy value={keyData.keychain_id} />
</span>
</div>
<div className="flex flex-col text-left">
Expand Down Expand Up @@ -152,10 +152,10 @@ function Key({
}

export async function loader({ params }: { params: Params<string> }) {
if (!params.spaceAddr) {
if (!params.spaceId) {
throw new Error("No space address provided");
}
return {
spaceAddr: params.spaceAddr,
spaceId: params.spaceId,
};
}
24 changes: 12 additions & 12 deletions spaceward/src/components/new-key-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
FormLabel,
} from "@/components/ui/form";
import { Label } from "./ui/label";
import { useSpaceAddress } from "@/hooks/useSpaceAddress";
import useKeychainAddress from "@/hooks/useKeychainAddress";
import { useSpaceId } from "@/hooks/useSpaceId";
import useKeychainId from "@/hooks/useKeychainId";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand All @@ -37,8 +37,8 @@ const FormSchema = z.object({});

function NewKeyButton() {
const { address } = useAddressContext();
const [keychainAddress, setKeychainAddress] = useKeychainAddress();
const { spaceAddress } = useSpaceAddress();
const [keychainId, setKeychainId] = useKeychainId();
const { spaceId } = useSpaceId();

const { state, error, keyRequest, requestKey, reset } = useRequestKey();

Expand Down Expand Up @@ -79,7 +79,7 @@ function NewKeyButton() {
<Select
onValueChange={(value) =>
field.onChange(
setKeychainAddress(
setKeychainId(
value
)
)
Expand All @@ -98,10 +98,10 @@ function NewKeyButton() {
(kr) => (
<SelectItem
key={
kr.address
kr.id
}
value={
kr.address!
kr.id!
}
>
{
Expand All @@ -118,7 +118,7 @@ function NewKeyButton() {
/>
{/* <Select
onValueChange={() =>
setKeychainAddress(e.target.value)
setKeychainId(e.target.value)
}
>
<SelectTrigger className="w-full">
Expand All @@ -135,7 +135,7 @@ function NewKeyButton() {
{/* <Label htmlFor="description">Chain</Label>
<Select
// onChange={(e) =>
// setKeychainAddress(e.target.value)
// setKeychainId(e.target.value)
// }
>
<SelectTrigger className="w-full">
Expand All @@ -161,12 +161,12 @@ function NewKeyButton() {
<SheetClose asChild>
<Button
type="submit"
disabled={!keychainAddress || !spaceAddress}
disabled={!keychainId || !spaceId}
onClick={() =>
requestKey(
keychainAddress!,
keychainId!,
address,
spaceAddress!
spaceId!
)
}
>
Expand Down
Loading

0 comments on commit 6f636a5

Please sign in to comment.