2021-02-04 19:15:23 +01:00
|
|
|
import log from 'loglevel';
|
2021-03-01 16:15:42 +01:00
|
|
|
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { valuesFor } from '../app/helpers/utils/util';
|
2016-05-03 23:32:22 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function txHelper(
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
personalMsgs,
|
|
|
|
decryptMsgs,
|
|
|
|
encryptionPublicKeyMsgs,
|
|
|
|
typedMessages,
|
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2020-11-03 00:41:28 +01:00
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('tx-helper called with params:');
|
2020-11-03 00:41:28 +01:00
|
|
|
log.debug({
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
personalMsgs,
|
|
|
|
decryptMsgs,
|
|
|
|
encryptionPublicKeyMsgs,
|
|
|
|
typedMessages,
|
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2017-02-21 08:33:21 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const txValues = network
|
2021-03-01 16:15:42 +01:00
|
|
|
? valuesFor(unapprovedTxs).filter((txMeta) =>
|
|
|
|
transactionMatchesNetwork(txMeta, chainId, network),
|
2020-11-03 00:41:28 +01:00
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
: valuesFor(unapprovedTxs);
|
|
|
|
log.debug(`tx helper found ${txValues.length} unapproved txs`);
|
2017-09-29 18:24:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const msgValues = valuesFor(unapprovedMsgs);
|
|
|
|
log.debug(`tx helper found ${msgValues.length} unsigned messages`);
|
|
|
|
let allValues = txValues.concat(msgValues);
|
2017-09-29 18:24:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const personalValues = valuesFor(personalMsgs);
|
2020-11-03 00:41:28 +01:00
|
|
|
log.debug(
|
|
|
|
`tx helper found ${personalValues.length} unsigned personal messages`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
allValues = allValues.concat(personalValues);
|
2017-09-29 18:24:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const decryptValues = valuesFor(decryptMsgs);
|
|
|
|
log.debug(`tx helper found ${decryptValues.length} decrypt requests`);
|
|
|
|
allValues = allValues.concat(decryptValues);
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const encryptionPublicKeyValues = valuesFor(encryptionPublicKeyMsgs);
|
2020-11-03 00:41:28 +01:00
|
|
|
log.debug(
|
|
|
|
`tx helper found ${encryptionPublicKeyValues.length} encryptionPublicKey requests`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
allValues = allValues.concat(encryptionPublicKeyValues);
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const typedValues = valuesFor(typedMessages);
|
|
|
|
log.debug(`tx helper found ${typedValues.length} unsigned typed messages`);
|
|
|
|
allValues = allValues.concat(typedValues);
|
2017-09-29 18:24:08 +02:00
|
|
|
|
2017-07-25 02:27:27 +02:00
|
|
|
allValues = allValues.sort((a, b) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return a.time - b.time;
|
|
|
|
});
|
2017-02-23 01:23:13 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return allValues;
|
2017-10-21 21:06:39 +02:00
|
|
|
}
|