Rename files

This commit is contained in:
Yung chieh Tsai 2018-05-24 23:08:02 +07:00
parent 86ead431c3
commit 829deacb57
10 changed files with 119 additions and 1912 deletions

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>404</title>
<title>MetaMask</title>
<style>
*{
padding: 0;

View File

@ -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>
*{

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>Portal Network</title>
<title>MetaMask Loading</title>
<style>
#div-logo {
position: absolute;

View File

@ -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>

View File

@ -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)
}
//

View File

@ -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/']})
}

View File

@ -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/"]})
}

View File

@ -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)

59
app/unsupport.html Normal file
View File

@ -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>

File diff suppressed because it is too large Load Diff