Created
August 27, 2021 21:21
-
-
Save andrewxhill/4b02d1558eb34ecad764c3ccf5289600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trigger bridge deposit for a user with their wallet | |
const onSubmit = () => { | |
api | |
.addDeposit() | |
.then(() => setDeposit(true)) | |
.catch((err: Error) => alert(err.message)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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