Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update ipld explorer components #1750

Merged
merged 4 commits into from
Apr 3, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ yarn-error.log*
.idea
.eslintcache
tsconfig.tsbuildinfo
.connect-deps*
49,198 changes: 24,308 additions & 24,890 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"brace": "^0.11.1",
"change-case": "^3.1.0",
"chart.js": "^2.9.3",
"cids": "^1.1.5",
"cids": "^1.1.6",
"countly-sdk-web": "^19.8.0",
"d3": "^5.16.0",
"datatransfer-files-promise": "^1.3.1",
Expand All @@ -41,20 +41,22 @@
"file-extension": "^4.0.5",
"filesize": "^6.1.0",
"hashlru": "^2.3.0",
"i18next": "^19.9.0",
"i18next-browser-languagedetector": "^6.0.1",
"i18next-chained-backend": "^2.0.1",
"i18next-http-backend": "^1.1.1",
"i18next-icu": "^2.0.0",
"i18next": "^20.1.0",
"i18next-browser-languagedetector": "^6.1.0",
"i18next-chained-backend": "^2.1.0",
"i18next-http-backend": "^1.2.1",
"i18next-icu": "^2.0.3",
"i18next-localstorage-backend": "^3.1.2",
"internal-nav-helper": "^3.1.0",
"intl-messageformat": "^9.5.1",
"intl-messageformat": "^9.6.4",
"ip": "^1.1.5",
"ipfs-css": "^1.2.0",
"ipfs-css": "^1.3.0",
"ipfs-geoip": "^7.0.0",
"ipfs-http-client": "49.0.2",
"ipfs-provider": "^1.1.0",
"ipld-explorer-components": "^1.6.1",
"ipfs-provider": "^2.0.1",
"ipld-ethereum": "^5.0.1",
"ipld-explorer-components": "^2.0.0",
"ipld-git": "^0.6.4",
"is-binary": "^0.1.0",
"is-ipfs": "^3.0.0",
"it-all": "^1.0.5",
Expand All @@ -80,7 +82,7 @@
"react-faux-dom": "^4.5.0",
"react-helmet": "^5.2.1",
"react-hook-form": "^6.0.6",
"react-i18next": "^11.8.8",
"react-i18next": "^11.8.12",
"react-identicons": "^1.2.4",
"react-joyride": "^2.3.0",
"react-loadable": "^5.5.0",
Expand Down
61 changes: 46 additions & 15 deletions src/bundles/ipfs-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import last from 'it-last'
import * as Enum from './enum'
import { perform } from './task'

// @ts-ignore
import ipldGit from 'ipld-git'
// @ts-ignore
import ipldEthereum from 'ipld-ethereum'

/**
* @typedef {import('ipfs').IPFSService} IPFSService
* @typedef {import('cids')} CID
Expand Down Expand Up @@ -202,20 +207,27 @@ const asMultiaddress = (value) => {

/**
* @typedef {Object} HTTPClientOptions
* @property {string} [url]
* @property {string} [host]
* @property {string} [port] - (e.g. '443', or '80')
* @property {string} [protocol] - (e.g 'https', 'http')
* @property {string} [apiPath] - ('/api/v0' by default)
* @property {Object<string, string>} [headers]
*/

/**
* @typedef {Object} IPFSProviderHttpClientOptions
* @property {Object} [ipld]
* @property {string|undefined} [url]
*/

/**
* Attempts to turn parse given input as an options object for ipfs-http-client.
* @param {string|object} value
* @returns {HTTPClientOptions|null}
*/
const asHttpClientOptions = (value) =>
typeof value === 'string' ? parseHTTPClientOptions(value) : readHTTPClinetOptions(value)
typeof value === 'string' ? parseHTTPClientOptions(value) : readHTTPClientOptions(value)

