Skip to content

Commit b06cb4a

Browse files
authored
make env variables optional with elegant fallbacks (#21)
1 parent ea24d9a commit b06cb4a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/ipfs/preferences.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import getIpfsWithConfig from "get-ipfs";
2-
import { FissionUser } from "@fission-suite/client";
2+
import { pin } from "@fission-suite/client";
33

44
const ipfsProvider =
55
process.env.REACT_APP_INTERPLANETARY_FISSION_URL || "https://hostless.dev";
66
const username = process.env.REACT_APP_INTERPLANETARY_FISSION_USERNAME;
77
const password = process.env.REACT_APP_INTERPLANETARY_FISSION_PASSWORD;
88
const bootstrapNode = process.env.REACT_APP_BOOTSTRAP_NODE;
9-
const fission = new FissionUser(username, password, ipfsProvider);
109

1110
export const DefaultCid = "QmUMQ5Zxu94gwGq96hGEBc2hzoMkywUctbySw7YY6g8ktw";
1211

1312
const getIpfs = async () => {
13+
if (bootstrapNode) {
14+
return getIpfsWithConfig({
15+
bootstrap: [bootstrapNode]
16+
});
17+
}
1418
return getIpfsWithConfig();
15-
const ipfs = await getIpfsWithConfig({
16-
bootstrap: [bootstrapNode]
17-
});
1819
};
1920

2021
export const validPreferences = preferences => {
@@ -68,7 +69,9 @@ export const savePreferences = async preferences => {
6869
throw new Error("Could not parse CID");
6970
}
7071
try {
71-
await fission.pin(cid);
72+
if (username && password && ipfsProvider) {
73+
await pin(cid, { username, password }, ipfsProvider);
74+
}
7275
} catch (err) {
7376
console.error(err);
7477
}

0 commit comments

Comments
 (0)