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

feat: move kyc to events #891

Merged
merged 12 commits into from
Jul 25, 2024
6 changes: 4 additions & 2 deletions instances/events-committee.near/aliases.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"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_PROPOSAL_FEED_INDEXER_QUERY_NAME": "thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot",
"REPL_INDEXER_HASURA_ROLE": "thomasguntenaar_near"
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const Button = ({
disabled ? "disabled" : "",
].join(" ")}
style={{ width: "fit-content" }}
disabled={disabled}
{...restProps}
data-testid={props.testId ?? "button"}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const showAccountAutoComplete = props.showAutoComplete ?? false;
const showProposalIdAutoComplete = props.showProposalIdAutoComplete ?? false;
const autoFocus = props.autoFocus ?? false;

const queryName =
"thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot";
const queryName = "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
Expand Down Expand Up @@ -231,7 +230,7 @@ async function getSuggestedProposals(id) {
}
await asyncFetch("https://near-queryapi.api.pagoda.co/v1/graphql", {
method: "POST",
headers: { "x-hasura-role": "thomasguntenaar_near" },
headers: { "x-hasura-role": "${REPL_INDEXER_HASURA_ROLE}" },
body: JSON.stringify({
query: query,
variables: variables,
Expand All @@ -241,7 +240,7 @@ async function getSuggestedProposals(id) {
.then((res) => {
const proposals =
res?.data?.[
"thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot"
"${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}"
];
results = proposals;
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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": "${REPL_INDEXER_HASURA_ROLE}" },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName,
}),
});
};

const queryName = "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}";
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];
State.update({ proposalBlockHeight: data[0].block_height });
}
}
});

let acceptedTermsVersion = Near.block().header.height;

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.TermsAndConditions@${acceptedTermsVersion}`
)}
className="text-decoration-underline"
Tguntenaar marked this conversation as resolved.
Show resolved Hide resolved
target="_blank"
rel="noopener noreferrer"
>
DevHub’s Terms and Conditions
</a>
);
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ function sortTimelineAndComments() {
.slice(1)
.map((item, index) => {
const startingPoint = snapshotHistory[index]; // Set comparison to the previous item
// we don't show timeline_version in logs
delete startingPoint.timeline.timeline_version;
delete item.timeline.timeline_version;
if (
startingPoint.timeline.kyc_verified === undefined &&
item.timeline.kyc_verified === false
) {
startingPoint.timeline.kyc_verified = false;
}

return {
editorId: item.editor_id,
...getDifferentKeysWithValues(startingPoint, item),
Expand Down Expand Up @@ -270,8 +280,12 @@ function parseTimelineKeyAndValue(timeline, originalValue, modifiedValue) {
</span>
)
);
case "sponsor_requested_review":
return !oldValue && newValue && <span>completed review</span>;
case "sponsor_requested_review": {
if (!oldValue && newValue) {
return <span>completed review</span>;
} else if (oldValue && !newValue) return <span>unmarked review</span>;
return null;
}
case "reviewer_completed_attestation":
return !oldValue && newValue && <span>completed attestation</span>;
case "kyc_verified":
Expand Down Expand Up @@ -317,7 +331,7 @@ const parseProposalKeyAndValue = (key, modifiedValue, originalValue) => {
<span>
accepted
<Widget
src={"${REPL_EVENTS}/widget/devhub.entity.proposal.AcceptedTerms"}
src={"${REPL_DEVHUB}/widget/devhub.entity.proposal.AcceptedTerms"}
Tguntenaar marked this conversation as resolved.
Show resolved Hide resolved
props={{ proposalId: proposalId }}
/>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,12 @@ const onSubmit = ({ isDraft, isCancel }) => {
status: "CANCELLED",
sponsor_requested_review: false,
reviewer_completed_attestation: false,
kyc_verified: false,
}
: isDraft
? { status: "DRAFT" }
: isEditPage
? editProposalData.snapshot.timeline
: {
status: "REVIEW",
sponsor_requested_review: false,
Expand All @@ -749,6 +752,10 @@ const onSubmit = ({ isDraft, isCancel }) => {
const args = { labels: (labels ?? []).map((i) => i.value), body: body };
if (isEditPage) {
args["id"] = editProposalData.id;
} else {
args["accepted_terms_and_conditions_version"] = parseInt(
Near.block().header.height
);
}

Near.call([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ const FeedPage = () => {
currentlyDisplaying: 0,
});

const queryName =
"thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot";
const queryName = "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
Expand Down Expand Up @@ -245,7 +244,7 @@ const FeedPage = () => {
function fetchGraphQL(operationsDoc, operationName, variables) {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
headers: { "x-hasura-role": `thomasguntenaar_near` },
headers: { "x-hasura-role": `${REPL_INDEXER_HASURA_ROLE}` },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
Expand Down Expand Up @@ -332,12 +331,8 @@ const FeedPage = () => {
fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => {
if (result.status === 200) {
if (result.body.data) {
const data =
result.body.data
.thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot;
const totalResult =
result.body.data
.thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot_aggregate;
const data = result.body.data[queryName];
const totalResult = result.body.data[`${queryName}_aggregate`];
State.update({ aggregatedCount: totalResult.aggregate.count });
// Parse timeline
fetchBlockHeights(data, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const [selectedProposals, setSelectedProposals] = useState(linkedProposals);
const [proposalsOptions, setProposalsOptions] = useState([]);
const [searchProposalId, setSearchProposalId] = useState("");
const QUERYAPI_ENDPOINT = `https://near-queryapi.api.pagoda.co/v1/graphql`;
const queryName =
"thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot";
const queryName = "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
Expand Down Expand Up @@ -63,7 +62,7 @@ const buildWhereClause = () => {
function fetchGraphQL(operationsDoc, operationName, variables) {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
headers: { "x-hasura-role": `thomasguntenaar_near` },
headers: { "x-hasura-role": `${REPL_INDEXER_HASURA_ROLE}` },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
Expand All @@ -82,9 +81,7 @@ const fetchProposals = () => {
fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => {
if (result.status === 200) {
if (result.body.data) {
const proposalsData =
result.body.data
.thomasguntenaar_near_events_committee_proposals_2_proposals_with_latest_snapshot;
const proposalsData = result.body.data[queryName];

const data = [];
for (const prop of proposalsData) {
Expand Down
Loading
Loading