Skip to content

Commit cc2db1b

Browse files
authored
Merge pull request #49 from hypersign-protocol/integrate/ssiUseage
Integrate/ssi useage
2 parents 522f62e + b22cce2 commit cc2db1b

File tree

3 files changed

+541
-170
lines changed

3 files changed

+541
-170
lines changed

src/store/mainStore.js

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,11 @@ const mainStore = {
12211221
headers
12221222
})
12231223
const json = await resp.json()
1224-
return json?.data
1224+
if (json?.data) {
1225+
return json?.data
1226+
} else {
1227+
return json
1228+
}
12251229
},
12261230

12271231
async fetchUsageDetailsForAService({ getters, commit }, payload) {
@@ -1237,8 +1241,13 @@ const mainStore = {
12371241
headers
12381242
})
12391243
const json = await resp.json()
1240-
commit('setUsageDetails', json?.data)
1241-
return json?.data
1244+
if (json?.data) {
1245+
commit('setUsageDetails', json?.data)
1246+
return json?.data
1247+
} else {
1248+
commit('setUsageDetails', json)
1249+
return json
1250+
}
12421251
},
12431252

12441253
// - KYC Credit
@@ -1336,6 +1345,9 @@ const mainStore = {
13361345
.then(response => response.json())
13371346
.then(json => {
13381347
if (json) {
1348+
if (json.error) {
1349+
reject(new Error(json.message[0]))
1350+
}
13391351
if (json.data.length > 0) {
13401352
const payload = json.data.map(x => {
13411353
return {
@@ -1353,7 +1365,8 @@ const mainStore = {
13531365
}
13541366

13551367
resolve(json.data)
1356-
} else {
1368+
}
1369+
else {
13571370
resolve([])
13581371
commit('setDIDList', [])
13591372
}
@@ -1406,13 +1419,12 @@ const mainStore = {
14061419
.then(json => {
14071420

14081421
if (json) {
1409-
1410-
1411-
1422+
if (json.error) {
1423+
reject(new Error(json.message[0]))
1424+
}
14121425
resolve(json.didDocument)
1413-
14141426
} else {
1415-
reject(new Error('Could not resovle'))
1427+
reject(new Error('Could not resolve'))
14161428
}
14171429

14181430
}).catch(e => {
@@ -1457,6 +1469,9 @@ const mainStore = {
14571469
.then(response => response.json())
14581470
.then(json => {
14591471
if (json) {
1472+
if (json.error) {
1473+
reject(new Error(json.message[0]))
1474+
}
14601475
const data = {
14611476
did: payload,
14621477
didDocument: json.didDocument,
@@ -1498,6 +1513,9 @@ const mainStore = {
14981513
})
14991514
.then(response => response.json())
15001515
.then(async json => {
1516+
if (json.error) {
1517+
reject(new Error(json.message[0]))
1518+
}
15011519
if (json && json.did) {
15021520
commit('insertDIDList', {
15031521
did: json.did,
@@ -1785,6 +1803,28 @@ const mainStore = {
17851803

17861804
},
17871805

1806+
// eslint-disable-next-line
1807+
async ssiCredits({ getters }, payload) {
1808+
const url = `${sanitizeUrl(getters.getSelectedService.tenantUrl)}/api/v1/credit`;
1809+
const options = {
1810+
method: "GET",
1811+
headers: {
1812+
"Content-Type": "application/json",
1813+
"Authorization": `Bearer ${getters.getSelectedService.access_token}`,
1814+
"Origin": '*'
1815+
1816+
}
1817+
}
1818+
1819+
const resp = await fetch(url, {
1820+
...options
1821+
})
1822+
const json = await resp.json()
1823+
1824+
return json
1825+
1826+
1827+
},
17881828

17891829
// eslint-disable-next-line
17901830
async ssiDashboardAllowanceStats({ getters }, payload) {

src/views/playground/SSIDashboardCredit.vue

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ h5 span {
145145
<v-card class="card p-4 mt-1">
146146
<div class="row">
147147
<div class="col-8">
148-
<p><b>Total Credits</b></p>
148+
<p><b>Total Credits Used</b></p>
149149
<p>
150150
<span style="font-size:xx-large;">
151151
{{ numberFormat(parsedAllowanceLimit) }}
@@ -171,10 +171,10 @@ h5 span {
171171
<v-card class="p-4 mt-2">
172172
<div>
173173
<p><b>Scope(s)</b></p>
174-
<p v-if="grants.length > 0">
175-
<span class="badge badge-info mx-1" v-for="eachRow in grants"
176-
v-bind:key="eachRow.authorization.msg">{{
177-
eachRow.authorization.msg.replace('/hypersign.ssi.v1.Msg', '') }}</span>
174+
<p v-if="allowance.scope.length > 0">
175+
<span class="badge badge-info mx-1" v-for="eachRow in allowance.scope"
176+
v-bind:key="eachRow">{{
177+
eachRow }}</span>
178178
</p>
179179
<p v-else>
180180
No scope granted!
@@ -378,26 +378,36 @@ export default {
378378
},
379379
async mounted() {
380380
try {
381+
381382
this.isLoading = true
382-
const payload = {
383-
// wallet: "hid1a4zqvlmp3w9ggctvc873f08k3evh3mmj2vx939",
384-
groupBy: 'daily'
385-
}
386383
387-
// get allowance
388-
const t = await this.ssiDashboardAllowanceStats(payload)
389-
if (t.allowance) {
390-
this.allowance = t.allowance
391-
this.allowance.total = 5000000
392-
this.dougnNutData = [this.parsedAllowanceLimit, this.allowance.total - this.parsedAllowanceLimit]
384+
const credits = await this.ssiCredits()
385+
386+
387+
const credit = credits.filter(each => {
388+
if (each.status == 'Active') {
389+
return each
390+
}
391+
})
392+
393+
394+
// get allowanc
395+
396+
if (credit[0]?.credit) {
397+
398+
// this.allowance = credits[0].credit.amount
399+
this.allowance.spend_limit[0].amount = credit[0].used
400+
this.allowance.total = credit[0].totalCredits
401+
this.dougnNutData = [this.allowance.total - this.parsedAllowanceLimit, this.parsedAllowanceLimit]
402+
403+
this.allowance.scope=credit[0].creditScope
404+
this.allowance.expiration = credit[0].expiresAt
405+
393406
this.redrawChart = true
394407
}
395408
396409
// get grants
397-
this.grants = await this.ssiDashboardGrantsStats(payload)
398410
399-
// get tx stats
400-
this.ssiDashboardStats = await this.ssiDashboardTxStats(payload)
401411
402412
this.isLoading = false
403413
} catch (e) {
@@ -484,7 +494,8 @@ export default {
484494
}
485495
],
486496
"expiration": null,
487-
"total": 5000000
497+
"total": 5000000,
498+
scope: []
488499
},
489500
initialBalance: 1000,
490501
leftBalance: 1000,
@@ -509,7 +520,7 @@ export default {
509520
}
510521
},
511522
methods: {
512-
...mapActions('mainStore', ['ssiDashboardTxStats', 'ssiDashboardAllowanceStats', 'ssiDashboardGrantsStats']),
523+
...mapActions('mainStore', ['ssiDashboardTxStats', 'ssiDashboardAllowanceStats', 'ssiCredits', 'ssiDashboardGrantsStats']),
513524
514525
renderChart() {
515526
const ctx = document.getElementById('doughNutChat');

0 commit comments

Comments
 (0)