Skip to content

Commit

Permalink
fix that submit draft keeps on spinning (#951)
Browse files Browse the repository at this point in the history
* fix that submit draft keeps on spinning

retry checking for the latest proposal if it matches title and description
  • Loading branch information
petersalomonsen authored Oct 7, 2024
1 parent 6330078 commit 3b1e9d1
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 92 deletions.
56 changes: 26 additions & 30 deletions instances/devhub.near/widget/devhub/entity/proposal/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,31 @@ const InputContainer = ({ heading, description, children }) => {
);
};

function checkIfLatestProposalMatchesTitleAndDescription() {
Near.asyncView("${REPL_DEVHUB_CONTRACT}", "get_all_proposal_ids").then(
(proposalIds) => {
const latestProposalId = proposalIds[proposalIds.length - 1];
Near.asyncView("${REPL_DEVHUB_CONTRACT}", "get_proposal", {
proposal_id: latestProposalId,
}).then((latestProposal) => {
if (
latestProposal.snapshot.name === title &&
latestProposal.snapshot.description === description
) {
setCreateTxn(false);
setProposalId(proposalIds[proposalIds.length - 1]);
setShowProposalPage(true);
} else {
setTimeout(
() => checkIfLatestProposalMatchesTitleAndDescription(),
500
);
}
});
}
);
}

// show proposal created after txn approval for popup wallet
useEffect(() => {
if (isTxnCreated) {
Expand All @@ -427,36 +452,7 @@ useEffect(() => {
setShowProposalPage(true);
}
} else {
const proposalIds = Near.view(
"${REPL_DEVHUB_CONTRACT}",
"get_all_proposal_ids"
);
if (Array.isArray(proposalIds) && !proposalIdsArray) {
setProposalIdsArray(proposalIds);
}
if (
Array.isArray(proposalIds) &&
Array.isArray(proposalIdsArray) &&
proposalIds.length !== proposalIdsArray.length
) {
const latestProposalId = proposalIds[proposalIds.length - 1];
const latestProposal = Near.view(
"${REPL_DEVHUB_CONTRACT}",
"get_proposal",
{
proposal_id: latestProposalId,
}
);

if (
latestProposal.snapshot.name === title &&
latestProposal.snapshot.description === description
) {
setCreateTxn(false);
setProposalId(proposalIds[proposalIds.length - 1]);
setShowProposalPage(true);
}
}
checkIfLatestProposalMatchesTitleAndDescription();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,31 @@ const InputContainer = ({ heading, description, children }) => {
);
};

function checkIfLatestProposalMatchesTitleAndDescription() {
Near.asyncView("${REPL_EVENTS_CONTRACT}", "get_all_proposal_ids").then(
(proposalIds) => {
const latestProposalId = proposalIds[proposalIds.length - 1];
Near.asyncView("${REPL_EVENTS_CONTRACT}", "get_proposal", {
proposal_id: latestProposalId,
}).then((latestProposal) => {
if (
latestProposal.snapshot.name === title &&
latestProposal.snapshot.description === description
) {
setCreateTxn(false);
setProposalId(proposalIds[proposalIds.length - 1]);
setShowProposalPage(true);
} else {
setTimeout(
() => checkIfLatestProposalMatchesTitleAndDescription(),
500
);
}
});
}
);
}

// show proposal created after txn approval for popup wallet
useEffect(() => {
if (isTxnCreated) {
Expand All @@ -430,36 +455,7 @@ useEffect(() => {
setShowProposalPage(true);
}
} else {
const proposalIds = Near.view(
"${REPL_EVENTS_CONTRACT}",
"get_all_proposal_ids"
);
if (Array.isArray(proposalIds) && !proposalIdsArray) {
setProposalIdsArray(proposalIds);
}
if (
Array.isArray(proposalIds) &&
Array.isArray(proposalIdsArray) &&
proposalIds.length !== proposalIdsArray.length
) {
const latestProposalId = proposalIds[proposalIds.length - 1];
const latestProposal = Near.view(
"${REPL_DEVHUB_CONTRACT}",
"get_proposal",
{
proposal_id: latestProposalId,
}
);

if (
latestProposal.snapshot.name === title &&
latestProposal.snapshot.description === description
) {
setCreateTxn(false);
setProposalId(proposalIds[proposalIds.length - 1]);
setShowProposalPage(true);
}
}
checkIfLatestProposalMatchesTitleAndDescription();
}
}
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,36 @@ const InputContainer = ({ heading, description, children }) => {
);
};

function checkIfLatestProposalMatchesTitleAndDescription() {
Near.asyncView(
"${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}",
"get_all_proposal_ids"
).then((proposalIds) => {
const latestProposalId = proposalIds[proposalIds.length - 1];
Near.asyncView(
"${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}",
"get_proposal",
{
proposal_id: latestProposalId,
}
).then((latestProposal) => {
if (
latestProposal.snapshot.name === title &&
latestProposal.snapshot.description === description
) {
setCreateTxn(false);
setProposalId(proposalIds[proposalIds.length - 1]);
setShowProposalViewModal(true);
} else {
setTimeout(
() => checkIfLatestProposalMatchesTitleAndDescription(),
500
);
}
});
});
}

// show proposal created after txn approval for popup wallet
useEffect(() => {
if (isTxnCreated) {
Expand All @@ -480,36 +510,7 @@ useEffect(() => {
setShowProposalViewModal(true);
}
} else {
const proposalIds = Near.view(
"${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}",
"get_all_proposal_ids"
);
if (Array.isArray(proposalIds) && !proposalIdsArray) {
setProposalIdsArray(proposalIds);
}
if (
Array.isArray(proposalIds) &&
Array.isArray(proposalIdsArray) &&
proposalIds.length !== proposalIdsArray.length
) {
const latestProposalId = proposalIds[proposalIds.length - 1];
const latestProposal = Near.view(
"${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}",
"get_proposal",
{
proposal_id: latestProposalId,
}
);

if (
latestProposal.snapshot.name === title &&
latestProposal.snapshot.description === description
) {
setCreateTxn(false);
setProposalId(proposalIds[proposalIds.length - 1]);
setShowProposalViewModal(true);
}
}
checkIfLatestProposalMatchesTitleAndDescription();
}
}
setLoading(false);
Expand Down
8 changes: 6 additions & 2 deletions playwright-tests/tests/proposal/proposals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ test.describe("Don't ask again enabled", () => {
await expect(disabledSubmitButton).not.toBeAttached();

let newProposalId = 0;
let get_all_proposal_ids_attempt = 0;
await mockTransactionSubmitRPCResponses(
page,
async ({ route, request, transaction_completed, last_receiver_id }) => {
Expand All @@ -162,11 +163,14 @@ test.describe("Don't ask again enabled", () => {
const response = await route.fetch();
const json = await response.json();

await new Promise((resolve) => setTimeout(() => resolve(), 4000));
const resultObj = decodeResultJSON(json.result.result);
newProposalId = resultObj[resultObj.length - 1] + 1;
if (transaction_completed) {
resultObj.push(newProposalId);
if (get_all_proposal_ids_attempt === 1) {
resultObj.push(newProposalId);
} else {
get_all_proposal_ids_attempt++;
}
}
json.result.result = encodeResultJSON(resultObj);

Expand Down

0 comments on commit 3b1e9d1

Please sign in to comment.