Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(installBundle): add :bundles follower to confirm installation #39

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ts:check": "tsc --noEmit"
},
"dependencies": {
"@agoric/casting": "^0.4.3-u13.0",
"@agoric/cosmic-proto": "dev",
"@agoric/eventual-send": "^0.14.1",
"@agoric/notifier": "^0.6.2",
Expand Down
45 changes: 45 additions & 0 deletions src/components/BundleFollowerToastMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { toast } from "react-toastify";
import { ClipboardDocumentIcon } from "@heroicons/react/20/solid";
import { XMarkIcon } from "@heroicons/react/20/solid";

export const BundleFollowerToastMessage = ({
endoZipBase64Sha512,
closeToast = () => {},
}: {
endoZipBase64Sha512: string;
closeToast: () => void;
}) => (
<div className="flex items-start pointer-events-auto">
<div className="ml-3 w-0 flex-1 pt-0.5">
<p className="text-sm font-medium text-gray-900">
Bundle Successfully Installed!
</p>
<span className="mt-1 text-sm text-gray-500">
<span
className="text-sm text-blue-500 hover:text-blue-700 underline cursor-pointer"
onClick={async () => {
await window.navigator.clipboard.writeText(endoZipBase64Sha512);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would it cost to avoid ambient access to window?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toast.info("Copied to clipboard!", {
position: "bottom-center",
autoClose: 3000,
hideProgressBar: true,
});
}}
>
EndoZipBase64Sha512{" "}
<ClipboardDocumentIcon className="inline-block w-4 h-4" />
</span>
</span>
</div>
<div className="ml-4 flex flex-shrink-0">
<button
type="button"
className="inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-teal-500 focus:ring-offset-2"
onClick={closeToast}
>
<span className="sr-only">Close</span>
<XMarkIcon className="h-5 w-5" aria-hidden="true" />
</button>
</div>
</div>
);
10 changes: 8 additions & 2 deletions src/config/agoric/agoric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import {
} from "../../lib/messageBuilder";
import { isValidBundle } from "../../utils/validate";
import { makeSignAndBroadcast } from "../../lib/signAndBroadcast";
import { useWatchBundle } from "../../hooks/useWatchBundle";

const Agoric = () => {
const { netName } = useNetwork();
const { walletAddress, stargateClient } = useWallet();
const proposalFormRef = useRef<HTMLFormElement>(null);
const corEvalFormRef = useRef<HTMLFormElement>(null);
const bundleFormRef = useRef<HTMLFormElement>(null);
const watchBundle = useWatchBundle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

watchBundle presumable access the net, yes? but no access to the net is passed around explicitly. What would it cost to remedy that lack of ocap discipline?

I suppose this goes for useWallet too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See [c9c1537]. useWallet, agree but deeming out of scope for this pr


const signAndBroadcast = useMemo(
() => makeSignAndBroadcast(stargateClient, walletAddress, netName),
Expand All @@ -46,8 +48,12 @@ const Agoric = () => {
submitter: walletAddress,
});
try {
await signAndBroadcast(proposalMsg, "bundle");
bundleFormRef.current?.reset();
const txResponse = await signAndBroadcast(proposalMsg, "bundle");
if (txResponse) {
const endoZipBase64Sha512 = JSON.parse(vals.bundle).endoZipBase64Sha512;
0xpatrickdev marked this conversation as resolved.
Show resolved Hide resolved
await watchBundle(endoZipBase64Sha512, txResponse);
bundleFormRef.current?.reset();
}
} catch (e) {
console.error(e);
}
Expand Down
61 changes: 61 additions & 0 deletions src/hooks/useWatchBundle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
iterateEach,
makeCastingSpec,
makeFollower,
makeLeader,
} from "@agoric/casting";
import { toast } from "react-toastify";
import { useNetwork } from "./useNetwork";
import { BundleFollowerToastMessage } from "../components/BundleFollowerToastMessage";

type IteratorEnvelope = {
value?: {
endoZipBase64Sha512: string;
installed: boolean;
error: unknown;
};
error?: { message: string; stack: string };
};

export const useWatchBundle = () => {
const { networkConfig } = useNetwork();
const leader = networkConfig ? makeLeader(networkConfig.rpc) : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... I think I enhanced casting to accept an RPC client object, i.e. explicit access to the network, and not just a URL that gets turned into network access like casting an int to a pointer.

Or maybe I just figured out how to.

Copy link
Collaborator Author

@0xpatrickdev 0xpatrickdev Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makeHttpClient ?

It seems I need a follower to be able to query :bundles? I'm not sure how this maps wrt things like :1317/agoric/(swingset|vstorage)/* and agd query (vstorage|swingset)... .

makeLeader in u-13 (current version checked in) only take a url or network config object. makeRoundRobinLeader on latest master still seems to only accept strings too


const watchBundle = async (
expectedEndoZipBase64Sha512: string,
{ height }: { height: number },
) => {
if (!leader) throw Error("Unexpected error: leader not found.");
const castingSpec = makeCastingSpec(":bundles");
const follower = makeFollower(castingSpec, leader);
for await (const envelope of iterateEach(follower, { height })) {
const { value, error } = envelope as IteratorEnvelope;
if (!value && error) {
toast.error(`Bundle installation failed.\nSee console for details.`);
console.log(envelope);
throw error;
}
if (value) {
const { endoZipBase64Sha512, installed, error } = value;
0xpatrickdev marked this conversation as resolved.
Show resolved Hide resolved
if (endoZipBase64Sha512 === expectedEndoZipBase64Sha512) {
if (!installed) {
toast.error(
`Bundle installation failed.\nSee console for details.`,
);
throw error;
} else {
toast.success(({ closeToast }) => (
<BundleFollowerToastMessage
endoZipBase64Sha512={endoZipBase64Sha512}
closeToast={closeToast as () => void}
/>
));
return;
}
}
}
}
};

return watchBundle;
};
Loading
Loading