Skip to content

Commit

Permalink
watchlist: refresh name state on new blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Jan 30, 2023
1 parent af51b5b commit 281e7ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/ducks/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export const DROPDOWN_TYPES = [
{label: RECORD_TYPE.TXT},
];

export const fetchName = name => async (dispatch, getState) => {
export const fetchName = (name, force) => async (dispatch, getState) => {
const {names} = getState();
const existing = names[name];

if (existing && existing.info) {
if (!force && existing && existing.info) {
return;
}

Expand Down
19 changes: 16 additions & 3 deletions app/pages/YourBids/BidStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router';
import { connect } from 'react-redux';
import throttle from 'lodash.throttle';
import {
isReveal,
isClosed,
Expand All @@ -18,18 +19,29 @@ class BidStatus extends Component {
static propTypes = {
name: PropTypes.string.isRequired,
domain: PropTypes.object,
height: PropTypes.number.isRequired,
address: PropTypes.string.isRequired,
fetchName: PropTypes.func.isRequired,
};

static contextType = I18nContext;

componentDidMount() {
if (!this.props.domain) {
this.props.fetchName();
this.fetchName();
}

componentDidUpdate(prevProps, prevState) {
if (this.props.height !== prevProps.height) {
this.fetchName();
}
}

fetchName = throttle(() => {
if (this.props.name) {
this.props.fetchName();
}
}, 10*1000, {leading: true, trailing: true}); // 10 seconds

isSold = () => isClosed(this.props.domain);
isReveal = () => isReveal(this.props.domain);
isOwned = () => {
Expand Down Expand Up @@ -148,11 +160,12 @@ export default withRouter(
const name = state.names[ownProps.name];
return {
domain: name,
height: state.node.chain.height,
address: state.wallet.receiveAddress,
};
},
(dispatch, ownProps) => ({
fetchName: () => dispatch(namesActions.fetchName(ownProps.name)),
fetchName: () => dispatch(namesActions.fetchName(ownProps.name, true)),
}),
)(BidStatus)
);

0 comments on commit 281e7ba

Please sign in to comment.