Skip to content

Commit

Permalink
feat: enable infura ipfs headers via env vars (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
dohaki authored Aug 10, 2022
1 parent 64f5388 commit f81e2a1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
REACT_APP_CHAIN_ID=1234
REACT_APP_WIDGETS_URL=

# Infura IPFS project ID, used for auth header
REACT_APP_INFURA_IPFS_PROJECT_ID=

# Infura IPFS project secret, used for auth header
REACT_APP_INFURA_IPFS_PROJECT_SECRET=

# A Biconomy API key can be set here, to allow meta transactions in the widgets
REACT_APP_META_TX_API_KEY=

Expand Down
66 changes: 33 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]
},
"dependencies": {
"@bosonprotocol/react-kit": "^0.3.0-alpha.5",
"@bosonprotocol/react-kit": "^0.3.0-alpha.6",
"@bosonprotocol/widgets-sdk": "^1.9.0-alpha.0",
"@davatar/react": "^1.10.4",
"@ethersproject/address": "^5.6.1",
Expand Down
21 changes: 20 additions & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export const CONFIG = {
: 2 * 1024 * 1024,
widgetsUrl: process.env.REACT_APP_WIDGETS_URL || config.widgetsUrl,
chainId: REACT_APP_CHAIN_ID,
ipfsMetadataUrl:
ipfsMetadataStorageUrl:
process.env.REACT_APP_IPFS_METADATA_URL || config.ipfsMetadataUrl,
ipfsMetadataStorageHeaders: getIpfsMetadataStorageHeaders(
process.env.REACT_APP_INFURA_IPFS_PROJECT_ID,
process.env.REACT_APP_INFURA_IPFS_PROJECT_SECRET
),
sentryDSNUrl:
"https://[email protected]/6455090",
metaTransactionsApiKey: process.env.REACT_APP_META_TX_API_KEY,
Expand All @@ -46,3 +50,18 @@ function stringToBoolean(value?: string) {

return Boolean(value);
}

function getIpfsMetadataStorageHeaders(
infuraProjectId?: string,
infuraProjectSecret?: string
) {
if (!infuraProjectId && !infuraProjectSecret) {
return undefined;
}

return {
authorization: `Basic ${Buffer.from(
infuraProjectId + ":" + infuraProjectSecret
).toString("base64")}`
};
}
12 changes: 12 additions & 0 deletions src/lib/utils/hooks/useIpfsStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { hooks } from "@bosonprotocol/react-kit";

import { CONFIG } from "../../config";

export function useIpfsStorage() {
const storage = hooks.useIpfsMetadataStorage(
CONFIG.chainId,
CONFIG.ipfsMetadataStorageHeaders
);

return storage;
}

0 comments on commit f81e2a1

Please sign in to comment.