1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-24 02:58:09 +01:00
metamask-extension/app/scripts/controllers/network/util.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-04-12 23:17:36 +02:00
const {
ROPSTEN,
RINKEBY,
KOVAN,
MAINNET,
2019-04-17 19:34:49 +02:00
GOERLI,
2018-04-12 23:17:36 +02:00
ROPSTEN_CODE,
2019-09-11 00:51:34 +02:00
RINKEBY_CODE,
2018-04-12 23:17:36 +02:00
KOVAN_CODE,
2019-04-17 19:34:49 +02:00
GOERLI_CODE,
2018-04-12 23:17:36 +02:00
ROPSTEN_DISPLAY_NAME,
RINKEBY_DISPLAY_NAME,
KOVAN_DISPLAY_NAME,
MAINNET_DISPLAY_NAME,
2019-04-17 19:34:49 +02:00
GOERLI_DISPLAY_NAME,
2018-04-12 23:17:36 +02:00
} = require('./enums')
const networkToNameMap = {
[ROPSTEN]: ROPSTEN_DISPLAY_NAME,
[RINKEBY]: RINKEBY_DISPLAY_NAME,
[KOVAN]: KOVAN_DISPLAY_NAME,
[MAINNET]: MAINNET_DISPLAY_NAME,
2019-04-17 19:34:49 +02:00
[GOERLI]: GOERLI_DISPLAY_NAME,
2018-04-12 23:17:36 +02:00
[ROPSTEN_CODE]: ROPSTEN_DISPLAY_NAME,
2019-09-11 00:51:34 +02:00
[RINKEBY_CODE]: RINKEBY_DISPLAY_NAME,
2018-04-12 23:17:36 +02:00
[KOVAN_CODE]: KOVAN_DISPLAY_NAME,
2019-04-17 19:34:49 +02:00
[GOERLI_CODE]: GOERLI_DISPLAY_NAME,
2018-04-12 23:17:36 +02:00
}
const getNetworkDisplayName = key => networkToNameMap[key]
function formatTxMetaForRpcResult (txMeta) {
return {
'blockHash': txMeta.txReceipt ? txMeta.txReceipt.blockHash : null,
'blockNumber': txMeta.txReceipt ? txMeta.txReceipt.blockNumber : null,
'from': txMeta.txParams.from,
'gas': txMeta.txParams.gas,
'gasPrice': txMeta.txParams.gasPrice,
'hash': txMeta.hash,
'input': txMeta.txParams.data || '0x',
'nonce': txMeta.txParams.nonce,
'to': txMeta.txParams.to,
'transactionIndex': txMeta.txReceipt ? txMeta.txReceipt.transactionIndex : null,
'value': txMeta.txParams.value || '0x0',
'v': txMeta.v,
'r': txMeta.r,
's': txMeta.s,
}
}
2018-04-12 23:17:36 +02:00
module.exports = {
getNetworkDisplayName,
formatTxMetaForRpcResult,
2018-04-12 23:17:36 +02:00
}