aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/ens-ipfs/setup.js
diff options
context:
space:
mode:
authorpldespaigne <pldespaigne@cascade8.com>2019-04-04 23:15:57 +0800
committerpldespaigne <pldespaigne@cascade8.com>2019-04-04 23:15:57 +0800
commitdc4c40414e6fb76d3c56aa771752dd6ade61c280 (patch)
treee98da4985ed226b05103a66def82fff7f38167e0 /app/scripts/lib/ens-ipfs/setup.js
parentb26a59dbbe2666640529f7ae0a86bd5a2da3f607 (diff)
downloadtangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.gz
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.tar.zst
tangerine-wallet-browser-dc4c40414e6fb76d3c56aa771752dd6ade61c280.zip
issue#5742
Diffstat (limited to 'app/scripts/lib/ens-ipfs/setup.js')
-rw-r--r--app/scripts/lib/ens-ipfs/setup.js36
1 files changed, 21 insertions, 15 deletions
diff --git a/app/scripts/lib/ens-ipfs/setup.js b/app/scripts/lib/ens-ipfs/setup.js
index df756d0f7..43194afbd 100644
--- a/app/scripts/lib/ens-ipfs/setup.js
+++ b/app/scripts/lib/ens-ipfs/setup.js
@@ -38,23 +38,29 @@ function setupEnsIpfsResolver ({ provider }) {
async function attemptResolve ({ tabId, name, path, search }) {
extension.tabs.update(tabId, { url: `loading.html` })
try {
- const ipfsContentId = await resolveEnsToIpfsContentId({ provider, name })
- const url = `https://gateway.ipfs.io/ipfs/${ipfsContentId}${path}${search || ''}`
- try {
- // check if ipfs gateway has result
- const response = await fetch(url, { method: 'HEAD' })
- // if failure, redirect to 404 page
- if (response.status !== 200) {
- extension.tabs.update(tabId, { url: '404.html' })
- return
+ let url = '400.html'
+ const {type, hash} = await resolveEnsToIpfsContentId({ provider, name })
+ if (type === 'ipfs-ns') {
+ url = `https://gateway.ipfs.io/ipfs/${hash}${path}${search || ''}`
+ try {
+ // check if ipfs gateway has result
+ const response = await fetch(url, { method: 'HEAD' })
+ // if failure, redirect to 404 page
+ if (response.status !== 200) {
+ extension.tabs.update(tabId, { url: '404.html' })
+ return
+ }
+ // otherwise redirect to the correct page
+ extension.tabs.update(tabId, { url })
+ } catch (err) {
+ console.warn(err)
+ // if HEAD fetch failed, redirect so user can see relevant error page
+ extension.tabs.update(tabId, { url })
}
- // otherwise redirect to the correct page
- extension.tabs.update(tabId, { url })
- } catch (err) {
- console.warn(err)
- // if HEAD fetch failed, redirect so user can see relevant error page
- extension.tabs.update(tabId, { url })
+ } else if (type === 'swarm-ns') {
+ url = `https://swarm-gateways.net/bzz:/${hash}${path}${search || ''}`
}
+ extension.tabs.update(tabId, { url })
} catch (err) {
console.warn(err)
extension.tabs.update(tabId, { url: `error.html?name=${name}` })