Skip to content

Commit

Permalink
Update terms and condition (#854)
Browse files Browse the repository at this point in the history
* add log for terms and condition

* update contract call

* added RPC call to get accepted block height

* fix t&c test

* remove logs
  • Loading branch information
Megha-Dev-19 authored Jul 8, 2024
1 parent fb01c8b commit f492594
Show file tree
Hide file tree
Showing 7 changed files with 1,728 additions and 15 deletions.
3 changes: 2 additions & 1 deletion instances/devhub.near/aliases.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"REPL_EFIZ": "efiz.near",
"REPL_DEVS": "devs.near",
"REPL_SOCIAL_CONTRACT": "social.near",
"REPL_RPC_URL": "https://rpc.mainnet.near.org"
"REPL_RPC_URL": "https://rpc.mainnet.near.org",
"REPL_TERMS_AND_CONDITION_BLOCKHEIGHT": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { getLinkUsingCurrentGateway } = VM.require(
"${REPL_DEVHUB}/widget/core.lib.url"
) || { getLinkUsingCurrentGateway: () => {} };
const snapshotHistory = props.snapshotHistory;
const proposalId = props.id;

const Wrapper = styled.div`
position: relative;
Expand Down Expand Up @@ -97,6 +98,22 @@ function sortTimelineAndComments() {
...getDifferentKeysWithValues(startingPoint, item),
};
});

// add log for accepting terms and condition
changedKeysListWithValues.unshift({
0: {
key: "timestamp",
originalValue: "0",
modifiedValue: snapshotHistory[0].timestamp,
},
1: {
key: "terms_and_condition",
originalValue: "",
modifiedValue: "accepted",
},
editorId: snapshotHistory[0].editor_id,
});

State.update({
changedKeysListWithValues,
snapshotHistoryLength: snapshotHistory.length,
Expand Down Expand Up @@ -296,6 +313,17 @@ const AccountProfile = ({ accountId }) => {

const parseProposalKeyAndValue = (key, modifiedValue, originalValue) => {
switch (key) {
case "terms_and_condition": {
return (
<span>
accepted
<Widget
src={"${REPL_DEVHUB}/widget/devhub.entity.proposal.T&C"}
props={{ proposalId: proposalId }}
/>
</span>
);
}
case "name":
return <span>changed title</span>;
case "summary":
Expand Down
23 changes: 12 additions & 11 deletions instances/devhub.near/widget/devhub/entity/proposal/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,16 @@ const onSubmit = ({ isDraft, isCancel }) => {
reviewer_completed_attestation: false,
},
};
const args = { labels: [], body: body };
const args = {
labels: [],
body: body,
};
if (isEditPage) {
args["id"] = editProposalData.id;
} else {
args["accepted_terms_and_conditions_version"] = parseInt(
"${REPL_TERMS_AND_CONDITION_BLOCKHEIGHT}"
);
}

Near.call([
Expand Down Expand Up @@ -884,16 +891,10 @@ const ConsentComponent = useMemo(() => {
label: (
<>
I’ve agree to{" "}
<a
href={
"https://docs.google.com/document/d/1nRGy7LhpLj56SjN9MseV1x-ubH8O_c6B9DOAZ9qTwMU/edit?usp=sharing"
}
className="text-decoration-underline"
target="_blank"
rel="noopener noreferrer"
>
DevHub’s Terms and Conditions
</a>
<Widget
src={"${REPL_DEVHUB}/widget/devhub.entity.proposal.T&C"}
props={{ proposalId: proposalId }}
/>
and commit to honoring it
</>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,11 @@ const editProposal = ({ timeline }) => {
requested_sponsor: snapshot.requested_sponsor,
timeline: timeline,
};
const args = { labels: [], body: body, id: proposal.id };
const args = {
labels: [],
body: body,
id: proposal.id,
};

Near.call([
{
Expand Down
90 changes: 90 additions & 0 deletions instances/devhub.near/widget/devhub/entity/proposal/T&C.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const { getLinkUsingCurrentGateway } = VM.require(
"${REPL_DEVHUB}/widget/core.lib.url"
) || { getLinkUsingCurrentGateway: () => {} };

State.init({
proposalBlockHeight: null,
});

const proposalId = props.proposalId;

const QUERYAPI_ENDPOINT = `https://near-queryapi.api.pagoda.co/v1/graphql`;
const fetchGraphQL = (operationsDoc, operationName, variables) => {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
headers: { "x-hasura-role": `polyprogrammist_near` },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName,
}),
});
};

const queryName =
"polyprogrammist_near_devhub_prod_v1_proposals_with_latest_snapshot";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
limit: $limit
order_by: {proposal_id: desc}
where: $where
) {
block_height
}
}`;

const variables = {
limit: 10,
offset,
where: { proposal_id: { _eq: proposalId } },
};

fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => {
if (result.status === 200) {
if (result.body.data) {
const data = result.body.data?.[queryName];
console.log(data);
State.update({ proposalBlockHeight: data[0].block_height });
}
}
});

let acceptedTermsVersion = "${REPL_TERMS_AND_CONDITION_BLOCKHEIGHT}";

if (state.proposalBlockHeight !== null) {
const data = fetch(
`https://mainnet.neardata.xyz/v0/block/${state.proposalBlockHeight}`
);
if (Array.isArray(data?.body?.shards)) {
data.body.shards.map((shard) => {
const data = shard.chunk.transactions.filter(
(txn) =>
txn.transaction.receiver_id === "devhub.near" &&
txn.transaction.actions[0].FunctionCall.method_name === "add_proposal"
);
if (data?.length) {
const args = JSON.parse(
Buffer.from(
data[0].transaction.actions[0].FunctionCall.args,
"base64"
).toString("utf8")
);
acceptedTermsVersion = args.accepted_terms_and_conditions_version;
}
});
}
}

return (
<a
href={getLinkUsingCurrentGateway(
`${REPL_DEVHUB}/widget/devhub.entity.proposal.TermsAndCondition@${acceptedTermsVersion}`
)}
className="text-decoration-underline"
target="_blank"
rel="noopener noreferrer"
>
DevHub’s Terms and Conditions
</a>
);
Loading

0 comments on commit f492594

Please sign in to comment.