Skip to content

Commit

Permalink
records: tree status relative to update (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Apr 20, 2022
1 parent 6874d02 commit b8fe29d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
8 changes: 7 additions & 1 deletion app/components/Blocktime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export default class Blocktime extends Component {
height: PropTypes.number.isRequired,
className: PropTypes.string,
fromNow: PropTypes.bool,
prefix: PropTypes.bool,
format: PropTypes.string,
};

static defaultProps = {
className: '',
fromNow: false,
prefix: false,
format: 'YYYY-MM-DD',
};

Expand All @@ -41,8 +43,12 @@ export default class Blocktime extends Component {

const delta = this.props.height - this.props.currentHeight;
const end = moment().add(delta * AVERAGE_BLOCK_TIME);

if (this.props.fromNow) {
return '~' + end.toNow(true);
return '~'
+ (delta > 0) ?
end.fromNow(!this.props.prefix)
: end.toNow(!this.props.prefix);
}

return end.format(this.props.format);
Expand Down
32 changes: 25 additions & 7 deletions app/components/Records/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { clientStub as aClientStub } from '../../background/analytics/client';
import './records.scss';
import {clearDeeplinkParams} from "../../ducks/app";
import {deserializeRecord} from '../../utils/recordHelpers'
import {I18nContext} from "../../utils/i18n";

const analytics = aClientStub(() => require('electron').ipcRenderer);

Expand All @@ -27,6 +28,8 @@ const DEFAULT_RESOURCE = {
};

export class Records extends Component {
static contextType = I18nContext;

static propTypes = {
name: PropTypes.string.isRequired,
resource: PropTypes.object,
Expand Down Expand Up @@ -244,17 +247,32 @@ export class Records extends Component {
}

renderTreeUpdateInfo() {
const {t} = this.context;
const { currentHeight } = this.props;
const network = Network.get(this.props.network);
const nextTreeUpdateBlock = this.props.currentHeight + (network.names.treeInterval - this.props.currentHeight % network.names.treeInterval);
const { treeInterval } = network.names;

// Next Tree Update Block (w.r.t. current height)
let block = currentHeight + (treeInterval - (currentHeight % treeInterval));
let text = 'treeUpdateGeneric';

// If last transaction was an UPDATE, then relative block
const { height, covenant } = this.props.domain?.lastTx || {};
if (
height &&
(covenant.action === 'UPDATE' || covenant.action === 'REGISTER')
) {
block = height + (treeInterval - (height % treeInterval));

text =
currentHeight < block
? 'treeUpdateFuture'
: 'treeUpdatePast';
}

return (
<div className="tree-update">
Next tree update: Block {nextTreeUpdateBlock} (
<Blocktime
height={nextTreeUpdateBlock}
fromNow={true}
/>
)
{t(text)} {block} (<Blocktime height={block} fromNow prefix />)
</div>
);
}
Expand Down
24 changes: 17 additions & 7 deletions app/ducks/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const getNameInfo = name => async (dispatch) => {
let bids = [];
let reveals = [];
let winner = null;
let lastTx = null;
let isOwner = false;
let walletHasName = false;

Expand All @@ -89,6 +90,7 @@ export const getNameInfo = name => async (dispatch) => {
bids,
reveals,
winner,
lastTx,
isOwner,
walletHasName,
},
Expand All @@ -114,12 +116,20 @@ export const getNameInfo = name => async (dispatch) => {
const buyOutput = buyTx.outputs[info.owner.index];
const coin = await walletClient.getCoin(info.owner.hash, info.owner.index);
isOwner = !!coin;
if (coin && coin.covenant.action === 'TRANSFER') {
const {network} = await nodeClient.getInfo();
info.transferTo = Address.fromHash(
Buffer.from(coin.covenant.items[3], 'hex'),
Number(coin.covenant.items[2])
).toString(network);

if (coin) {
lastTx = {
height: coin.height,
covenant: coin.covenant,
}

if (coin.covenant.action === 'TRANSFER') {
const {network} = await nodeClient.getInfo();
info.transferTo = Address.fromHash(
Buffer.from(coin.covenant.items[3], 'hex'),
Number(coin.covenant.items[2])
).toString(network);
}
}

winner = {
Expand All @@ -130,7 +140,7 @@ export const getNameInfo = name => async (dispatch) => {

dispatch({
type: SET_NAME,
payload: {name, start, info, bids, reveals, winner, isOwner, walletHasName},
payload: {name, start, info, bids, reveals, winner, lastTx, isOwner, walletHasName},
});
};

Expand Down
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@
"transferSuccess": "Your transfer request is submitted! Please wait around 15 minutes for it to be confirmed.",
"transferring": "Transferring",
"transferringTo": "Transferring to",
"treeUpdateFuture": "Will be committed after block",
"treeUpdateGeneric": "Next tree update: Block",
"treeUpdatePast": "Committed in tree as of block",
"txDescBid": "Placed Bid",
"txDescClaim": "Claimed Reserved Name",
"txDescCoinbase": "Mining Reward",
Expand Down

0 comments on commit b8fe29d

Please sign in to comment.