-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
fb01c8b
commit f492594
Showing
7 changed files
with
1,728 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
instances/devhub.near/widget/devhub/entity/proposal/T&C.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
Oops, something went wrong.