Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
nutrina committed Jun 16, 2022
2 parents 7bf1185 + 3e1e0f4 commit 24ee5e5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
dashboard.views.verify_passport,
name='verify_passport'
),
url(
r'^api/v2/profile/(?P<handle>.*)/passport/trust_bonus',
dashboard.views.get_passport_trust_bonus,
name='get_passport_trust_bonus'
),


# grants1.0 Verification Services
Expand Down
47 changes: 46 additions & 1 deletion app/assets/v2/js/pages/profile-trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ Vue.component('active-trust-manager', {
passportUrl: 'https://passport.gitcoin.co/',
rawPassport: undefined,
trustBonus: (document.trust_bonus * 100) || 50,
trustBonusStatus: document.trust_bonus_status,
isTrustBonusRefreshInProggress: false,
loading: false,
verificationError: false,
saveSuccessMsg: document.trust_bonus_status === 'pending_celery' ? 'Your Passport has been submitted.' : false,
roundStartDate: parseMonthDay(document.round_start_date),
roundEndDate: parseMonthDay(document.round_end_date),
services: document.services || [],
Expand All @@ -52,6 +55,11 @@ Vue.component('active-trust-manager', {
document.addEventListener('dataWalletReady', () => (!this.passportVerified || this.loading) && this.connectPassport(true));
// on wallet disconnect (clear Passport state)
document.addEventListener('walletDisconnect', () => (!this.passportVerified ? this.reset(true) : false));
// start watching for trust bonus status updates, in case the calculation is still pending
console.log('geri checking this.trustBonusStatus', this.trustBonusStatus);
if (this.trustBonusStatus === 'pending_celery') {
this.refreshTrustBonus();
}
},
computed: {
serviceDict: function() {
Expand Down Expand Up @@ -119,6 +127,38 @@ Vue.component('active-trust-manager', {
await this.savePassport();
}
},
async refreshTrustBonus() {
// if we have sig, attempt to save the passports details into the backend
const url = `/api/v2/profile/${document.contxt.github_handle}/passport/trust_bonus`;

const _getTrustBonus = () => {
const getTrustBonusRequest = fetchData(url, 'GET');

$.when(getTrustBonusRequest).then(response => {
this.trustBonusStatus = response.passport_trust_bonus_status;

if (response.passport_trust_bonus_status === 'pending_celery') {
_refreshTrustBonus();
} else {
this.trustBonus = (parseFloat(response.passport_trust_bonus) * 100) || 50;
this.isTrustBonusRefreshInProggress = false;
this.saveSuccessMsg = false;
}

}).catch((err) => {
_refreshTrustBonus();
});
};

const _refreshTrustBonus = () => {
setTimeout(_getTrustBonus, 5000);
};

if (!this.isTrustBonusRefreshInProggress) {
this.isTrustBonusRefreshInProggress = true;
_refreshTrustBonus();
}
},
/*
* The ignoreErrors attribute is intended to be used when calling this function automatically on page
* load and not expecting this to trigger an error.
Expand All @@ -128,6 +168,7 @@ Vue.component('active-trust-manager', {
this.loading = true;
// clear error state
this.verificationError = false;
this.saveSuccessMsg = false;

// clear all state
this.reset(true);
Expand Down Expand Up @@ -249,6 +290,7 @@ Vue.component('active-trust-manager', {
async savePassport() {
// enter loading
this.loading = true;
this.saveSuccessMsg = false;

// attempt to verify the passport
try {
Expand Down Expand Up @@ -288,7 +330,10 @@ Vue.component('active-trust-manager', {
// mark as verified
this.passportVerified = true;
// notify success (temp)
_alert('Your Passport\'s Trust Bonus has been saved!', 'success', 6000);
// _alert('Your Passport\'s Trust Bonus has been saved!', 'success', 6000);
this.saveSuccessMsg = 'Your Passport has been submitted.';
this.trustBonusStatus = 'refresh-pending';
this.refreshTrustBonus();
}
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/passport_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_stream_ids(did, ids=[CERAMIC_GITCOIN_PASSPORT_STREAM_ID]):

def get_passport(did="", stream_ids=[]):
# get streamIds if non are provided
stream_ids = stream_ids if len(stream_ids) > 0 else get_stream_ids(did, [CERAMIC_PASSPORT_STREAM_ID])
stream_ids = stream_ids if len(stream_ids) > 0 else get_stream_ids(did, [CERAMIC_GITCOIN_PASSPORT_STREAM_ID])

# attempt to pull content
passport = get_stamps(get_passport_stream(stream_ids))
Expand Down
2 changes: 2 additions & 0 deletions app/dashboard/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
document.round_end_date = {{ round_end_date }};
document.is_passport_connected = {% if is_passport_connected %}{{ is_passport_connected }}{% else %}0{% endif %};
document.trust_bonus = {% if passport_trust_bonus %}{{ passport_trust_bonus }}{% else %}0{% endif %};
document.trust_bonus_status = {% if passport_trust_bonus_status %}"{{ passport_trust_bonus_status }}"{% else %}null{% endif %};
document.trust_bonus_last_updated = {% if passport_trust_bonus_last_updated %}"{{ passport_trust_bonus_last_updated }}"{% else %}null{% endif %};
document.passport = {% if passport %}{{ passport|safe }}{% else %}null{% endif %};

</script>
Expand Down
24 changes: 18 additions & 6 deletions app/dashboard/templates/profiles/trust-vue.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,18 @@ <h1>Trust Bonus</h1>
<div :class="`${(step < 2 && !passportVerified)? 'gc-text-disabled' : 'gc-text-default'}`">
Return to present your stamps to Gitcoin and receive a Trust Bonus score.
</div>
<b-button v-if="step === 2 && !passportVerified" variant="primary" style="max-height: 52px;" class="col-12 col-md-auto btn btn-lg px-5 mt-3 flex-shrink-0 btn-primary" :disabled="loading" @click="() => passportActionHandlerRefresh()">
Score Passport
</b-button>
<b-button v-if="passportVerified" variant="dark" style="max-height: 52px;" class="col-12 col-md-auto btn btn-lg px-5 mt-3 flex-shrink-0 btn-dark" :disabled="loading" @click="() => passportActionHandlerConnect()">
Refresh Passport
</b-button>
<div class="d-flex flex-row">
<b-button v-if="step === 2 && !passportVerified" variant="primary" style="max-height: 52px;" class="col-12 col-md-auto btn btn-lg px-5 mt-3 flex-shrink-0 btn-primary" :disabled="loading" @click="() => passportActionHandlerRefresh()">
Score Passport
</b-button>
<b-button v-if="passportVerified" variant="dark" style="max-height: 52px;" class="col-12 col-md-auto btn btn-lg px-5 mt-3 flex-shrink-0 btn-dark" :disabled="loading" @click="() => passportActionHandlerConnect()">
Refresh Passport
</b-button>
<div v-if="trustBonusStatus !== 'saved'" class="ml-2 mt-3 py-2 border rounded button btn-lg">
<div class="spinner-border spinner-border-sm"></div>
Validating Passport ...
</div>
</div>
<div v-if="step === 2 && verificationError" class="d-flex px-0 pt-3 my-auto">
<i class="fa-shield-virus fas mt-1 px-1" style="color: #d03e63"></i>
<div class="d-inline ml-2 my-auto">
Expand Down Expand Up @@ -127,6 +133,12 @@ <h1>Trust Bonus</h1>
<span style="color: #d03e63"><div class="font-smaller-2" @click="handleErrorClick" v-html="verificationError"></div></span>
</div>
</div>
<div v-if="saveSuccessMsg" class="d-flex px-0 pt-3 my-auto">
<i class="fa-shield-virus fas mt-1 px-1" style="color: #059669"></i>
<div class="d-inline ml-2 my-auto">
<span style="color: #059669"><div class="font-smaller-2" v-html="saveSuccessMsg"></div></span>
</div>
</div>
</div>
</li>
</ul>
Expand Down
17 changes: 16 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,9 @@ def get_profile_tab(request, profile, tab, prev_context):
# gets passport_trust_bonus || trust_bonus
context['trust_bonus'] = profile.final_trust_bonus
# this score will be displayed on first load if the passport is connected
context['passport_trust_bonus'] = profile.passport_trust_bonus if profile.passport_trust_bonus is not None else 'null'
context['passport_trust_bonus'] = profile.passport_trust_bonus
context['passport_trust_bonus_status'] = profile.passport_trust_bonus_status
context['passport_trust_bonus_last_updated'] = profile.passport_trust_bonus_last_updated.isoformat() if profile.passport_trust_bonus_last_updated else None

# dump the full passport into the context
try:
Expand Down Expand Up @@ -3071,6 +3073,19 @@ def check_passport_stamps(request, handle):
})


@login_required
@require_GET
def get_passport_trust_bonus(request, handle):
user = request.user
profile = user.profile

return JsonResponse({
"passport_trust_bonus": profile.passport_trust_bonus,
"passport_trust_bonus_status": profile.passport_trust_bonus_status,
"passport_trust_bonus_last_updated": profile.passport_trust_bonus_last_updated
})


@login_required
@require_POST
def verify_passport(request, handle):
Expand Down

0 comments on commit 24ee5e5

Please sign in to comment.