Skip to content

Commit

Permalink
Add peer count
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 committed Oct 12, 2020
1 parent e61074e commit a98b15e
Show file tree
Hide file tree
Showing 14 changed files with 755 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/actions/ClientActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as sel from "selectors";
import eq from "lodash/fp/eq";
import {
getNextAddressAttempt,
getPeerInfo,
publishUnminedTransactionsAttempt
} from "./ControlActions";
import {
Expand Down Expand Up @@ -62,6 +63,7 @@ const startWalletServicesTrigger = () => (dispatch, getState) =>
dispatch(getAccountMixerServiceAttempt());
}
await dispatch(getNextAddressAttempt(0));
await dispatch(getPeerInfo());
await dispatch(getTicketPriceAttempt());
await dispatch(getNetworkAttempt());
await dispatch(refreshStakepoolPurchaseInformation());
Expand Down
14 changes: 14 additions & 0 deletions app/actions/ControlActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,17 @@ export const getAccountExtendedKeyAttempt = (accountNumber) => (
})
.catch((error) => dispatch({ error, type: GETACCOUNTEXTENDEDKEY_FAILED }));
};

export const GETPEERINFO_ATTEMPT = "GETPEERINFO_ATTEMPT";
export const GETPEERINFO_FAILED = "GETPEERINFO_FAILED";
export const GETPEERINFO_SUCCESS = "GETPEERINFO_SUCCESS";

