-
-
Notifications
You must be signed in to change notification settings - Fork 774
Let users ingest missing contributions #8274
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
Merged
thelostone-mc
merged 5 commits into
gitcoinco:stable
from
ScopeLift:let-users-ingest-missing-contributions
Jan 26, 2021
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c19ba16
Setup new page for ingesting missing contributions
mds1 6ccd107
Setup form and add input validation
mds1 9dac950
Add ingestion endpoint + UI status alerts
mds1 def1e4a
Remove unnecessary authentication check in ingest_contributions_view
mds1 191d3f2
Move missing-contributions JS file into grants folder
mds1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
150 changes: 150 additions & 0 deletions
150
app/assets/v2/js/grants-ingest-missing-contributions.js
This file contains hidden or 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,150 @@ | ||
/** | ||
* @notice Vue component for ingesting contributions that were missed during checkout | ||
* @dev See more at: https://github.com/gitcoinco/web/issues/7744 | ||
*/ | ||
|
||
let appIngestContributions; | ||
|
||
Vue.component('grants-ingest-contributions', { | ||
delimiters: [ '[[', ']]' ], | ||
|
||
data: function() { | ||
return { | ||
form: { | ||
txHash: undefined, // user transaction hash, used to ingest L1 donations | ||
userAddress: undefined // user address, used to ingest zkSync (L2) donations | ||
}, | ||
errors: {}, // keys are errors that occurred | ||
submitted: false // true if form has been submitted and we are waiting on response | ||
}; | ||
}, | ||
|
||
methods: { | ||
checkForm() { | ||
this.submitted = true; | ||
this.errors = {}; | ||
let isValidTxHash; | ||
let isValidAddress; | ||
|
||
// Validate that at least one of txHash and userAddress is provided | ||
const { txHash, userAddress } = this.form; | ||
const isFormComplete = txHash || userAddress; | ||
|
||
if (!isFormComplete) { | ||
// Form was not filled out | ||
this.$set(this.errors, 'invalidForm', 'Please enter a valid transaction hash or a valid wallet address'); | ||
} else { | ||
// Form was filled out, so validate the inputs | ||
isValidTxHash = txHash && txHash.length === 66 && txHash.startsWith('0x'); | ||
isValidAddress = ethers.utils.isAddress(userAddress); | ||
|
||
if (txHash && !isValidTxHash) { | ||
this.$set(this.errors, 'txHash', 'Please enter a valid transaction hash'); | ||
} | ||
if (userAddress && !isValidAddress) { | ||
this.$set(this.errors, 'address', 'Please enter a valid address'); | ||
} | ||
} | ||
|
||
if (Object.keys(this.errors).length) { | ||
return false; // there are errors the user must correct | ||
} | ||
|
||
return { | ||
txHash: isValidTxHash ? txHash : '', | ||
// getAddress returns checksum address required by web3py, and throws if address is invalid | ||
userAddress: isValidAddress ? ethers.utils.getAddress(userAddress) : '' | ||
}; | ||
}, | ||
|
||
async ingest(event) { | ||
try { | ||
event.preventDefault(); | ||
|
||
// Return if form is not valid | ||
const formParams = this.checkForm(); | ||
|
||
if (!formParams) { | ||
return; | ||
} | ||
|
||
// Send POST requests to ingest contributions | ||
const { txHash, userAddress } = formParams; | ||
const csrfmiddlewaretoken = document.querySelector('[name=csrfmiddlewaretoken]').value; | ||
const url = '/grants/ingest'; | ||
const headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; | ||
const payload = { | ||
csrfmiddlewaretoken, | ||
txHash, | ||
userAddress, | ||
network: document.web3network || 'mainnet' | ||
}; | ||
const postParams = { | ||
method: 'POST', | ||
headers, | ||
body: new URLSearchParams(payload) | ||
}; | ||
|
||
// Send saveSubscription request | ||
const res = await fetch(url, postParams); | ||
const json = await res.json(); | ||
|
||
// Notify user of success status, and clear form if successful | ||
console.log('ingestion response: ', json); | ||
if (!json.success) { | ||
console.log('ingestion failed'); | ||
this.submitted = false; | ||
throw new Error('Your transactions could not be processed, please try again'); | ||
} else { | ||
console.log('ingestion successful'); | ||
_alert('Your contributions have been added successfully!', 'success'); | ||
this.resetForm(); | ||
} | ||
} catch (e) { | ||
this.handleError(e); | ||
} | ||
}, | ||
|
||
resetForm() { | ||
this.form.txHash = undefined; | ||
this.form.userAddress = undefined; | ||
this.errors = {}; | ||
this.submitted = false; | ||
}, | ||
|
||
handleError(err) { | ||
console.error(err); // eslint-disable-line no-console | ||
let message = 'There was an error'; | ||
|
||
if (err.message) | ||
message = err.message; | ||
else if (err.msg) | ||
message = err.msg; | ||
else if (typeof err === 'string') | ||
message = err; | ||
|
||
_alert(message, 'error'); | ||
this.submitted = false; | ||
} | ||
}, | ||
|
||
watch: { | ||
deep: true, | ||
form: { | ||
deep: true, | ||
handler(newVal, oldVal) { | ||
this.checkForm(); | ||
this.submitted = false; | ||
this.errors = {}; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
if (document.getElementById('gc-grants-ingest-contributions')) { | ||
|
||
appIngestContributions = new Vue({ | ||
delimiters: [ '[[', ']]' ], | ||
el: '#gc-grants-ingest-contributions' | ||
}); | ||
} | ||
This file contains hidden or 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,146 @@ | ||
{% comment %} | ||
Copyright (C) 2020 Gitcoin Core | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
{% endcomment %} | ||
{% load i18n static email_obfuscator add_url_schema avatar_tags %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
{% include 'shared/head.html' with slim=1 %} | ||
{% include 'shared/cards.html' %} | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-select@latest/dist/vue-select.css"> | ||
<link rel="stylesheet" href="{% static "v2/css/grants/new.css" %}"> | ||
<link rel="stylesheet" href={% static "v2/css/tabs.css" %}> | ||
</head> | ||
|
||
<body class="interior {{ active }} grant g-font-muli"> | ||
|
||
{% include 'shared/tag_manager_2.html' %} | ||
<div class="container-fluid header dash px-0"> | ||
{% include 'shared/top_nav.html' with class='d-md-flex' %} | ||
{% include 'grants/nav.html' %} | ||
</div> | ||
|
||
<grants-ingest-contributions class="container-fluid bg-lightblue pb-5 pt-5" v-cloak id="gc-grants-ingest-contributions" inline-template> | ||
<form action="" @submit="checkForm"> | ||
<div class="text-center"> | ||
<img style="width:6rem;" src="{% static "v2/images/grants/torchbearer.svg" %}"> | ||
</div> | ||
|
||
<div class="container mt-3 mb-3 bg-white position-relative rounded col-lg-6 mx-auto"> | ||
<div class="row p-4 p-md-5"> | ||
|
||
<div class="col-12 text-center mb-4"> | ||
<h1 class="text-center font-title-xl">Add Missing Contributions</h1> | ||
<p class="text-center font-smaller-1 text-black-60"> | ||
If you completed a Gitcoin Grants checkout, but don't see evidence of this in your | ||
email or the Gitcoin interface, you can use this form to fix that! | ||
</p> | ||
</div> | ||
|
||
{% csrf_token %} | ||
|
||
<!-- Instructions --> | ||
<div class="col-12 mb-2"> | ||
<h5 class="mt-4">Instructions</h5> | ||
<hr> | ||
</div> | ||
|
||
<!-- Amount --> | ||
<div class="col-12 mb-3"> | ||
<p class="font-body mb-1"> | ||
<ul> | ||
<li>If you donated using L1 (Standard Checkout), please enter the transaction hash</li> | ||
<li>If you donated using L2 (zkSync Checkout), please enter your wallet address</li> | ||
<li>At least one of these two is required</li> | ||
</ul> | ||
</p> | ||
</div> | ||
|
||
<!-- Collect Information --> | ||
<div class="col-12 mb-2"> | ||
<h5 class="mt-4">Contribution Data</h5> | ||
<hr> | ||
</div> | ||
|
||
<!-- Transaction hash --> | ||
<div class="col-12 mb-3"> | ||
<label class="font-caption letter-spacing text-black-60 text-uppercase">Transaction Hash</label> | ||
<input id="amount" v-model="form.txHash" name="amount" class="form__input form__input-lg" /> | ||
</div> | ||
<div class="col-12 text-danger" v-if="errors.txHash"> | ||
[[errors.txHash]] | ||
</div> | ||
|
||
<!-- User address --> | ||
<div class="col-12 mb-3"> | ||
<label class="font-caption letter-spacing text-black-60 text-uppercase">Wallet Address</label> | ||
<input id="amount" v-model="form.userAddress" name="amount" class="form__input form__input-lg" /> | ||
</div> | ||
|
||
<div class="col-12 text-danger" v-if="errors.address"> | ||
[[errors.address]] | ||
</div> | ||
|
||
<div class="col-12 text-danger" v-if="errors.invalidForm"> | ||
[[errors.invalidForm]] | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
||
<div class="container mt-5"> | ||
<div class="row"> | ||
<div class="col-12 text-center"> | ||
<button class="btn btn-gc-blue btn-lg mb-3 px-5 btn-lg-padding" :disabled="submitted" type="submit" @click="ingest($event)">Add Contributions</button> | ||
</div> | ||
<div class="col-12 text-center" v-if="Object.keys(errors).length > 0"> | ||
Please verify forms errors and try again | ||
</div> | ||
<div class="col-12 text-center" v-else-if="submitted"> | ||
Processing your contributions. This may take a minute or two... | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</form> | ||
</grants-ingest-contributions> | ||
|
||
{% include 'shared/bottom_notification.html' %} | ||
{% include 'shared/footer.html' %} | ||
{% include 'shared/current_profile.html' %} | ||
{% include 'shared/analytics.html' %} | ||
{% include 'grants/shared/shared_scripts.html' %} | ||
{% include 'shared/footer_scripts.html' with vue=True ignore_inject_web3=1 %} | ||
|
||
<script type="text/javascript" src="https://cdn.ethers.io/lib/ethers-5.0.umd.min.js"></script> | ||
<script src="{% static "v2/js/grants-ingest-missing-contributions.js" %}"></script> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
|
||
<script src="{% static "v2/js/lib/ipfs-api.js" %}"></script> | ||
<script src="{% static "v2/js/ipfs.js" %}"></script> | ||
<script src="{% static "v2/js/abi.js" %}"></script> | ||
|
||
<script src="{% static "v2/js/tokens.js" %}"></script> | ||
<script src="{% static "v2/js/grants/shared.js" %}"></script> | ||
|
||
<script src="{% static "v2/js/grants/new_match.js" %}"></script> | ||
|
||
</body> | ||
|
||
<html> |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.