Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added progress bar for transactions status #199

Merged
merged 7 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function TransactionLoader({ showInProgress, showError, toggleToast }) {
return showInProgress || showError ? (
<div class="toast-container position-fixed bottom-0 end-0 p-3">
<div className={`toast ${showInProgress || showError ? "show" : ""}`}>
<div class="toast-header px-2">
<strong class="me-auto">Just Now</strong>
{showError && (
<i
class="bi bi-x-lg h6 mb-0 cursor-pointer"
onClick={() => toggleToast(false)}
></i>
)}
</div>
<div class="toast-body">
{showInProgress ? (
<div className="d-flex align-items-center gap-3">
<img
height={30}
width={30}
src="https://i.gifer.com/origin/34/34338d26023e5515f6cc8969aa027bca.gif"
/>
<div className="flex-1 text-left">
Processing your request ...
</div>
</div>
) : (
<div className="d-flex align-items-center gap-3 ">
<i class="bi bi-exclamation-triangle h3 mb-0 warning-icon"></i>
<div className="flex-1 text-left">
Something went wrong. Please try resubmitting the request.
</div>
</div>
)}
</div>
</div>
</div>
) : null;
}
return { TransactionLoader };
36 changes: 33 additions & 3 deletions instances/treasury-devdao.near/widget/components/VoteActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ if (!instance) {
}

const { treasuryDaoID } = VM.require(`${instance}/widget/config.data`);
const { TransactionLoader } = VM.require(
`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.TransactionLoader`
) || { TransactionLoader: () => <></> };

const votes = props.votes ?? {};
const proposalId = props.proposalId;
Expand Down Expand Up @@ -37,6 +40,7 @@ const [isInsufficientBalance, setInsufficientBal] = useState(false);
const [showWarning, setShowWarning] = useState(false);
const [isReadyToBeWithdrawn, setIsReadyToBeWithdrawn] = useState(true);
const [showConfirmModal, setConfirmModal] = useState(null);
const [showErrorToast, setShowErrorToast] = useState(false);