/**
*
Expand All @@ -224,19 +236,17 @@ const asHttpClientOptions = (value) =>
const parseHTTPClientOptions = (input) => {
// Try parsing and reading as json
try {
return readHTTPClinetOptions(JSON.parse(input))
return readHTTPClientOptions(JSON.parse(input))
} catch (_) {}

// turn URL with inlined basic auth into client options object
try {
const uri = new URL(input)
const { username, password } = uri
const url = new URL(input)
const { username, password } = url
if (username && password) {
url.username = url.password = ''
return {
host: uri.hostname,
port: uri.port || (uri.protocol === 'https:' ? '443' : '80'),
protocol: uri.protocol.slice(0, -1), // trim out ':' at the end
apiPath: (uri.pathname !== '/' ? uri.pathname : 'api/v0'),
url: url.toString(),
headers: {
authorization: `Basic ${btoa(username + ':' + password)}`
}
Expand All @@ -251,9 +261,9 @@ const parseHTTPClientOptions = (input) => {
* @param {Object<string, any>} value
* @returns {HTTPClientOptions|null}
*/
const readHTTPClinetOptions = (value) => {
const readHTTPClientOptions = (value) => {
// https://github.com/ipfs/js-ipfs/tree/master/packages/ipfs-http-client#importing-the-module-and-usage
if (value && (value.host || value.apiPath || value.protocol || value.port || value.headers)) {
if (value && (!!value.url || value.host || value.apiPath || value.protocol || value.port || value.headers)) {
return value
} else {
return null
Expand Down Expand Up @@ -367,12 +377,33 @@ const actions = {
* @returns {function(Context):Promise<InitResult>}
*/
doInitIpfs: () => perform('IPFS_INIT',
/**
* @param {Context} context
* @returns {Promise<InitResult>}
*/
/**
* @param {Context} context
* @returns {Promise<InitResult>}
*/
async (context) => {
const { apiAddress } = context.getState().ipfs
/** @type {IPFSProviderHttpClientOptions} */
let ipfsOptions = {
ipld: {
formats: [
...Object.values(ipldEthereum),
ipldGit
]
}
}

if (typeof apiAddress === 'string') {
ipfsOptions = {
...ipfsOptions,
url: apiAddress
}
} else {
ipfsOptions = {
...apiAddress,
...ipfsOptions
}
}

const result = await getIpfs({
// @ts-ignore - TS can't seem to infer connectionTest option
Expand All @@ -391,7 +422,7 @@ const actions = {
},
loadHttpClientModule: () => HttpClient,
providers: [
providers.httpClient({ apiAddress })
providers.httpClient(ipfsOptions)
]
})

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/explore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe('Explore screen', () => {
await page.goto(webuiUrl + `#/explore/${cid}`, { waitUntil: 'networkidle0' })
await page.waitForSelector(`a[href="#/explore/${cid}"]`)
// expect node type
await expect(page).toMatch('DAG Node')
await expect(page).toMatch('Raw Block')
// expect cid details
await expect(page).toMatch('base32 - cidv1 - raw - sha2-256-256-46532c71d1b730e168548410ddbb4186a2c3c0659e915b19d47f373ec6c5174a')
await expect(page).toMatch('base32 - cidv1 - raw - sha2-256~256~46532C71D1B730E168548410DDBB4186A2C3C0659E915B19D47F373EC6C5174A')
})
})
12 changes: 3 additions & 9 deletions test/e2e/remote-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ const basicAuthConnectionConfirmation = async (user, password, proxyPort) => {
await expectPeerIdOnStatusPage(ipfsd.api)
// (2) go to Settings and confirm API string includes expected JSON config
const apiOptions = JSON.stringify({
protocol: 'http',
host: '127.0.0.1',
port: `${proxyPort}`,
url: `http://127.0.0.1:${proxyPort}/`,
headers: {
authorization: `Basic ${nodeBtoa(user + ':' + password)}`
}
Expand Down Expand Up @@ -230,9 +228,7 @@ describe('API with CORS and Basic Auth', () => {

it('should work when localStorage[ipfsApi] is set to a JSON string with a custom ipfs-http-client config', async () => {
const apiOptions = JSON.stringify({
protocol: 'http',
host: '127.0.0.1',
port: `${proxyPort}`,
url: `http://127.0.0.1:${proxyPort}/`,
headers: {
authorization: `Basic ${nodeBtoa(user + ':' + password)}`
}
Expand All @@ -249,9 +245,7 @@ describe('API with CORS and Basic Auth', () => {

it('should work when JSON with ipfs-http-client config is entered at the Settings page', async () => {
const apiOptions = JSON.stringify({
protocol: 'http',
host: '127.0.0.1',
port: `${proxyPort}`,
url: `http://127.0.0.1:${proxyPort}/`,
headers: {
authorization: `Basic ${nodeBtoa(user + ':' + password)}`
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"jsx": "react",
"jsx": "react-jsx",
"baseUrl": ".",
"module": "esnext"
},
Expand Down