Skip to content

Commit

Permalink
sentry cleaning (#1894)
Browse files Browse the repository at this point in the history
* fromTokenMinimalUnit

* notification tx

* getActiveTabUrl

* _finishedCallback

* getBlockExplorerName

* iftx
  • Loading branch information
estebanmino authored Oct 20, 2020
1 parent c6d5090 commit d936595
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
16 changes: 11 additions & 5 deletions app/components/UI/Notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,17 @@ class Notification extends PureComponent {
tx = paymentChannelTransaction
? { paymentChannelTransaction, transaction: {} }
: this.props.transactions.find(({ id }) => id === this.props.transaction.id);
const decoded = await decodeTransaction({ ...this.props, tx });
transactionElement = decoded[0];
transactionDetails = decoded[1];
const existingGasPrice = tx.transaction ? tx.transaction.gasPrice : '0x0';
this.existingGasPriceDecimal = parseInt(existingGasPrice === undefined ? '0x0' : existingGasPrice, 16);
// THIS NEEDS REFACTOR
if (tx) {
const decoded = await decodeTransaction({ ...this.props, tx });
transactionElement = decoded[0];
transactionDetails = decoded[1];
const existingGasPrice = tx.transaction ? tx.transaction.gasPrice : '0x0';
this.existingGasPriceDecimal = parseInt(
existingGasPrice === undefined ? '0x0' : existingGasPrice,
16
);
}
}
// eslint-disable-next-line react/no-did-update-set-state
await this.setState({
Expand Down
4 changes: 3 additions & 1 deletion app/core/NotificationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ class NotificationManager {
this._handleTransactionsWatchListUpdate(transactionMeta);
// If it fails we hide the pending tx notification
this._hideTransactionNotification(transactionMeta.id);
this._transactionsWatchTable[transactionMeta.transaction.nonce].length &&
const transaction = this._transactionsWatchTable[transactionMeta.transaction.nonce];
transaction &&
transaction.length &&
setTimeout(() => {
// Then we show the error notification
this._showNotification({
Expand Down
1 change: 1 addition & 0 deletions app/util/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ export function getBlockExplorerName(blockExplorerUrl) {
const hostname = new URL(blockExplorerUrl).hostname;
if (!hostname) return undefined;
const tempBlockExplorerName = hostname.split('.')[0];
if (!tempBlockExplorerName || !tempBlockExplorerName[0]) return undefined;
return tempBlockExplorerName[0].toUpperCase() + tempBlockExplorerName.slice(1);
}
3 changes: 2 additions & 1 deletion app/util/number.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Collection of utility functions for consistent formatting and conversion
*/
import { BN } from 'ethereumjs-util';
import { addHexPrefix, BN } from 'ethereumjs-util';
import convert from 'ethjs-unit';
import { util } from '@metamask/controllers';
import numberToBN from 'number-to-bn';
Expand Down Expand Up @@ -36,6 +36,7 @@ export function fromWei(value = 0, unit = 'ether') {
* @returns {string} - String containing the new number
*/
export function fromTokenMinimalUnit(minimalInput, decimals) {
minimalInput = addHexPrefix(Number(minimalInput).toString(16));
let minimal = numberToBN(minimalInput);
const negative = minimal.lt(new BN(0));
const base = toBN(Math.pow(10, decimals).toString());
Expand Down
7 changes: 7 additions & 0 deletions app/util/number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ describe('Number utils :: fromTokenMinimalUnit', () => {
expect(fromTokenMinimalUnit(new BN('1337'), 0)).toEqual('1337');
expect(fromTokenMinimalUnit(new BN('1337'), 18)).toEqual('0.000000000000001337');
});

it('fromTokenMinimalUnit using exp number', () => {
expect(fromTokenMinimalUnit(1e22, 6)).toEqual('10000000000000000');
expect(fromTokenMinimalUnit(1e2, 6)).toEqual('0.0001');
expect(fromTokenMinimalUnit(1e16, 6)).toEqual('10000000000');
expect(fromTokenMinimalUnit(1e18, 18)).toEqual('1');
});
});

describe('Number utils :: toTokenMinimalUnit', () => {
Expand Down
8 changes: 6 additions & 2 deletions app/util/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export async function getTransactionActionKey(transaction) {
* @returns {string} - Transaction type message
*/
export async function getActionKey(tx, selectedAddress, ticker, paymentChannelTransaction) {
if (tx.isTransfer) {
if (tx && tx.isTransfer) {
const selfSent = safeToChecksumAddress(tx.transaction.from) === selectedAddress;
const translationKey = selfSent ? 'transactions.self_sent_unit' : 'transactions.received_unit';
// Third party sending wrong token symbol
Expand Down Expand Up @@ -415,5 +415,9 @@ export function getNormalizedTxState(state) {
}

export function getActiveTabUrl({ browser = {} }) {
return browser.tabs && browser.activeTab ? browser.tabs.find(({ id }) => id === browser.activeTab).url : '';
let tab;
if (browser.tabs && browser.activeTab) {
tab = browser.tabs.find(({ id }) => id === browser.activeTab);
}
return tab ? tab.url : '';
}

0 comments on commit d936595

Please sign in to comment.