This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added build:analyze script * removed pinata package and added custom api call function (#1993) * removed pinata package and added custom api function * added type and move url to const * added requested PR changes * Optimize bn.js package (#2479) * Use modified paraswap package version (#2493)
- Loading branch information
Showing
5 changed files
with
400 additions
and
260 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
import pinataSDK, { PinataPinResponse } from '@pinata/sdk' | ||
import { PINATA_API_KEY, PINATA_SECRET_API_KEY } from 'constants/ipfs' | ||
import { PINATA_API_KEY, PINATA_SECRET_API_KEY, PINATA_API_URL } from 'constants/ipfs' | ||
|
||
const pinata = pinataSDK(PINATA_API_KEY, PINATA_SECRET_API_KEY) | ||
type PinataPinResponse = { | ||
IpfsHash: string | ||
PinSize: number | ||
Timestamp: string | ||
} | ||
|
||
const pinataUrl = `${PINATA_API_URL}/pinning/pinJSONToIPFS` | ||
|
||
const headers = new Headers({ | ||
'Content-Type': 'application/json', | ||
pinata_api_key: PINATA_API_KEY, | ||
pinata_secret_api_key: PINATA_SECRET_API_KEY, | ||
}) | ||
|
||
export async function pinJSONToIPFS(file: any): Promise<PinataPinResponse> { | ||
return pinata.pinJSONToIPFS(file, { pinataMetadata: { name: 'appData-affiliate' } }) | ||
const body = JSON.stringify({ | ||
pinataContent: file, | ||
pinataMetadata: { name: 'appData-affiliate' }, | ||
}) | ||
|
||
const request = new Request(pinataUrl, { | ||
method: 'POST', | ||
headers, | ||
body, | ||
}) | ||
|
||
const response = await fetch(request) | ||
const data = await response.json() | ||
|
||
if (response.status !== 200) { | ||
throw new Error(data.error.details || data.error) | ||
} | ||
|
||
return data | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const PINATA_API_KEY = process.env.REACT_APP_PINATA_API_KEY as string | ||
export const PINATA_SECRET_API_KEY = process.env.REACT_APP_PINATA_SECRET_API_KEY as string | ||
export const PINATA_API_URL = process.env.REACT_APP_PINATA_API_URL || 'https://api.pinata.cloud' | ||
export const IPFS_URI = process.env.REACT_APP_IPFS_URI || 'https://ipfs.infura.io:5001/api/v0' |
Oops, something went wrong.