Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 16 additions & 26 deletions src/components/SubmitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,22 @@ import Button from "@material-ui/core/Button";
import CheckIcon from "@material-ui/icons/Check";

const SubmitButton = props => {
if (!props.submitted) {
return (
<Button
variant="contained"
color="secondary"
type="submit"
className={props.classes.button}
>
{props.textNormal}
{props.icon}
</Button>
);
} else {
return (
<Button
variant="contained"
color="secondary"
type="submit"
className={props.classes.button}
disabled
>
{props.textSubmitted}
<CheckIcon className={props.classes.icon} />
</Button>
);
}
const { submitted, textNormal, textSubmitted } = props;
const text = submitted ? textSubmitted : textNormal;
const icon = submitted ? <CheckIcon /> : props.icon;

return (
<Button
variant="contained"
color="secondary"
type="submit"
disabled={submitted}
className={props.classes.button}
>
{text}
{icon}
</Button>
);
};

const styles = theme =>
Expand Down
76 changes: 42 additions & 34 deletions src/ipfs/getIpfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,41 @@ export const ipfsIsWorking = async ipfs => {
}
};

const getIpfs = (permissions = DEFAULT_PERMISSIONS) => {
return new Promise(async (resolve, reject) => {
// if already instantiated
if (ipfsInstance) {
return resolve(ipfsInstance);
}

if (window.ipfs) {
let ipfs = window.ipfs;
if (window.ipfs.enable) {
console.log("window.ipfs.enable is available!");
// if user set permissions, make sure id and version are both added
if (permissions.indexOf("id") < 0) {
permissions.push("id");
}
if (permissions.indexOf("version") < 0) {
permissions.push("version");
}
ipfs = await window.ipfs.enable({
commands: permissions
});
} else {
console.log("legacy window.ipfs is available!");
export const loadWindowIpfs = async permissions => {
if (window.ipfs) {
let ipfs = window.ipfs;
if (window.ipfs.enable) {
// if user set permissions, make sure id and version are both added
if (permissions.indexOf("id") < 0) {
permissions.push("id");
}
const isWorking = await ipfsIsWorking(ipfs);
if (isWorking) {
ipfsInstance = ipfs;
resolve(ipfsInstance);
} else {
console.log(
"cannot access window.ipfs, may not be connected to a working gateway"
);
if (permissions.indexOf("version") < 0) {
permissions.push("version");
}
ipfs = await window.ipfs.enable({
commands: permissions
});
} else {
}
const isWorking = await ipfsIsWorking(ipfs);
if (isWorking) {
return ipfs;
} else {
return null;
}
}
return null;
};

console.log("window.ipfs is not available, downloading from CDN...");
export const loadJsIpfs = async () => {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = "https://unpkg.com/ipfs/dist/index.min.js";
script.onload = async () => {
const ipfs = await window.Ipfs.create();
const isWorking = await ipfsIsWorking(ipfs);
if (isWorking) {
ipfsInstance = ipfs;
resolve(ipfsInstance);
resolve(ipfs);
} else {
reject(new Error("js-ipfs is not able to load"));
}
Expand All @@ -67,4 +58,21 @@ const getIpfs = (permissions = DEFAULT_PERMISSIONS) => {
});
};

const getIpfs = (permissions = DEFAULT_PERMISSIONS) => {
// if already instantiated
if (ipfsInstance) {
return ipfsInstance;
}

ipfsInstance = await loadWindowIpfs(permissions)
if(ipfsInstance){
console.log("window.ipfs is available!")
return ipfsInstance
}

console.log("window.ipfs is not available, downloading from CDN...");
ipfsInstance = await loadJsIpfs();
return ipfsInstance
};

export default getIpfs;