-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from 1 commit
de6d935
d7ce24e
2e258ce
c9c1537
864e9e1
96e07dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
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> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I suppose this goes for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See [c9c1537]. |
||
|
||
const signAndBroadcast = useMemo( | ||
() => makeSignAndBroadcast(stargateClient, walletAddress, netName), | ||
|
@@ -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); | ||
} | ||
|
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems I need a follower to be able to query
|
||
|
||
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; | ||
}; |
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c9c1537