Skip to content

Commit

Permalink
fix desktop wallet page
Browse files Browse the repository at this point in the history
  • Loading branch information
feruzm committed May 30, 2023
1 parent b06448e commit 6752ad7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
77 changes: 39 additions & 38 deletions src/common/components/rc-info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,8 @@ export const ResourceCreditsInfo = (props: any) => {
const [transferAmount, setTransferAmount] = useState(0);
const [customJsonAmount, setCustomJsonAmount] = useState(0);

useEffect(() => {
findRcAccounts(account.name)
.then((r) => {
const outGoing = r.map((a: any) => a.delegated_rc);
const delegated = outGoing[0];
const formatOutGoing: any = rcFormatter(delegated);
setDelegated(formatOutGoing);
const availableResourceCredit: any = r.map((a: any) => Number(a.rc_manabar.current_mana));
const inComing: any = r.map((a: any) => Number(a.received_delegated_rc));
const formatIncoming = rcFormatter(inComing);
const totalRc = Number(availableResourceCredit) + Number(inComing);
setReceivedDelegation(formatIncoming);
setResourceCredit(totalRc);

const rcOperationsCost = async () => {
const rcStats: any = await getRcOperationStats();
const operationCosts = rcStats.rc_stats.ops;
const commentCost = operationCosts.comment_operation.avg_cost;
const transferCost = operationCosts.transfer_operation.avg_cost;
const voteCost = operationCosts.vote_operation.avg_cost;
const customJsonOperationsCosts = operationCosts.custom_json_operation.avg_cost;

const commentCount: number = Math.ceil(Number(availableResourceCredit) / commentCost);
const votetCount: number = Math.ceil(Number(availableResourceCredit) / voteCost);
const transferCount: number = Math.ceil(Number(availableResourceCredit) / transferCost);
const customJsonCount: number = Math.ceil(
Number(availableResourceCredit) / customJsonOperationsCosts
);
setCommentAmount(commentCount);
setVoteAmount(votetCount);
setTransferAmount(transferCount);
setCustomJsonAmount(customJsonCount);
};
rcOperationsCost();
})
.catch(console.log);
}, []);

const showModal = () => {
fetchRCData();
setShowRcInfo(true);
};

Expand Down Expand Up @@ -114,6 +77,44 @@ export const ResourceCreditsInfo = (props: any) => {
setShowConfirmDelete(false);
};

const fetchRCData = () => {
findRcAccounts(account.name)
.then((r) => {
const outGoing = r.map((a: any) => a.delegated_rc);
const delegated = outGoing[0];
const formatOutGoing: any = rcFormatter(delegated);
setDelegated(formatOutGoing);
const availableResourceCredit: any = r.map((a: any) => Number(a.rc_manabar.current_mana));
const inComing: any = r.map((a: any) => Number(a.received_delegated_rc));
const formatIncoming = rcFormatter(inComing);
const totalRc = Number(availableResourceCredit) + Number(inComing);
setReceivedDelegation(formatIncoming);
setResourceCredit(totalRc);

const rcOperationsCost = async () => {
const rcStats: any = await getRcOperationStats();
const operationCosts = rcStats.rc_stats.ops;
const commentCost = operationCosts.comment_operation.avg_cost;
const transferCost = operationCosts.transfer_operation.avg_cost;
const voteCost = operationCosts.vote_operation.avg_cost;
const customJsonOperationsCosts = operationCosts.custom_json_operation.avg_cost;

const commentCount: number = Math.ceil(Number(availableResourceCredit) / commentCost);
const votetCount: number = Math.ceil(Number(availableResourceCredit) / voteCost);
const transferCount: number = Math.ceil(Number(availableResourceCredit) / transferCost);
const customJsonCount: number = Math.ceil(
Number(availableResourceCredit) / customJsonOperationsCosts
);
setCommentAmount(commentCount);
setVoteAmount(votetCount);
setTransferAmount(transferCount);
setCustomJsonAmount(customJsonCount);
};
rcOperationsCost();
})
.catch(console.log);
};

return (
<div>
<div className="cursor-pointer d-flex flex-column mb-1" onClick={showModal}>
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/wallet-hive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class WalletHive extends BaseComponent<Props, State> {
tokenType
} = this.state;

if (!account.__loaded) {
if (!account?.__loaded) {
return null;
}

Expand Down

0 comments on commit 6752ad7

Please sign in to comment.