useEffect(() => {
if (!avoidCheckForBalance) {
Expand Down Expand Up @@ -74,20 +78,36 @@ function getProposalData() {
(result) => result
);
}

useEffect(() => {
if (isTxnCreated) {
let checkTxnTimeout = null;
let errorTimeout = null;

const checkForVoteOnProposal = () => {
getProposalData().then((proposal) => {
if (JSON.stringify(proposal.votes) !== JSON.stringify(votes)) {
checkProposalStatus();
clearTimeout(errorTimeout);
setTxnCreated(false);
} else {
setTimeout(() => checkForVoteOnProposal(), 1000);
checkTxnTimeout = setTimeout(checkForVoteOnProposal, 1000);
}
});
};

checkForVoteOnProposal();

// if in 20 seconds there is no change, show error condition
errorTimeout = setTimeout(() => {
setShowErrorToast(true);
setTxnCreated(false);
clearTimeout(checkTxnTimeout);
}, 20000);

return () => {
clearTimeout(checkTxnTimeout);
clearTimeout(errorTimeout);
};
}
}, [isTxnCreated]);

Expand Down Expand Up @@ -134,7 +154,10 @@ const InsufficientBalanceWarning = () => {
<div className={`toast ${showWarning ? "show" : ""}`}>
<div class="toast-header px-2">
<strong class="me-auto">Just Now</strong>
<i class="bi bi-x-lg h6" onClick={() => setShowWarning(false)}></i>
<i
class="bi bi-x-lg h6 mb-0 cursor-pointer"
onClick={() => setShowWarning(false)}
></i>
</div>
<div class="toast-body">
The request cannot be approved because the treasury balance is
Expand All @@ -144,8 +167,15 @@ const InsufficientBalanceWarning = () => {
</div>
) : null;
};

return (
<Container>
<TransactionLoader
showInProgress={isTxnCreated}
showError={showErrorToast}
toggleToast={() => setShowErrorToast(false)}
/>

<InsufficientBalanceWarning />
<Widget
src={`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.Modal`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function AppLayout({ page, instance, children, treasuryDaoID }) {
.btn:disabled,
.btn.disabled,
fieldset:disabled {
border-color: none !important;
border-color: transparent !important;
}

.table {
Expand Down Expand Up @@ -371,6 +371,14 @@ function AppLayout({ page, instance, children, treasuryDaoID }) {
.cursor-pointer {
cursor: pointer;
}

.success-icon {
color: var(--other-green) !important;
}

.warning-icon {
color: var(--other-warning) !important;
}
`;

return !config ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const { getLinkUsingCurrentGateway } = VM.require(
"${REPL_DEVHUB}/widget/core.lib.url"
) || { getLinkUsingCurrentGateway: () => {} };

const { TransactionLoader } = VM.require(
`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.TransactionLoader`
) || { TransactionLoader: () => <></> };

const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url") || {
href: () => {},
};
Expand Down Expand Up @@ -45,6 +49,7 @@ const [selectedTokensAvailable, setSelectedTokensAvailable] = useState(null);
const [isReceiverRegistered, setReceiverRegister] = useState(false);
const [isLoadingProposals, setLoadingProposals] = useState(false);
const [showCancelModal, setShowCancelModal] = useState(false);
const [showErrorToast, setShowErrorToast] = useState(false);

useEffect(() => {
if (!showProposalSelection) {
Expand Down Expand Up @@ -150,19 +155,36 @@ function cleanInputs() {
// close canvas after proposal is submitted
useEffect(() => {
if (isTxnCreated) {
let checkTxnTimeout = null;
let errorTimeout = null;

const checkForNewProposal = () => {
getLastProposalId().then((id) => {
if (lastProposalId !== id) {
cleanInputs();
onCloseCanvas();
clearTimeout(errorTimeout);
refreshData();
setTxnCreated(false);
} else {
setTimeout(() => checkForNewProposal(), 1000);
checkTxnTimeout = setTimeout(() => checkForNewProposal(), 1000);
}
});
};

checkForNewProposal();

// if in 20 seconds there is no change, show error condition
errorTimeout = setTimeout(() => {
setShowErrorToast(true);
setTxnCreated(false);
clearTimeout(checkTxnTimeout);
}, 20000);

return () => {
clearTimeout(checkTxnTimeout);
clearTimeout(errorTimeout);
};
}
}, [isTxnCreated]);

Expand Down Expand Up @@ -373,6 +395,11 @@ useEffect(() => {

return (
<Container>
<TransactionLoader
showInProgress={isTxnCreated}
showError={showErrorToast}
toggleToast={() => setShowErrorToast(false)}
/>
<Widget
src={`${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/components.Modal`}
props={{
Expand Down Expand Up @@ -588,7 +615,8 @@ return (
!selectedProposal?.name ||
!tokenId ||
!isAccountValid() ||
!isAmountValid(),
!isAmountValid() ||
isTxnCreated,
label: "Submit",
onClick: onSubmitClick,
loading: isTxnCreated,
Expand Down
53 changes: 32 additions & 21 deletions instances/treasury-devdao.near/widget/pages/payments/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,34 @@ const ToastStatusContent = () => {
}
return (
<div className="toast-body">
{content}
<br />
{showToastStatus !== "InProgress" && showToastStatus !== "Removed" && (
<a
className="text-underline"
href={href({
widgetSrc: `${instance}/widget/app`,
params: {
page: "payments",
selectedTab: "History",
highlightProposalId:
typeof highlightProposalId === "number"
? highlightProposalId
: voteProposalId,
},
})}
>
View in History
</a>
)}
<div className="d-flex align-items-center gap-3">
{showToastStatus === "Approved" && (
<i class="bi bi-check2 h3 mb-0 success-icon"></i>
)}
<div>
{content}
<br />
{showToastStatus !== "InProgress" &&
showToastStatus !== "Removed" && (
<a
className="text-underline"
href={href({
widgetSrc: `${instance}/widget/app`,
params: {
page: "payments",
selectedTab: "History",
highlightProposalId:
typeof highlightProposalId === "number"
? highlightProposalId
: voteProposalId,
},
})}
>
View in History
</a>
)}
</div>
</div>
</div>
);
};
Expand All @@ -205,7 +213,10 @@ const VoteSuccessToast = () => {
<div className={`toast ${showToastStatus ? "show" : ""}`}>
<div className="toast-header px-2">
<strong className="me-auto">Just Now</strong>
<i className="bi bi-x-lg h6" onClick={() => setToastStatus(null)}></i>
<i
className="bi bi-x-lg h6 mb-0 cursor-pointer"
onClick={() => setToastStatus(null)}
></i>
</div>
<ToastStatusContent />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,34 @@ const ToastStatusContent = () => {
}
return (
<div className="toast-body">
{content}
<br />
{showToastStatus !== "InProgress" && (
<a
className="text-underline"
href={href({
widgetSrc: `${instance}/widget/app`,
params: {
page: "proposals-feed",
selectedTab: "History",
highlightProposalId:
typeof highlightProposalId === "number"
? highlightProposalId
: voteProposalId,
},
})}
>
View in History
</a>
)}
<div className="d-flex align-items-center gap-3">
{showToastStatus === "Approved" && (
<i class="bi bi-check2 h3 mb-0 success-icon"></i>
)}
<div>
{content}
<br />
{showToastStatus !== "InProgress" &&
showToastStatus !== "Removed" && (
<a
className="text-underline"
href={href({
widgetSrc: `${instance}/widget/app`,
params: {
page: "proposals-feed",
selectedTab: "History",
highlightProposalId:
typeof highlightProposalId === "number"
? highlightProposalId
: voteProposalId,
},
})}
>
View in History
</a>
)}
</div>
</div>
</div>
);
};
Expand All @@ -182,7 +190,10 @@ const VoteSuccessToast = () => {
<div className={`toast ${showToastStatus ? "show" : ""}`}>
<div className="toast-header px-2">
<strong className="me-auto">Just Now</strong>
<i className="bi bi-x-lg h6" onClick={() => setToastStatus(null)}></i>
<i
className="bi bi-x-lg h6 mb-0 cursor-pointer"
onClick={() => setToastStatus(null)}
></i>
</div>
<ToastStatusContent />
</div>
Expand Down
Loading
Loading