parent
221d338340
commit
dae91d1a0f
@ -1,109 +0,0 @@ |
||||
const yo = require('yo-yo') |
||||
const remixLib = require('@remix-project/remix-lib') |
||||
const confirmDialog = require('./confirmDialog') |
||||
const modalCustom = require('./modal-dialog-custom') |
||||
const modalDialog = require('./modaldialog') |
||||
const typeConversion = remixLib.execution.typeConversion |
||||
const Web3 = require('web3') |
||||
|
||||
module.exports = { |
||||
getCallBacksWithContext: (udappUI, blockchain) => { |
||||
const callbacks = {} |
||||
callbacks.confirmationCb = confirmationCb |
||||
callbacks.continueCb = continueCb |
||||
callbacks.promptCb = promptCb |
||||
callbacks.udappUI = udappUI |
||||
callbacks.blockchain = blockchain |
||||
return callbacks |
||||
} |
||||
} |
||||
|
||||
const continueCb = function (error, continueTxExecution, cancelCb) { |
||||
if (error) { |
||||
const msg = typeof error !== 'string' ? error.message : error |
||||
modalDialog( |
||||
'Gas estimation failed', |
||||
yo` |
||||
<div>Gas estimation errored with the following message (see below). |
||||
The transaction execution will likely fail. Do you want to force sending? <br>${msg}</div> |
||||
`,
|
||||
{ |
||||
label: 'Send Transaction', |
||||
fn: () => continueTxExecution() |
||||
}, |
||||
{ |
||||
label: 'Cancel Transaction', |
||||
fn: () => cancelCb() |
||||
} |
||||
) |
||||
} else { |
||||
continueTxExecution() |
||||
} |
||||
} |
||||
|
||||
const promptCb = function (okCb, cancelCb) { |
||||
modalCustom.promptPassphrase('Passphrase requested', 'Personal mode is enabled. Please provide passphrase of account', '', okCb, cancelCb) |
||||
} |
||||
|
||||
const confirmationCb = function (network, tx, gasEstimation, continueTxExecution, cancelCb) { |
||||
const self = this |
||||
if (network.name !== 'Main') { |
||||
return continueTxExecution(null) |
||||
} |
||||
var amount = Web3.utils.fromWei(typeConversion.toInt(tx.value), 'ether') |
||||
var content = confirmDialog(tx, network, amount, gasEstimation, |
||||
(gasPrice, cb) => { |
||||
let txFeeText, priceStatus |
||||
// TODO: this try catch feels like an anti pattern, can/should be
|
||||
// removed, but for now keeping the original logic
|
||||
try { |
||||
var fee = Web3.utils.toBN(tx.gas).mul(Web3.utils.toBN(Web3.utils.toWei(gasPrice.toString(10), 'gwei'))) |
||||
txFeeText = ' ' + Web3.utils.fromWei(fee.toString(10), 'ether') + ' Ether' |
||||
priceStatus = true |
||||
} catch (e) { |
||||
txFeeText = ' Please fix this issue before sending any transaction. ' + e.message |
||||
priceStatus = false |
||||
} |
||||
cb(txFeeText, priceStatus) |
||||
}, |
||||
(cb) => { |
||||
self.blockchain.web3().eth.getGasPrice((error, gasPrice) => { |
||||
const warnMessage = ' Please fix this issue before sending any transaction. ' |
||||
if (error) { |
||||
return cb('Unable to retrieve the current network gas price.' + warnMessage + error) |
||||
} |
||||
try { |
||||
var gasPriceValue = Web3.utils.fromWei(gasPrice.toString(10), 'gwei') |
||||
cb(null, gasPriceValue) |
||||
} catch (e) { |
||||
cb(warnMessage + e.message, null, false) |
||||
} |
||||
}) |
||||
} |
||||
) |
||||
modalDialog( |
||||
'Confirm transaction', |
||||
content, |
||||
{ |
||||
label: 'Confirm', |
||||
fn: () => { |
||||
self.blockchain.config.setUnpersistedProperty( |
||||
'doNotShowTransactionConfirmationAgain', |
||||
content.querySelector('input#confirmsetting').checked |
||||
) |
||||
// TODO: check if this is check is still valid given the refactor
|
||||
if (!content.gasPriceStatus) { |
||||
cancelCb('Given transaction fee is not correct') |
||||
} else { |
||||
continueTxExecution(content.txFee) |
||||
} |
||||
} |
||||
}, |
||||
{ |
||||
label: 'Cancel', |
||||
fn: () => { |
||||
return cancelCb('Transaction canceled by user.') |
||||
} |
||||
} |
||||
) |
||||
} |
@ -1,64 +0,0 @@ |
||||
import { Storage } from '@remix-project/remix-lib' |
||||
import { joinPath } from './lib/helper' |
||||
import yo from 'yo-yo' |
||||
const modalDialogCustom = require('./app/ui/modal-dialog-custom') |
||||
/* |
||||
Migrating the files to the BrowserFS storage instead or raw localstorage |
||||
*/ |
||||
export default (fileProvider) => { |
||||
const fileStorage = new Storage('sol:') |
||||
const flag = 'status' |
||||
const fileStorageBrowserFS = new Storage('remix_browserFS_migration:') |
||||
if (fileStorageBrowserFS.get(flag) === 'done') return |
||||
fileStorage.keys().forEach((path) => { |
||||
if (path !== '.remix.config') { |
||||
const content = fileStorage.get(path) |
||||
fileProvider.set(path, content) |
||||
// TODO https://github.com/ethereum/remix-ide/issues/2377
|
||||
// fileStorage.remove(path) we don't want to remove it as we are still supporting the old version
|
||||
} |
||||
}) |
||||
fileStorageBrowserFS.set(flag, 'done') |
||||
} |
||||
|
||||
export async function migrateToWorkspace (fileManager, filePanel) { |
||||
const browserProvider = fileManager.getProvider('browser') |
||||
const workspaceProvider = fileManager.getProvider('workspace') |
||||
const files = await browserProvider.copyFolderToJson('/') |
||||
|
||||
if (Object.keys(files).length === 0) { |
||||
// we don't have any root file, only .workspaces
|
||||
// don't need to create a workspace
|
||||
throw new Error('No file to migrate') |
||||
} |
||||
|
||||
if (Object.keys(files).length === 1 && files['/.workspaces']) { |
||||
// we don't have any root file, only .workspaces
|
||||
// don't need to create a workspace
|
||||
throw new Error('No file to migrate') |
||||
} |
||||
|
||||
const workspaceName = 'workspace_migrated_' + Date.now() |
||||
await filePanel.processCreateWorkspace(workspaceName) |
||||
filePanel.getWorkspaces() // refresh list
|
||||
const workspacePath = joinPath('browser', workspaceProvider.workspacesPath, workspaceName) |
||||
await populateWorkspace(workspacePath, files, browserProvider) |
||||
return workspaceName |
||||
} |
||||
|
||||
const populateWorkspace = async (workspace, json, browserProvider) => { |
||||
for (const item in json) { |
||||
const isFolder = json[item].content === undefined |
||||
if (isFolder && item === '/.workspaces') continue // we don't want to replicate this one.
|
||||
if (isFolder) { |
||||
browserProvider.createDir(joinPath(workspace, item)) |
||||
await populateWorkspace(workspace, json[item].children, browserProvider) |
||||
} else { |
||||
await browserProvider.set(joinPath(workspace, item), json[item].content, (err) => { |
||||
if (err && err.message) { |
||||
modalDialogCustom.alert(yo`<div>There was an error migrating your files:${err.message} <div>Please use the ‘Download all Files' action, clear the local storage and re-import your files manually or use the 'Restore files' action.</div></div>`) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue