Skip to content

Commit

Permalink
refactor: use Telescope api
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 16, 2024
1 parent 653f9ff commit 28d358b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 49 deletions.
14 changes: 9 additions & 5 deletions src/components/BundleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useMemo,
ReactNode,
} from "react";
import { MsgInstallBundle } from "@agoric/cosmic-proto/swingset/msgs.js";
import { agoric } from "@agoric/cosmic-proto";
import { useQuery } from "@tanstack/react-query";
import { toast } from "react-toastify";
import { CodeInput, CodeInputMethods } from "./CodeInput";
Expand All @@ -18,7 +18,11 @@ import { accountBalancesQuery, swingSetParamsQuery } from "../lib/queries";
import { selectStorageCost, selectIstBalance } from "../lib/selectors";
import { useWallet } from "../hooks/useWallet";

export type BundleFormArgs = Pick<MsgInstallBundle, "bundle">;
// XXX can we import this type?
export type BundleFormArgs = Pick<
ReturnType<typeof agoric.swingset.MsgInstallBundle.fromJSON>,
"bundle"
>;

interface BundleFormProps {
title: string;
Expand All @@ -40,12 +44,12 @@ const BundleForm = forwardRef<BundleFormMethods, BundleFormProps>(
const swingsetParams = useQuery(swingSetParamsQuery(api));
const costPerByte = useMemo(
() => selectStorageCost(swingsetParams),
[swingsetParams],
[swingsetParams]
);
const accountBalances = useQuery(accountBalancesQuery(api, walletAddress));
const istBalance = useMemo(
() => selectIstBalance(accountBalances),
[accountBalances],
[accountBalances]
);

useImperativeHandle(ref, () => ({
Expand Down Expand Up @@ -116,7 +120,7 @@ const BundleForm = forwardRef<BundleFormMethods, BundleFormProps>(
</div>
</form>
);
},
}
);

export { BundleForm };
8 changes: 4 additions & 4 deletions src/components/CodeInputGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useRef, forwardRef, useImperativeHandle } from "react";
import { CodeInput } from "./CodeInput";
import { CoreEval } from "@agoric/cosmic-proto/swingset/swingset.js";
import type { CoreEval } from "@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset";
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
import { Button } from "./Button";
import { CodeInput } from "./CodeInput";

interface CodeInputGroupProps {
onPairsChange: (pairs: CoreEval[]) => void;
Expand Down Expand Up @@ -76,7 +76,7 @@ const CodeInputGroup = forwardRef<CodeInputGroupMethods, CodeInputGroupProps>(
/>
</div>
);
},
}
);

export { CodeInputGroup };
4 changes: 2 additions & 2 deletions src/components/ProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
FormEvent,
ReactNode,
} from "react";
import type { CoreEval } from "@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset";
import { CodeInputGroup } from "./CodeInputGroup";
import { CoreEval } from "@agoric/cosmic-proto/swingset/swingset.js";
import { Button } from "./Button";
import { ParamChange } from "cosmjs-types/cosmos/params/v1beta1/params";
import { ParameterChangeFormSection } from "./ParameterChangeForm";
Expand Down Expand Up @@ -150,7 +150,7 @@ const ProposalForm = forwardRef<ProposalFormMethods, ProposalFormProps>(
</div>
</form>
);
},
}
);

export { ProposalForm };
8 changes: 4 additions & 4 deletions src/config/inter/inter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useRef, FormEvent } from "react";
import { toast } from "react-toastify";
import type { CoreEval } from "@agoric/cosmic-proto/swingset/swingset.js";
import type { CoreEval } from "@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset";
import { MultiStepProposalForm } from "../../components/MultiStepProposalForm";
import { Tabs } from "../../components/Tabs";
import { useNetwork } from "../../hooks/useNetwork";
Expand Down Expand Up @@ -33,7 +33,7 @@ const Inter = () => {

const signAndBroadcast = useMemo(
() => makeSignAndBroadcast(stargateClient, walletAddress, netName),
[stargateClient, walletAddress, netName],
[stargateClient, walletAddress, netName]
);

const handlePsmSubmit = async (e: FormEvent) => {
Expand Down Expand Up @@ -150,11 +150,11 @@ const Inter = () => {
};
const generatedAddVaultJs = generateFromTemplate<AddVaultParams>(
addVaultJs,
templateParams,
templateParams
);
const generatedAddOracleJs = generateFromTemplate<AddVaultParams>(
addOracleJs,
templateParams,
templateParams
);

const evals: CoreEval[] = [
Expand Down
8 changes: 4 additions & 4 deletions src/contexts/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
ReactNode,
useCallback,
} from "react";
import { getSigningAgoricClientOptions } from "@agoric/cosmic-proto";
import { Decimal } from "@cosmjs/math";
import { SigningStargateClient } from "@cosmjs/stargate";
import { AccountData } from "@keplr-wallet/types";
import { useNetwork, NetName } from "../hooks/useNetwork";
import { suggestChain } from "../lib/suggestChain";
import { getNetConfigUrl } from "../lib/getNetworkConfig";
import { registry } from "../lib/messageBuilder";

interface WalletContext {
walletAddress: string | null;
Expand Down Expand Up @@ -57,7 +57,7 @@ export const WalletContextProvider = ({
const connectWallet = useCallback(async () => {
setIsLoading(true);
const { chainId, rpc } = await suggestChain(
getNetConfigUrl(netName as NetName),
getNetConfigUrl(netName as NetName)
);
setRpc(rpc);
if (chainId) {
Expand All @@ -72,12 +72,12 @@ export const WalletContextProvider = ({
rpc,
offlineSigner,
{
registry,
...getSigningAgoricClientOptions(),
gasPrice: {
denom: "uist",
amount: Decimal.fromUserInput("50000000", 0),
},
},
}
);
} catch (e) {
console.error("error stargateClient setup", e);
Expand Down
47 changes: 17 additions & 30 deletions src/lib/messageBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { CoreEvalProposal } from "@agoric/cosmic-proto/swingset/swingset.js";
import { MsgInstallBundle } from "@agoric/cosmic-proto/swingset/msgs.js";
import { agoric, cosmos } from "@agoric/cosmic-proto";
import { StdFee } from "@cosmjs/amino";
import { fromBech32 } from "@cosmjs/encoding";
import { coins, Registry } from "@cosmjs/proto-signing";
import { defaultRegistryTypes } from "@cosmjs/stargate";
import { coins } from "@cosmjs/proto-signing";
import { TextProposal } from "cosmjs-types/cosmos/gov/v1beta1/gov";
import type { ParamChange } from "cosmjs-types/cosmos/params/v1beta1/params";
import { ParameterChangeProposal } from "cosmjs-types/cosmos/params/v1beta1/params";
import { Any } from "cosmjs-types/google/protobuf/any";
import type { ParamChange } from "cosmjs-types/cosmos/params/v1beta1/params";

export const registry = new Registry([
...defaultRegistryTypes,
["/agoric.swingset.MsgInstallBundle", MsgInstallBundle],
]);
import type { CoreEvalProposal } from "@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset";

interface MakeTextProposalArgs {
title: string;
Expand All @@ -36,8 +30,8 @@ export const makeTextProposalMsg = ({
TextProposal.fromPartial({
title,
description,
}),
).finish(),
})
).finish()
),
}),
proposer,
Expand All @@ -52,26 +46,19 @@ export const makeCoreEvalProposalMsg = ({
evals,
proposer,
deposit,
}: CoreEvalProposal & { proposer: string; deposit?: string | number }) => ({
typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal",
value: {
content: Any.fromPartial({
typeUrl: "/agoric.swingset.CoreEvalProposal",
value: Uint8Array.from(
CoreEvalProposal.encode(
CoreEvalProposal.fromPartial({
title,
description,
evals,
}),
).finish(),
),
}: CoreEvalProposal & { proposer: string; deposit?: string | number }) => {
return cosmos.gov.v1beta1.MsgSubmitProposal.fromPartial({
// @ts-expect-error FIXME generate union instead of intersection types
content: agoric.swingset.CoreEvalProposal.fromPartial({
title,
description,
evals,
}),
proposer,
...(deposit &&
Number(deposit) && { initialDeposit: coins(deposit, "ubld") }),
},
});
});
};

export interface ParamChangeArgs {
title: string;
Expand All @@ -98,8 +85,8 @@ export const makeParamChangeProposalMsg = ({
title,
description,
changes,
}),
).finish(),
})
).finish()
),
}),
proposer,
Expand Down

0 comments on commit 28d358b

Please sign in to comment.