aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/404.html2
-rw-r--r--app/error.html2
-rw-r--r--app/loading.html2
-rw-r--r--app/no_mainnet.html59
-rw-r--r--app/scripts/background.js8
-rw-r--r--app/scripts/lib/ipfsContent.js36
-rw-r--r--app/scripts/lib/portalnetwork.js36
-rw-r--r--app/scripts/lib/resolver.js37
-rw-r--r--app/unsupport.html59
9 files changed, 119 insertions, 122 deletions
diff --git a/app/404.html b/app/404.html
index 2fbf1e311..0dbab69a7 100644
--- a/app/404.html
+++ b/app/404.html
@@ -1,6 +1,6 @@
<html>
<head>
- <title>404</title>
+ <title>MetaMask</title>
<style>
*{
padding: 0;
diff --git a/app/error.html b/app/error.html
index d4484d8e3..366b3d94a 100644
--- a/app/error.html
+++ b/app/error.html
@@ -1,6 +1,6 @@
<html>
<head>
- <title>Portal Network</title>
+ <title>MetaMask Error</title>
<link href="https://fonts.googleapis.com/css?family=Rokkitt" rel="stylesheet">
<style>
*{
diff --git a/app/loading.html b/app/loading.html
index bbf1c1b4e..aef5d9607 100644
--- a/app/loading.html
+++ b/app/loading.html
@@ -1,6 +1,6 @@
<html>
<head>
- <title>Portal Network</title>
+ <title>MetaMask Loading</title>
<style>
#div-logo {
position: absolute;
diff --git a/app/no_mainnet.html b/app/no_mainnet.html
deleted file mode 100644
index f90e6d397..000000000
--- a/app/no_mainnet.html
+++ /dev/null
@@ -1,59 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="UTF-8">
- <title>no_mainnet</title>
-</head>
-<style>
- *{
- padding: 0;
- margin: 0;
- box-sizing: border-box;
- }
- img{
- display: block;
- }
- html, body{
- display: flex;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
- }
- @keyframes logoAmin{
- from {transform: scale(1);}
- 50%{transform: scale(1.1);}
- to {transform: scale(1);}
- }
- .no_mainnet{
- width: 80%;
- height: auto;
- overflow: hidden;
- padding: 10px;
- }
- .no_mainnet > img{
- margin: 0 auto 31px auto;
- width: 136px;
- height: auto;
- animation: logoAmin 1s infinite linear;
- }
- .no_mainnet > h1{
- text-align: center;
- font-family: Gotham;
- font-size: 18px;
- font-weight: 500;
- font-style: normal;
- font-stretch: normal;
- line-height: normal;
- letter-spacing: 1.3px;
- color: #33559f;
- }
-
- </style>
-<body>
- <div class="no_mainnet">
- <img src="./images/cancel.png" alt="">
- <h1>ENS resolver only support on Ethereum mainnet</h1>
- </div>
-</body>
-</html> \ No newline at end of file
diff --git a/app/scripts/background.js b/app/scripts/background.js
index fc2ad5773..672a2dcac 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -25,7 +25,7 @@ const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics')
const EdgeEncryptor = require('./edge-encryptor')
const getFirstPreferredLangCode = require('./lib/get-first-preferred-lang-code')
const getObjStructure = require('./lib/getObjStructure')
-const pw = require('./lib/portalnetwork.js')
+const ipfsContent = require('./lib/ipfsContent.js')
const {
ENVIRONMENT_TYPE_POPUP,
@@ -61,9 +61,6 @@ const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY })
const localStore = new LocalStore()
let versionedData
-console.log('localStore', localStore);
-console.log('diskStore', diskStore);
-
// initialization flow
initialize().catch(log.error)
@@ -161,8 +158,7 @@ async function initialize () {
const initLangCode = await getFirstPreferredLangCode()
await setupController(initState, initLangCode)
log.debug('MetaMask initialization complete.')
- // porto network init
- pw(initState.NetworkController.provider);
+ ipfsContent(initState.NetworkController.provider)
}
//
diff --git a/app/scripts/lib/ipfsContent.js b/app/scripts/lib/ipfsContent.js
new file mode 100644
index 000000000..4d66745e9
--- /dev/null
+++ b/app/scripts/lib/ipfsContent.js
@@ -0,0 +1,36 @@
+const extension = require('extensionizer')
+const resolver = require('./resolver.js')
+
+module.exports = function (provider) {
+ extension.webRequest.onBeforeRequest.addListener(details => {
+ const name = details.url.substring(7, details.url.length - 1)
+ let clearTime = null
+ extension.tabs.getSelected(null, tab => {
+ extension.tabs.update(tab.id, { url: 'loading.html' })
+
+ clearTime = setTimeout(() => {
+ return extension.tabs.update(tab.id, { url: '404.html' })
+ }, 60000)
+
+ resolver.resolve(name, provider).then(ipfsHash => {
+ clearTimeout(clearTime)
+ let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash
+ return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => {
+ if (statusCode !== 200) return 'Local'
+ extension.tabs.update(tab.id, { url: url })
+ })
+ .catch(err => {
+ url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash
+ extension.tabs.update(tab.id, {url: url})
+ return err
+ })
+ })
+ .catch(err => {
+ clearTimeout(clearTime)
+ const url = err === 'unsupport' ? 'unsupport' : 'error'
+ extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`})
+ })
+ })
+ return { cancel: true }
+ }, {urls: ['*://*.eth/']})
+}
diff --git a/app/scripts/lib/portalnetwork.js b/app/scripts/lib/portalnetwork.js
deleted file mode 100644
index 977f17926..000000000
--- a/app/scripts/lib/portalnetwork.js
+++ /dev/null
@@ -1,36 +0,0 @@
-const extension = require('extensionizer')
-const resolver = require('./resolver.js');
-module.exports = function (provider) {
- extension.webRequest.onBeforeRequest.addListener(details => {
- let name = details.url.substring(7, details.url.length - 1);
- let clearTime = null;
- extension.tabs.getSelected(null, tab => {
- extension.tabs.update(tab.id, { url: "loading.html" });
-
- clearTime = setTimeout(() => {
- return extension.tabs.update(tab.id, { url: "404.html" });
- }, 60000);
-
- resolver.resolve(name, provider).then(ipfsHash => {
- clearTimeout(clearTime);
- let url = "https://gateway.ipfs.io/ipfs/" + ipfsHash;
- return fetch(url, { method: "HEAD" }).then(response => response.status).then(statusCode => {
- if (statusCode !== 200) return "Local"
- extension.tabs.update(tab.id, { url: url })
- })
- .catch(err => {
- url = "https://gateway.ipfs.io/ipfs/" + ipfsHash
- extension.tabs.update(tab.id, {url: url})
- return err
- })
- })
- .catch(err => {
- clearTimeout(clearTime);
- let nameWithoutTld = name.substring(0, name.lastIndexOf('.'))
- let url = err === "no_mainnet" ? "no_mainnet" : "error"
- extension.tabs.update(tab.id, {url: `${url}.html?name=${name}`})
- })
- })
- return { cancel: true }
- }, {urls: ["*://*.eth/"]})
-}
diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js
index 43ccec0cc..dec43c481 100644
--- a/app/scripts/lib/resolver.js
+++ b/app/scripts/lib/resolver.js
@@ -1,43 +1,44 @@
const namehash = require('eth-ens-namehash')
const multihash = require('multihashes')
-const REGISTRAR_ENS_MAIN_NET = "0x314159265dd8dbb310642f98f50c066173c1259b"
+const REGISTRAR_ENS_MAIN_NET = '0x314159265dd8dbb310642f98f50c066173c1259b'
const HttpProvider = require('ethjs-provider-http')
const Eth = require('ethjs-query')
const EthContract = require('ethjs-contract')
const registrarAbi = require('./contracts/registrar')
const resolverAbi = require('./contracts/resolver')
-function ens(name, provider) {
- // provider need mainnet
- let eth = new Eth(new HttpProvider(provider.rpcTarget))
- let hash = namehash.hash(name)
- let contract = new EthContract(eth)
- let Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET)
+
+function ens (name, provider) {
+ const eth = new Eth(new HttpProvider(provider.rpcTarget))
+ const hash = namehash.hash(name)
+ const contract = new EthContract(eth)
+ const Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET)
return new Promise((resolve, reject) => {
- if (provider.type !== "mainnet") reject('no_mainnet')
+ if (provider.type !== 'mainnet') reject('unsupport')
Registrar.resolver(hash).then((address) => {
if (address === '0x0000000000000000000000000000000000000000') {
reject(null)
} else {
- let Resolver = contract(resolverAbi).at(address["0"])
+ const Resolver = contract(resolverAbi).at(address['0'])
return Resolver.content(hash)
}
}).then((contentHash) => {
- if (contentHash["0"] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null)
- if (contentHash.ret !== "0x") {
- let hex = contentHash["0"].substring(2)
- let buf = multihash.fromHexString(hex)
- resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256')))
+ if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null)
+ if (contentHash.ret !== '0x') {
+ const hex = contentHash['0'].substring(2)
+ const buf = multihash.fromHexString(hex)
+ resolve(multihash.toB58String(buf))
} else {
- reject('fisk')
+ reject(null)
}
})
})
}
+
module.exports.resolve = function (name, provider) {
- let path = name.split(".");
- let tld = path[path.length - 1];
+ const path = name.split('.')
+ const tld = path[path.length - 1]
if (tld === 'eth') {
- return ens(name, provider);
+ return ens(name, provider)
} else {
return new Promise((resolve, reject) => {
reject(null)
diff --git a/app/unsupport.html b/app/unsupport.html
new file mode 100644
index 000000000..6f514eb17
--- /dev/null
+++ b/app/unsupport.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>MetaMask</title>
+ </head>
+ <style>
+ *{
+ padding: 0;
+ margin: 0;
+ box-sizing: border-box;
+ }
+ img{
+ display: block;
+ }
+ html, body{
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 100%;
+ }
+ @keyframes logoAmin{
+ from {transform: scale(1);}
+ 50%{transform: scale(1.1);}
+ to {transform: scale(1);}
+ }
+ .unsupport{
+ width: 80%;
+ height: auto;
+ overflow: hidden;
+ padding: 10px;
+ }
+ .unsupport > img{
+ margin: 0 auto 31px auto;
+ width: 136px;
+ height: auto;
+ animation: logoAmin 1s infinite linear;
+ }
+ .unsupport > h1{
+ text-align: center;
+ font-family: Gotham;
+ font-size: 18px;
+ font-weight: 500;
+ font-style: normal;
+ font-stretch: normal;
+ line-height: normal;
+ letter-spacing: 1.3px;
+ color: #33559f;
+ }
+
+ </style>
+ <body>
+ <div class="unsupport">
+ <img src="./images/cancel.png" alt="">
+ <h1>ENS resolver only support on Ethereum mainnet</h1>
+ </div>
+ </body>
+</html> \ No newline at end of file