parent
c37fa3d924
commit
3c43c1d797
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,45 +1,45 @@ |
||||
let parser: any |
||||
self.onmessage = (e: MessageEvent) => { |
||||
const data: any = e.data |
||||
switch (data.cmd) { |
||||
case 'load': |
||||
{ |
||||
(self as any).importScripts(e.data.url) |
||||
// @ts-ignore
|
||||
parser = SolidityParser as any; |
||||
const data: any = e.data |
||||
switch (data.cmd) { |
||||
case 'load': |
||||
{ |
||||
(self as any).importScripts(e.data.url) |
||||
// @ts-ignore
|
||||
parser = SolidityParser as any; |
||||
|
||||
self.postMessage({ |
||||
cmd: 'loaded', |
||||
}) |
||||
break |
||||
} |
||||
self.postMessage({ |
||||
cmd: 'loaded', |
||||
}) |
||||
break |
||||
} |
||||
|
||||
case 'parse': |
||||
if (data.text && parser) { |
||||
case 'parse': |
||||
if (data.text && parser) { |
||||
|
||||
try { |
||||
let startTime = performance.now() |
||||
const blocks = parser.parseBlock(data.text, { loc: true, range: true, tolerant: true }) |
||||
const blockDuration = performance.now() - startTime |
||||
startTime = performance.now() |
||||
const ast = parser.parse(data.text, { loc: true, range: true, tolerant: true }) |
||||
const endTime = performance.now() |
||||
try { |
||||
let startTime = performance.now() |
||||
const blocks = parser.parseBlock(data.text, { loc: true, range: true, tolerant: true }) |
||||
const blockDuration = performance.now() - startTime |
||||
startTime = performance.now() |
||||
const ast = parser.parse(data.text, { loc: true, range: true, tolerant: true }) |
||||
const endTime = performance.now() |
||||
|
||||
self.postMessage({ |
||||
cmd: 'parsed', |
||||
timestamp: data.timestamp, |
||||
ast, |
||||
text: data.text, |
||||
file: data.file, |
||||
duration: endTime - startTime, |
||||
blockDuration, |
||||
blocks |
||||
}) |
||||
} catch (e) { |
||||
// do nothing
|
||||
} |
||||
self.postMessage({ |
||||
cmd: 'parsed', |
||||
timestamp: data.timestamp, |
||||
ast, |
||||
text: data.text, |
||||
file: data.file, |
||||
duration: endTime - startTime, |
||||
blockDuration, |
||||
blocks |
||||
}) |
||||
} catch (e) { |
||||
// do nothing
|
||||
} |
||||
|
||||
} |
||||
break |
||||
} |
||||
break |
||||
} |
||||
} |
@ -1,59 +1,59 @@ |
||||
import { Plugin } from '@remixproject/engine'; |
||||
|
||||
const profile = { |
||||
name: 'storage', |
||||
displayName: 'Storage', |
||||
description: 'Storage', |
||||
methods: ['getStorage', 'formatString'] |
||||
name: 'storage', |
||||
displayName: 'Storage', |
||||
description: 'Storage', |
||||
methods: ['getStorage', 'formatString'] |
||||
}; |
||||
|
||||
export class StoragePlugin extends Plugin { |
||||
constructor() { |
||||
super(profile); |
||||
constructor() { |
||||
super(profile); |
||||
} |
||||
|
||||
async getStorage() { |
||||
let storage = null |
||||
if ('storage' in navigator && 'estimate' in navigator.storage && (window as any).remixFileSystem.name !== 'localstorage') { |
||||
storage = await navigator.storage.estimate() |
||||
} else { |
||||
storage ={ |
||||
usage: parseFloat(this.calculateLocalStorage()) * 1000, |
||||
quota: 5000000, |
||||
} |
||||
} |
||||
|
||||
async getStorage() { |
||||
let storage = null |
||||
if ('storage' in navigator && 'estimate' in navigator.storage && (window as any).remixFileSystem.name !== 'localstorage') { |
||||
storage = await navigator.storage.estimate() |
||||
} else { |
||||
storage ={ |
||||
usage: parseFloat(this.calculateLocalStorage()) * 1000, |
||||
quota: 5000000, |
||||
} |
||||
} |
||||
const _paq = (window as any)._paq = (window as any)._paq || [] |
||||
_paq.push(['trackEvent', 'Storage', 'used', this.formatString(storage)]); |
||||
return storage |
||||
} |
||||
|
||||
formatString(storage) { |
||||
return `${this.formatBytes(storage.usage)} / ${this.formatBytes(storage.quota)}`; |
||||
const _paq = (window as any)._paq = (window as any)._paq || [] |
||||
_paq.push(['trackEvent', 'Storage', 'used', this.formatString(storage)]); |
||||
return storage |
||||
} |
||||
|
||||
formatString(storage) { |
||||
return `${this.formatBytes(storage.usage)} / ${this.formatBytes(storage.quota)}`; |
||||
} |
||||
|
||||
calculateLocalStorage() { |
||||
let _lsTotal = 0 |
||||
let _xLen; let _x |
||||
for (_x in localStorage) { |
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (!localStorage.hasOwnProperty(_x)) { |
||||
continue |
||||
} |
||||
_xLen = ((localStorage[_x].length + _x.length)) |
||||
_lsTotal += _xLen |
||||
} |
||||
return (_lsTotal / 1024).toFixed(2) |
||||
} |
||||
|
||||
calculateLocalStorage() { |
||||
let _lsTotal = 0 |
||||
let _xLen; let _x |
||||
for (_x in localStorage) { |
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (!localStorage.hasOwnProperty(_x)) { |
||||
continue |
||||
} |
||||
_xLen = ((localStorage[_x].length + _x.length)) |
||||
_lsTotal += _xLen |
||||
} |
||||
return (_lsTotal / 1024).toFixed(2) |
||||
} |
||||
|
||||
formatBytes(bytes: number, decimals = 2) { |
||||
if (bytes === 0) return '0 Bytes'; |
||||
formatBytes(bytes: number, decimals = 2) { |
||||
if (bytes === 0) return '0 Bytes'; |
||||
|
||||
const k = 1024; |
||||
const dm = decimals < 0 ? 0 : decimals; |
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
||||
const k = 1024; |
||||
const dm = decimals < 0 ? 0 : decimals; |
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k)); |
||||
const i = Math.floor(Math.log(bytes) / Math.log(k)); |
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; |
||||
} |
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; |
||||
} |
||||
} |
||||
|
@ -1,55 +1,55 @@ |
||||
import { InjectedProviderDefaultBase } from './injected-provider-default' |
||||
|
||||
export class InjectedL2Provider extends InjectedProviderDefaultBase {
|
||||
chainName: string |
||||
chainId: string |
||||
rpcUrls: Array<string> |
||||
chainName: string |
||||
chainId: string |
||||
rpcUrls: Array<string> |
||||
|
||||
constructor (profile: any, chainName: string, chainId: string, rpcUrls: Array<string>) { |
||||
super(profile) |
||||
this.chainName = chainName |
||||
this.chainId = chainId |
||||
this.rpcUrls = rpcUrls |
||||
} |
||||
constructor (profile: any, chainName: string, chainId: string, rpcUrls: Array<string>) { |
||||
super(profile) |
||||
this.chainName = chainName |
||||
this.chainId = chainId |
||||
this.rpcUrls = rpcUrls |
||||
} |
||||
|
||||
async init () { |
||||
await super.init() |
||||
if (this.chainName && this.rpcUrls && this.rpcUrls.length > 0) await addL2Network(this.chainName, this.chainId, this.rpcUrls) |
||||
else |
||||
throw new Error('Cannot add the L2 network to main injected provider') |
||||
return {} |
||||
} |
||||
async init () { |
||||
await super.init() |
||||
if (this.chainName && this.rpcUrls && this.rpcUrls.length > 0) await addL2Network(this.chainName, this.chainId, this.rpcUrls) |
||||
else |
||||
throw new Error('Cannot add the L2 network to main injected provider') |
||||
return {} |
||||
} |
||||
} |
||||
|
||||
export const addL2Network = async (chainName: string, chainId: string, rpcUrls: Array<string>) => { |
||||
try { |
||||
try { |
||||
await (window as any).ethereum.request({ |
||||
method: 'wallet_switchEthereumChain', |
||||
params: [{ chainId: chainId }], |
||||
}); |
||||
} catch (switchError) { |
||||
// This error code indicates that the chain has not been added to MetaMask.
|
||||
if (switchError.code === 4902) { |
||||
try { |
||||
await (window as any).ethereum.request({ |
||||
method: 'wallet_switchEthereumChain', |
||||
params: [{ chainId: chainId }], |
||||
method: 'wallet_addEthereumChain', |
||||
params: [ |
||||
{ |
||||
chainId: chainId, |
||||
chainName: chainName, |
||||
rpcUrls: rpcUrls, |
||||
}, |
||||
], |
||||
}); |
||||
} catch (switchError) { |
||||
// This error code indicates that the chain has not been added to MetaMask.
|
||||
if (switchError.code === 4902) { |
||||
try { |
||||
await (window as any).ethereum.request({ |
||||
method: 'wallet_addEthereumChain', |
||||
params: [ |
||||
{ |
||||
chainId: chainId, |
||||
chainName: chainName, |
||||
rpcUrls: rpcUrls, |
||||
}, |
||||
], |
||||
}); |
||||
|
||||
await (window as any).ethereum.request({ |
||||
method: 'wallet_switchEthereumChain', |
||||
params: [{ chainId: chainId }], |
||||
}); |
||||
} catch (addError) { |
||||
// handle "add" error
|
||||
} |
||||
} |
||||
// handle other "switch" errors
|
||||
await (window as any).ethereum.request({ |
||||
method: 'wallet_switchEthereumChain', |
||||
params: [{ chainId: chainId }], |
||||
}); |
||||
} catch (addError) { |
||||
// handle "add" error
|
||||
} |
||||
} |
||||
// handle other "switch" errors
|
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,14 @@ |
||||
const transactionDetailsLinks = { |
||||
Main: 'https://www.etherscan.io/tx/', |
||||
Rinkeby: 'https://rinkeby.etherscan.io/tx/', |
||||
Ropsten: 'https://ropsten.etherscan.io/tx/', |
||||
Kovan: 'https://kovan.etherscan.io/tx/', |
||||
Goerli: 'https://goerli.etherscan.io/tx/', |
||||
Sepolia: 'https://sepolia.etherscan.io/tx/' |
||||
Main: 'https://www.etherscan.io/tx/', |
||||
Rinkeby: 'https://rinkeby.etherscan.io/tx/', |
||||
Ropsten: 'https://ropsten.etherscan.io/tx/', |
||||
Kovan: 'https://kovan.etherscan.io/tx/', |
||||
Goerli: 'https://goerli.etherscan.io/tx/', |
||||
Sepolia: 'https://sepolia.etherscan.io/tx/' |
||||
} |
||||
|
||||
export function etherScanLink (network: string, hash: string): string { |
||||
if (transactionDetailsLinks[network]) { |
||||
return transactionDetailsLinks[network] + hash |
||||
} |
||||
if (transactionDetailsLinks[network]) { |
||||
return transactionDetailsLinks[network] + hash |
||||
} |
||||
} |
@ -1,26 +1,26 @@ |
||||
// const moduleID = require('./module-id.js')
|
||||
|
||||
module.exports = class registry { |
||||
constructor () { |
||||
this.state = {} |
||||
} |
||||
constructor () { |
||||
this.state = {} |
||||
} |
||||
|
||||
put ({ api, name }) { |
||||
// const serveruid = moduleID() + '.' + (name || '')
|
||||
if (this.state[name]) return this.state[name] |
||||
const server = { |
||||
// uid: serveruid,
|
||||
api |
||||
} |
||||
this.state[name] = { server } |
||||
return server |
||||
put ({ api, name }) { |
||||
// const serveruid = moduleID() + '.' + (name || '')
|
||||
if (this.state[name]) return this.state[name] |
||||
const server = { |
||||
// uid: serveruid,
|
||||
api |
||||
} |
||||
this.state[name] = { server } |
||||
return server |
||||
} |
||||
|
||||
get (name) { |
||||
// const clientuid = moduleID()
|
||||
const state = this.state[name] |
||||
if (!state) return |
||||
const server = state.server |
||||
return server |
||||
} |
||||
get (name) { |
||||
// const clientuid = moduleID()
|
||||
const state = this.state[name] |
||||
if (!state) return |
||||
const server = state.server |
||||
return server |
||||
} |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue