Skip to content

Instantly share code, notes, and snippets.

@andrewxhill
Created August 27, 2021 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewxhill/4b02d1558eb34ecad764c3ccf5289600 to your computer and use it in GitHub Desktop.
Save andrewxhill/4b02d1558eb34ecad764c3ccf5289600 to your computer and use it in GitHub Desktop.
// trigger bridge deposit for a user with their wallet
const onSubmit = () => {
api
.addDeposit()
.then(() => setDeposit(true))
.catch((err: Error) => alert(err.message));
};
// release a user's deposited funds after they've expired
const onRelease = () => {
api
.releaseDeposit()
.then(() => {
alert(
"if your session is over, your funds should be returned"
);
// Auto-refresh the page
window.location.reload();
})
.catch((err: Error) => alert(err.message));
};
// check the status of a storage request by ID
const onStatus = (id: string) => {
if (id) {
api
.status(id)
.then(({ request }) => {
//alert(`Filecoin deal status: "${request.status_code}"!`);
})
.catch((err: Error) => alert(err.message));
} else {
console.warn("no 'active' file, upload a file first");
}
};
// push file bytes over the bridge for storage on Filecoin
const onUpload = (file: File) => {
setUploading(true);
api
.store(file)
.then(request => {
setUploads([...uploads, request]);
setUploading(false);
// alert(`IPFS CID:\n${request.cid["/"]}`);
})
.catch((err: Error) => {
setUploading(false);
alert(err.message);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment