From 5939bb4e13e9c1c5d12767f192babaf410cf1aa4 Mon Sep 17 00:00:00 2001 From: kandrusyak Date: Fri, 9 Dec 2022 11:53:36 +0300 Subject: [PATCH] add unlock transaction --- .prettierrc | 1 + src/pages/services/Delegates.jsx | 14 ++- src/partials/finance/TransactionPanel.jsx | 68 +++++------- src/partials/finance/TransactionsTable.jsx | 12 +- .../finance/TransactionsTableItem.jsx | 17 +-- src/store/store.js | 105 ++++++------------ 6 files changed, 80 insertions(+), 137 deletions(-) diff --git a/.prettierrc b/.prettierrc index ae23c2e..69cb95e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -6,6 +6,7 @@ "endOfLine": "lf", "jsxBracketSameLine": false, "trailingComma": "es5", + "printWidth": 100, "overrides": [ { "files": "*.json", diff --git a/src/pages/services/Delegates.jsx b/src/pages/services/Delegates.jsx index c7a93f5..7eb32de 100644 --- a/src/pages/services/Delegates.jsx +++ b/src/pages/services/Delegates.jsx @@ -81,7 +81,11 @@ const Delegates = observer(() => { setCurrentDelegate(delegate)} + rowClick={(delegate) => + (lockedFor === 'Voiting' || + store.accountLockedVotesCanReturnSum[delegate.address]) && + setCurrentDelegate(delegate) + } /> {/*/!* Pagination *!/*/} @@ -99,9 +103,11 @@ const Delegates = observer(() => { transactionPanelOpen={!!currentDelegate} onClose={() => setCurrentDelegate(null)} delegate={currentDelegate || {}} - postTransaction={(address, amount) => - store.pushVoteTransaction(address, amount) - } + unlocking={lockedFor !== 'Voiting'} + postTransaction={(address, amount) => { + if (lockedFor === 'Voiting') store.pushVoteTransaction(address, amount); + else store.pushUnlockTransaction(address); + }} /> diff --git a/src/partials/finance/TransactionPanel.jsx b/src/partials/finance/TransactionPanel.jsx index 185ebc6..3876b78 100644 --- a/src/partials/finance/TransactionPanel.jsx +++ b/src/partials/finance/TransactionPanel.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useEffect, useMemo, useRef, useState } from 'react'; import Image from '../../images/transactions-image-04.svg'; import moment from 'moment'; @@ -9,16 +9,19 @@ import UserAvatar from '../../images/user-avatar-32.png'; import { observer } from 'mobx-react-lite'; const TransactionPanel = observer( - ({ transactionPanelOpen, onClose, delegate, postTransaction }) => { + ({ transactionPanelOpen, onClose, delegate, postTransaction, unlocking }) => { const closeBtn = useRef(null); const panelContent = useRef(null); const [amount, setAmount] = useState(0); + const status = useMemo(() => (unlocking ? 'Unlock' : delegate.status), [unlocking, delegate]); + const statusColor = () => { - switch (delegate.status) { + switch (status) { case 'Vote': return 'bg-emerald-100 text-emerald-600'; + case 'Unlock': case 'Unvote': return 'bg-rose-100 text-rose-500'; default: @@ -26,8 +29,7 @@ const TransactionPanel = observer( } }; - const amountLabel = - delegate.status === 'Vote' ? 'Voiting amount' : 'Unvoiting amount'; + const amountLabel = delegate.status === 'Vote' ? 'Voiting amount' : 'Unvoiting amount'; // close if the esc key is pressed useEffect(() => { @@ -40,12 +42,13 @@ const TransactionPanel = observer( }); useEffect(() => { - const status = delegate.status; - if (status === 'Unvote') { setAmount(store.accountSentVotes[delegate.address].toString()); } - }, [delegate]); + if (status === 'Unlock') { + setAmount(store.accountLockedVotesCanReturnSum[delegate.address]?.toString()); + } + }, [delegate, status]); return (
-
- Vote Transaction -
+
Vote Transaction
{moment().format('DD/MM/YYYY hh:mm A')}
@@ -89,40 +90,28 @@ const TransactionPanel = observer( alt="Transaction 04" />
-
+
{amount}/idn
- {delegate?.dpos?.delegate?.username || - formatAddressBig(delegate.address || '')} + {delegate?.dpos?.delegate?.username || formatAddressBig(delegate.address || '')}
- {delegate.status} + {status}
{/* Divider */} -