Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Enrici committed Feb 25, 2019
2 parents 4a3fd21 + 5a9e9a1 commit 0716f83
Show file tree
Hide file tree
Showing 56 changed files with 2,204 additions and 1,491 deletions.
2,170 changes: 1,021 additions & 1,149 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metronome-desktop-wallet",
"version": "1.2.0",
"version": "1.3.0",
"author": {
"name": "Autonomous Software",
"email": "info@autonomous.sh",
Expand Down Expand Up @@ -35,7 +35,7 @@
"electron-context-menu": "0.9.1",
"electron-debug": "1.5.0",
"electron-is-dev": "0.3.0",
"electron-log": "2.2.17",
"electron-log": "3.0.1",
"electron-settings": "3.2.0",
"electron-unhandled": "1.1.0",
"electron-updater": "2.23.3",
Expand All @@ -44,8 +44,8 @@
"json-stringify-safe": "5.0.1",
"lodash": "4.17.11",
"metronome-contracts": "2.0.0",
"metronome-wallet-core": "2.0.1",
"metronome-wallet-ui-logic": "2.1.0",
"metronome-wallet-core": "2.0.2",
"metronome-wallet-ui-logic": "3.2.0",
"nedb": "1.8.0",
"p-timeout": "2.0.1",
"qrcode.react": "0.7.2",
Expand Down
21 changes: 20 additions & 1 deletion patches/web3-core-method+1.0.0-beta.37.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
patch-package
--- a/node_modules/web3-core-method/src/index.js
+++ b/node_modules/web3-core-method/src/index.js
@@ -533,7 +533,16 @@ Method.prototype.buildCall = function() {
@@ -200,6 +200,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
intervalId = null,
receiptJSON = '',
gasProvided = (_.isObject(payload.params[0]) && payload.params[0].gas) ? payload.params[0].gas : null,
+ isContractCall = _.isObject(payload.params[0]) && !!payload.params[0].data,
isContractDeployment = _.isObject(payload.params[0]) &&
payload.params[0].data &&
payload.params[0].from &&
@@ -348,8 +349,8 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
if (!isContractDeployment && !promiseResolved) {

if(!receipt.outOfGas &&
- (!gasProvided || gasProvided !== receipt.gasUsed) &&
- (receipt.status === true || receipt.status === '0x1' || typeof receipt.status === 'undefined')) {
+ (!gasProvided || gasProvided !== utils.numberToHex(receipt.gasUsed) || !isContractCall || (isContractCall && receipt.events)) &&
+ (receipt.status === true || receipt.status === '0x1' || receipt.status === null || typeof receipt.status === 'undefined')) {
defer.eventEmitter.emit('receipt', receipt);
defer.resolve(receipt);

@@ -533,7 +534,16 @@ Method.prototype.buildCall = function() {

// If wallet was found, sign tx, and send using sendRawTransaction
if (wallet && wallet.privateKey) {
Expand Down
12 changes: 12 additions & 0 deletions patches/web3-eth-accounts+1.0.0-beta.37.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
patch-package
--- a/node_modules/web3-eth-accounts/src/index.js
+++ b/node_modules/web3-eth-accounts/src/index.js
@@ -69,7 +69,7 @@ var Accounts = function Accounts() {
var _ethereumCall = [
new Method({
name: 'getId',
- call: 'net_version',
+ call: 'eth_chainId',
params: 0,
outputFormatter: utils.hexToNumber
}),
29 changes: 29 additions & 0 deletions public/config/etcMordenLocal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const MetronomeContracts = require('metronome-contracts')
const contracts = MetronomeContracts.morden

module.exports = {
displayName: 'Morden (Local)',
chainId: 2,
symbol: 'ETC',

// contracts addresses
tokenPorterAddress: contracts.TokenPorter.address,
converterAddress: contracts.AutonomousConverter.address,
validatorAddress: contracts.Validator.address,
metTokenAddress: contracts.METToken.address,
auctionAddress: contracts.Auctions.address,

// urls
explorerUrl: 'https://mordenexplorer.ethertrack.io/tx/{{hash}}',
indexerUrl: 'http://localhost:3015',
metApiUrl: 'http://localhost:3012/',
wsApiUrl: 'ws://localhost:8556',

// defauls
coinDefaultGasLimit: '21000',
metDefaultGasLimit: '250000',
defaultGasPrice: '1000000000',
maxGasPrice: '20000000000000000'
}
6 changes: 3 additions & 3 deletions public/config/ethMainnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const MetronomeContracts = require('metronome-contracts')
const contracts = MetronomeContracts.mainnet

module.exports = {
displayName: 'Ethereum', // visible in select control
displayName: 'Ethereum',
chainId: 1,
symbol: 'ETH', // visible next to amounts
symbol: 'ETH',

// contracts addresses
tokenPorterAddress: contracts.TokenPorter.address,
Expand All @@ -16,7 +16,7 @@ module.exports = {
auctionAddress: contracts.Auctions.address,

// urls
explorerUrl: 'https://explorer.metronome.io',
explorerUrl: 'https://etherscan.io/tx/{{hash}}',
indexerUrl: 'https://indexer.metronome.io',
metApiUrl: 'https://api.metronome.io/',
wsApiUrl: 'wss://eth.wallet.metronome.io:8546',
Expand Down
6 changes: 3 additions & 3 deletions public/config/ethRopstenLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const MetronomeContracts = require('metronome-contracts')
const contracts = MetronomeContracts.ropsten

module.exports = {
displayName: 'Ropsten (Local)', // visible in select control
displayName: 'Ropsten (Local)',
chainId: 3,
symbol: 'ETH', // visible next to amounts
symbol: 'ETH',

// contracts addresses
tokenPorterAddress: contracts.TokenPorter.address,
Expand All @@ -16,7 +16,7 @@ module.exports = {
auctionAddress: contracts.Auctions.address,

// urls
explorerUrl: 'http://localhost:3004',
explorerUrl: 'https://ropsten.etherscan.io/tx/{{hash}}',
indexerUrl: 'http://localhost:3005',
metApiUrl: 'http://localhost:3002/',
wsApiUrl: 'ws://localhost:8546',
Expand Down
4 changes: 2 additions & 2 deletions public/main/client/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const logger = require('electron-log')
const logger = require('../../logger.js')

const { getPasswordHash, setPasswordHash } = require('./settings')
const {
Expand All @@ -12,8 +12,8 @@ function setPassword (password) {
const passwordHash = getPasswordHash()
if (!passwordHash) {
logger.info('No password set, using current as default')
return hash(password).then(setPasswordHash)
}
return hash(password).then(setPasswordHash)
}

function isValidPassword (password) {
Expand Down
2 changes: 1 addition & 1 deletion public/main/client/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const { app } = require('electron')
const { promisify } = require('util')
const { sum, upperFirst } = require('lodash')
const Datastore = require('nedb')
const logger = require('electron-log')
const path = require('path')

const logger = require('../../logger')
const config = require('../../config')

const promisifyMethods = methods =>
Expand Down
66 changes: 52 additions & 14 deletions public/main/client/handlers/multi-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,42 @@ function onLoginSubmit (data, cores) {
})
}

const findCore = (cores, chain) => cores.find(e => e.chain === chain)
const findCoreByChainName = (cores, chain) => cores.find(e => e.chain === chain)

const findCoreBySymbol = (cores, ticker) =>
cores.find(e => e.config.symbol === ticker)

function getPortFees (data, cores) {
const exportCore = findCore(cores, data.chain)
const exportCore = findCoreByChainName(cores, data.chain)
return singleCore
.getExportMetFee(data, exportCore)
.then(fee =>
singleCore
.estimateExportMetGas(Object.assign({}, data, { fee }), exportCore)
.getExportGasLimit(Object.assign({}, data, { fee }), exportCore)
.then(({ gasLimit }) => ({ exportGasLimit: gasLimit, fee }))
)
}

const withMerkleRoot = fn =>
function (data, cores) {
const exportCore = findCoreBySymbol(cores, data.originChain)
const importCore = findCoreByChainName(cores, data.chain)
return singleCore
.getMerkleRoot(data.burnSequence, exportCore)
.then(function (root) {
const importData = Object.assign({}, data, { root })
return fn(importData, importCore)
})
}

const importMetronome = (data, cores) =>
withMerkleRoot(singleCore.importMetronome)(data, cores)

const getImportMetGas = (data, cores) =>
withMerkleRoot(singleCore.getImportGasLimit)(data, cores)

function portMetronome (data, cores) {
const exportCore = findCore(cores, data.chain)
const exportCore = findCoreByChainName(cores, data.chain)
const exportData = Object.assign({}, data, {
destinationChain: config.chains[data.destinationChain].symbol,
destinationMetAddress: config.chains[data.destinationChain].metTokenAddress,
Expand All @@ -75,19 +96,20 @@ function portMetronome (data, cores) {
return singleCore
.exportMetronome(exportData, exportCore)
.then(function ({ receipt }) {
const parsedExportReceipt = flatten(Object.keys(receipt.events)
.filter(e => !receipt.events[e].event) // Filter already parsed event keys
.map(e => receipt.events[e]) // Get not parsed events
.map(e => exportCore.coreApi.explorer.tryParseEventLog(e))) // Try to parse each event
.find(e => e.parsed.event === 'LogExportReceipt') // Get LogExportReceipt event
const parsedExportReceipt = flatten(
Object.keys(receipt.events)
.filter(e => !receipt.events[e].event) // Filter already parsed event keys
.map(e => receipt.events[e]) // Get not parsed events
.map(e => exportCore.coreApi.explorer.tryParseEventLog(e)) // Try to parse each event
).find(e => e.parsed.event === 'LogExportReceipt') // Get LogExportReceipt event
if (!parsedExportReceipt || !parsedExportReceipt.parsed) {
return Promise.reject(
new WalletError('There was an error trying to parse export receipt')
)
}
const { returnValues } = parsedExportReceipt.parsed
const importCore = findCore(cores, data.destinationChain)
const importData = Object.assign({}, data, {
const importCore = findCoreByChainName(cores, data.destinationChain)
const importData = {
blockTimestamp: returnValues.blockTimestamp,
burnSequence: returnValues.burnSequence,
currentBurnHash: returnValues.currentBurnHash,
Expand All @@ -101,15 +123,31 @@ function portMetronome (data, cores) {
originChain: config.chains[data.chain].symbol,
previousBurnHash: returnValues.prevBurnHash,
supply: returnValues.supplyOnAllChains,
value: returnValues.amountToBurn
})
return singleCore.importMetronome(importData, importCore)
value: returnValues.amountToBurn,
password: data.password,
walletId: data.walletId
}
return singleCore
.getMerkleRoot(returnValues.burnSequence, exportCore)
.then(function (root) {
Object.assign(importData, { root })
return singleCore
.getImportGasLimit(importData, importCore)
.then(({ gasLimit }) =>
singleCore.importMetronome(
Object.assign({}, importData, { gas: gasLimit }),
importCore
)
)
})
})
}

module.exports = {
onboardingCompleted,
recoverFromMnemonic,
importMetronome,
getImportMetGas,
portMetronome,
onLoginSubmit,
getPortFees
Expand Down
18 changes: 17 additions & 1 deletion public/main/client/handlers/no-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

const restart = require('../electron-restart')
const dbManager = require('../database')
const logger = require('electron-log')
const logger = require('../../../logger')
const storage = require('../storage')
const auth = require('../auth')
const wallet = require('../wallet')

const validatePassword = data => auth.isValidPassword(data)

Expand All @@ -18,8 +19,23 @@ function clearCache () {

const persistState = data => storage.persistState(data).then(() => true)

function changePassword ({ oldPassword, newPassword }) {
return validatePassword(oldPassword)
.then(function (isValid) {
if (isValid) {
wallet.getWallets().forEach(function (walletId) {
const seed = wallet.getSeed(walletId, oldPassword)
auth.setPassword(newPassword)
wallet.setSeed(seed, newPassword)
})
}
return isValid
})
}

module.exports = {
validatePassword,
changePassword,
persistState,
clearCache
}
17 changes: 8 additions & 9 deletions public/main/client/handlers/single-core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const logger = require('electron-log')
const pTimeout = require('p-timeout')

const logger = require('../../../logger')
const auth = require('../auth')
const config = require('../../../config')
const wallet = require('../wallet')
Expand Down Expand Up @@ -114,7 +114,7 @@ const sendMet = (data, { coreApi }) =>
const getExportMetFee = (data, { coreApi }) =>
coreApi.metronome.getExportMetFee(data)

const estimateExportMetGas = (data, { coreApi }) =>
const getExportGasLimit = (data, { coreApi }) =>
coreApi.metronome.estimateExportMetGas(
Object.assign({}, data, {
destinationChain: config.chains[data.destinationChain].symbol,
Expand All @@ -124,7 +124,7 @@ const estimateExportMetGas = (data, { coreApi }) =>
})
)

const estimateImportMetGas = (data, { coreApi }) =>
const getImportGasLimit = (data, { coreApi }) =>
coreApi.metronome.estimateImportMetGas(data)

const exportMetronome = (data, core) =>
Expand All @@ -133,30 +133,29 @@ const exportMetronome = (data, core) =>
const importMetronome = (data, core) =>
withAuth(core.coreApi.metronome.importMet)(data, core)

// TODO: Implement retry method
// eslint-disable-next-line no-unused-vars
const retryImport = (data, core) => Promise.resolve({})
const getMerkleRoot = (data, { coreApi }) =>
coreApi.metronome.getMerkleRoot(data)

module.exports = {
refreshAllTransactions,
getConvertCoinEstimate,
getConvertCoinGasLimit,
getConvertMetEstimate,
getConvertMetGasLimit,
estimateExportMetGas,
estimateImportMetGas,
refreshTransaction,
getAuctionGasLimit,
getExportGasLimit,
getImportGasLimit,
getTokensGasLimit,
getExportMetFee,
exportMetronome,
importMetronome,
getMerkleRoot,
buyMetronome,
createWallet,
getGasLimit,
getGasPrice,
convertCoin,
retryImport,
convertMet,
openWallet,
sendMet,
Expand Down
Loading

0 comments on commit 0716f83

Please sign in to comment.