Skip to content

Commit

Permalink
Fix bugs introduced in recent updates (#137)
Browse files Browse the repository at this point in the history
* Reword open auction error

* Fix spendable balance delta for register covenants

* Load watchlist only when booting or switching network

Since we moved bids into the global store, watchlist items were
broken. We need to keep the watchlist in the store, and just update
it when we need to. All the relevant components will expect the
data to be in the store rather than loading individually in
componentWillMount().
  • Loading branch information
pinheadmz committed May 13, 2020
1 parent 1aa8d54 commit 159ee32
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 31 deletions.
9 changes: 7 additions & 2 deletions app/components/Transactions/Transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const UPDATE = 'UPDATE';
const RENEW = 'RENEW';
const REDEEM = 'REDEEM';
const COINBASE = 'COINBASE';
const REGISTER = 'REGISTER';

class Transaction extends Component {
static propTypes = {
Expand Down Expand Up @@ -45,7 +46,8 @@ class Transaction extends Component {
(tx.type === RECEIVE
|| tx.type === COINBASE
|| tx.type === REVEAL
|| tx.type === REDEEM)
|| tx.type === REDEEM
|| tx.type === REGISTER)
&& !tx.pending,
'transaction__number--neutral':
(tx.type === UPDATE
Expand Down Expand Up @@ -93,6 +95,9 @@ class Transaction extends Component {
} else if (tx.type === UPDATE) {
description = 'Updated Record';
content = this.formatDomain(tx.meta.domain);
} else if (tx.type === REGISTER) {
description = 'Registered Name';
content = this.formatDomain(tx.meta.domain);
} else if (tx.type === RENEW) {
description = 'Renewed Domain';
content = this.formatDomain(tx.meta.domain);
Expand Down Expand Up @@ -123,7 +128,7 @@ class Transaction extends Component {
{tx.pending ? <em>(pending)</em> : null}
{' '}
{
tx.type === RECEIVE || tx.type === COINBASE || tx.type === REDEEM || tx.type === REVEAL ? '+'
tx.type === RECEIVE || tx.type === COINBASE || tx.type === REDEEM || tx.type === REVEAL || tx.type === REGISTER ? '+'
: tx.type === UPDATE || tx.type === RENEW || tx.type === OPEN ? ''
: '-'
}
Expand Down
17 changes: 8 additions & 9 deletions app/ducks/backgroundMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import isEqual from 'lodash.isequal';
import { SET_NODE_INFO, SET_FEE_INFO, NEW_BLOCK_STATUS } from './nodeReducer';
import { getNameInfo } from './names';
import { getYourBids } from './bids';
import { getWatching } from './watching';
import { fetchTransactions, fetchWallet } from './walletActions';

export function createBackgroundMonitor() {
Expand Down Expand Up @@ -103,14 +104,6 @@ function difference(setA, setB) {

export const onNewBlock = () => async (dispatch, getState) => {
let state = getState();
const isInitialized = await getInitializationState(state.node.network);
if (!isInitialized) {
return;
}

if (!state.wallet.initialized || !state.node.isRunning) {
return;
}

dispatch({type: NEW_BLOCK_STATUS, payload: 'Updating fees...'});
const newFees = await nodeClient.getFees();
Expand All @@ -130,7 +123,13 @@ export const onNewBlock = () => async (dispatch, getState) => {
const bids = state.bids.yourBids;
for (const bid of bids) {
const name = bid.name;
dispatch({type: NEW_BLOCK_STATUS, payload: `Loading name: ${name}`});
dispatch({type: NEW_BLOCK_STATUS, payload: `Loading bids: ${name}`});
await dispatch(getNameInfo(name));
}

const watch = state.watching.names;
for (const name of watch) {
dispatch({type: NEW_BLOCK_STATUS, payload: `Loading watchlist: ${name}`});
await dispatch(getNameInfo(name));
}

Expand Down
8 changes: 7 additions & 1 deletion app/ducks/node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { clientStub } from '../background/node/client';
import { getNetwork, setNetwork } from '../db/system';
import { fetchWallet } from './walletActions';
import { fetchWallet, fetchTransactions } from './walletActions';
import { getWatching } from './watching';
import * as logger from '../utils/logClient';
import { onNewBlock } from './backgroundMonitor';

import {
END_NETWORK_CHANGE,
SET_NODE_INFO,
Expand Down Expand Up @@ -37,6 +40,9 @@ export const start = (network) => async (dispatch, getState) => {
});
await dispatch(setNodeInfo());
await dispatch(fetchWallet());
await dispatch(fetchTransactions());
await dispatch(getWatching(network));
await dispatch(onNewBlock());
} catch (error) {
dispatch({
type: START_ERROR,
Expand Down
16 changes: 9 additions & 7 deletions app/ducks/walletActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,22 @@ async function parseInputsOutputs(net, tx) {

covAction = covenant.action;

// Special case for reveals, indicate how much
// Special case for reveals and registers, indicate how much
// spendable balance is returning to the wallet
// as change from the mask on the bid.
if (covenant.action === 'REVEAL')
// as change from the mask on the bid, or the difference
// between the highest and second-highest bid.
if (covenant.action === 'REVEAL'
|| covenant.action === 'REGISTER') {
covValue += tx.inputs[i].value - output.value;
else
} else {
covValue += output.value;
}

// Renewals and Updates have a value, but it doesn't
// affect the spendable balance of the wallet.
// TODO: Transfer, Finalize, etc will eventually need to go here
if (covenant.action === 'RENEW'
|| covenant.action === 'REGISTER'
|| covenant.action === 'UPDATE'){
|| covenant.action === 'UPDATE') {
covValue = 0;
}

Expand Down Expand Up @@ -347,7 +349,7 @@ async function parseCovenant(net, covenant) {
};
case 'REGISTER':
return {
type: 'UPDATE',
type: 'REGISTER',
meta: {
domain: await nameByHash(net, covenant),
data: covenant.items[2],
Expand Down
9 changes: 6 additions & 3 deletions app/ducks/watching.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as namesDb from '../db/names';
import { getWatchlist, saveToWatchlist } from '../db/watching';
import { getNameInfo } from './names';

const SET_WATCHLIST = 'app/watching/setWatchlist';

Expand All @@ -10,7 +11,7 @@ const initialState = {
export const getWatching = (network) => async dispatch => {
const data = await getWatchlist(network);

dispatch({
await dispatch({
type: SET_WATCHLIST,
payload: Array.isArray(data) ? data : [],
});
Expand All @@ -23,10 +24,12 @@ export const addName = (name, network) => async dispatch => {
await namesDb.storeName(name);
await saveToWatchlist(network, result);

dispatch({
await dispatch({
type: SET_WATCHLIST,
payload: result,
});

await dispatch(getNameInfo(name));
};

export const removeName = (name, network) => async dispatch => {
Expand All @@ -35,7 +38,7 @@ export const removeName = (name, network) => async dispatch => {
result = result.filter(n => n !== name);
await saveToWatchlist(network, result);

dispatch({
await dispatch({
type: SET_WATCHLIST,
payload: result,
})
Expand Down
1 change: 0 additions & 1 deletion app/pages/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class App extends Component {
async componentDidMount() {
this.setState({isLoading: true});
await this.props.startNode();
await this.props.onNewBlock();
this.props.watchActivity();
setTimeout(() => this.setState({isLoading: false}), 1000)
}
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Auction/BidActionPanel/OpenBid.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OpenBid extends Component {
} catch (e) {
console.error(e);
logger.error(`Error received from OpenBid - sendOpen]\n\n${e.message}\n${e.stack}\n`);
this.props.showError(`Failed to open bid: ${e.message}`);
this.props.showError(`Failed to open auction: ${e.message}`);
}
};

Expand Down
2 changes: 0 additions & 2 deletions app/pages/Auction/BidActionPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class BidActionPanel extends Component {
}),
}),
network: PropTypes.string.isRequired,
getWatching: PropTypes.func.isRequired,
watchDomain: PropTypes.func.isRequired,
unwatchDomain: PropTypes.func.isRequired,
};
Expand Down Expand Up @@ -135,7 +134,6 @@ export default withRouter(
network: state.node.network,
}),
dispatch => ({
getWatching: (network) => dispatch(watchingActions.getWatching(network)),
watchDomain: (name, network) => dispatch(watchingActions.addName(name, network)),
unwatchDomain: (name, network) => dispatch(watchingActions.removeName(name, network)),
}),
Expand Down
5 changes: 0 additions & 5 deletions app/pages/Watching/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class Watching extends Component {
analytics.screenView('Watching');
}

componentWillMount() {
this.props.getWatching(this.props.network);
}

handleOnChange = e => this.setState({query: e.target.value});

onDownload = () => {
Expand Down Expand Up @@ -207,7 +203,6 @@ export default withRouter(
network: state.node.network,
}),
dispatch => ({
getWatching: (network) => dispatch(watchingActions.getWatching(network)),
addName: (name, network) => dispatch(watchingActions.addName(name, network)),
removeName: (name, network) => dispatch(watchingActions.removeName(name, network)),
}),
Expand Down

0 comments on commit 159ee32

Please sign in to comment.