export const getPeerInfo = () => (dispatch, getState) => {
dispatch({ type: GETPEERINFO_ATTEMPT });
return wallet.getPeerInfo(getState().grpc.walletService)
.then(resp => {
const peersCount = resp.wrappers_[1].length;
dispatch({ type: GETPEERINFO_SUCCESS, peersCount });
})
.catch((error) => dispatch({ type: GETPEERINFO_FAILED, error }));
};
15 changes: 13 additions & 2 deletions app/components/SideBar/Logo/Logo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const Logo = React.memo(
onReduceSideBar,
onExpandSideBar,
isWatchingOnly,
accountMixerRunning
accountMixerRunning,
peersCount
}) => (
<div
className={expandSideBar ? style.logo : style.reducedLogo}>
className={expandSideBar ? style.logo : style.reducedLogo}
>
{isWatchingOnly && (
<Tooltip
text={
Expand All @@ -32,6 +34,15 @@ const Logo = React.memo(
!expandSideBar ? style.hamburger : isTestNet ? TESTNET : MAINNET
}
/>
<Tooltip
text={
<T
id="sidebar.peersCount"
m="Peers Count"
/>
}>
<div className={style.peersCount}>{peersCount}</div>
</Tooltip>
{accountMixerRunning && (
<Tooltip
text={
Expand Down
15 changes: 15 additions & 0 deletions app/components/SideBar/Logo/Logo.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
opacity: 0.7;
}

.peersCount {
border-radius: 50%;
width: 10px;
height: 12px;
margin-top: 4px;

background: #fff;
border: 1px solid var(--white-border);
color: var(--sidebar-menu-link);;
text-align: center;
padding-bottom: 4px;

font-size: 7pt;
}

@media screen and (max-width: 768px) {
.logo {
flex-direction: row-reverse;
Expand Down
6 changes: 4 additions & 2 deletions app/components/SideBar/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const SideBar = () => {
onReduceSideBar,
rescanAttempt,
rescanCancel,
isSPV
isSPV,
peersCount
} = useSideBar();

return (
Expand All @@ -44,7 +45,8 @@ const SideBar = () => {
onReduceSideBar,
onExpandSideBar,
isWatchingOnly,
accountMixerRunning
accountMixerRunning,
peersCount
}}
/>
<div className={style.sidebarMain}>
Expand Down
11 changes: 5 additions & 6 deletions app/components/SideBar/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import * as sba from "../../actions/SidebarActions";
export function useSideBar() {
const [isShowingAccounts, setIsShowingAccounts] = useState(false);

const onShowAccounts = useCallback(() => setIsShowingAccounts(true), []);
const onHideAccounts = useCallback(() => setIsShowingAccounts(false), []);

const isTestNet = useSelector(sel.isTestNet);
const balances = useSelector(sel.balances);
const currentBlockHeight = useSelector(sel.currentBlockHeight);
Expand All @@ -21,6 +18,7 @@ export function useSideBar() {
const accountMixerRunning = useSelector(sel.getAccountMixerRunning);
const rescanRequest = useSelector(sel.rescanRequest);
const isSPV = useSelector(sel.isSPV);
const peersCount = useSelector(sel.getPeersCount);

const dispatch = useDispatch();

Expand All @@ -39,8 +37,8 @@ export function useSideBar() {

return {
isShowingAccounts,
onShowAccounts,
onHideAccounts,
onShowAccounts: () => setIsShowingAccounts(true),
onHideAccounts: () => setIsShowingAccounts(false),
isTestNet,
balances,
currentBlockHeight,
Expand All @@ -55,6 +53,7 @@ export function useSideBar() {
onReduceSideBar,
rescanAttempt,
rescanCancel,
isSPV
isSPV,
peersCount
};
}
4 changes: 3 additions & 1 deletion app/connectors/walletContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { selectorMap } from "fp";
import * as ga from "actions/GovernanceActions";
import { getPeerInfo } from "actions/ControlActions";
import * as sel from "selectors";

const mapStateToProps = selectorMap({
Expand All @@ -12,7 +13,8 @@ const mapStateToProps = selectorMap({
const mapDispatchToProps = (dispatch) =>
bindActionCreators(
{
compareInventory: ga.compareInventory
compareInventory: ga.compareInventory,
getPeerInfo
},
dispatch
);
Expand Down
9 changes: 8 additions & 1 deletion app/containers/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ const pageAnimation = {
class Wallet extends React.Component {
constructor(props) {
super(props);
const { compareInventory, politeiaEnabled } = props;
const { compareInventory, politeiaEnabled, getPeerInfo } = props;
// Compare politeias inventory and update proposal list if they are different
// every 1 minute.
this.fetchPoliteiaInventory = this.props.setInterval(() => {
if (politeiaEnabled) {
compareInventory();
}
}, 60000);
// Get peer info every 1 minute, so we can no if there are no available
// peers.
this.props.setInterval(() => {
if (politeiaEnabled) {
getPeerInfo();
}
}, 60000);
}

render() {
Expand Down
19 changes: 18 additions & 1 deletion app/middleware/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ service WalletService {
rpc BestBlock (BestBlockRequest) returns (BestBlockResponse);
rpc Spender (SpenderRequest) returns (SpenderResponse);
rpc GetCFilters (GetCFiltersRequest) returns (stream GetCFiltersResponse);
rpc GetPeerInfo(GetPeerInfoRequest) returns (GetPeerInfoResponse);

// Notifications
rpc TransactionNotifications (TransactionNotificationsRequest) returns (stream TransactionNotificationsResponse);
Expand Down Expand Up @@ -1184,4 +1185,20 @@ message coinjoinTxsSumByAcct {

message GetCoinjoinOutputspByAcctResponse {
repeated coinjoinTxsSumByAcct data = 1;
}
}

message GetPeerInfoRequest {}

message GetPeerInfoResponse {
message PeerInfo {
int32 id = 1;
string addr = 2;
string addr_local = 3;
string services = 4;
uint32 version = 5;
string sub_ver = 6;
int64 starting_height = 7;
int32 ban_score = 8;
}
repeated PeerInfo peer_info = 1;
}
33 changes: 33 additions & 0 deletions app/middleware/walletrpc/api_grpc_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,28 @@ function deserialize_walletrpc_GetCoinjoinOutputspByAcctResponse(buffer_arg) {
return api_pb.GetCoinjoinOutputspByAcctResponse.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_walletrpc_GetPeerInfoRequest(arg) {
if (!(arg instanceof api_pb.GetPeerInfoRequest)) {
throw new Error('Expected argument of type walletrpc.GetPeerInfoRequest');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_walletrpc_GetPeerInfoRequest(buffer_arg) {
return api_pb.GetPeerInfoRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_walletrpc_GetPeerInfoResponse(arg) {
if (!(arg instanceof api_pb.GetPeerInfoResponse)) {
throw new Error('Expected argument of type walletrpc.GetPeerInfoResponse');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_walletrpc_GetPeerInfoResponse(buffer_arg) {
return api_pb.GetPeerInfoResponse.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_walletrpc_GetRawBlockRequest(arg) {
if (!(arg instanceof api_pb.GetRawBlockRequest)) {
throw new Error('Expected argument of type walletrpc.GetRawBlockRequest');
Expand Down Expand Up @@ -1925,6 +1947,17 @@ ping: {
responseSerialize: serialize_walletrpc_GetCFiltersResponse,
responseDeserialize: deserialize_walletrpc_GetCFiltersResponse,
},
getPeerInfo: {
path: '/walletrpc.WalletService/GetPeerInfo',
requestStream: false,
responseStream: false,
requestType: api_pb.GetPeerInfoRequest,
responseType: api_pb.GetPeerInfoResponse,
requestSerialize: serialize_walletrpc_GetPeerInfoRequest,
requestDeserialize: deserialize_walletrpc_GetPeerInfoRequest,
responseSerialize: serialize_walletrpc_GetPeerInfoResponse,
responseDeserialize: deserialize_walletrpc_GetPeerInfoResponse,
},
// Notifications
transactionNotifications: {
path: '/walletrpc.WalletService/TransactionNotifications',
Expand Down
Loading

0 comments on commit a98b15e

Please sign in to comment.