Skip to content

Commit

Permalink
feat: Finalize Request when staking (#571)
Browse files Browse the repository at this point in the history
* fix: order list on dashboard

* remove console

* feat: add finalize service request

Co-authored-by: Hildegard Lydia <37687466+hilyds@users.noreply.github.com>
  • Loading branch information
ciniiia and hilyds authored Nov 9, 2022
1 parent fae7037 commit ea465a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib/polkadotProvider/command/service-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export async function finalizeServiceRequest(api, pair, requestId) {
const result = await api.tx.serviceRequest
.finalizeRequest(requestId)
.signAndSend(pair, { nonce: -1 })
return result.toHuman()
}
9 changes: 9 additions & 0 deletions src/lib/polkadotProvider/query/service-request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export async function getRequestByOrderId(api, orderId){
const res = await api.query.serviceRequest.requestByOrderId(orderId)
return res.toHuman()
}

export async function getRequestById(api, requestId) {
const res = await api.query.serviceRequest.requestById(requestId)
return res.toHuman()
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ import { submitTestResult, processDnaSample, submitTestResultFee, processDnaSamp
import { queryDnaTestResults } from "@/lib/polkadotProvider/query/geneticTesting"
import localStorage from "@/lib/local-storage"
import DialogErrorBalance from "@/components/Dialog/DialogErrorBalance"
import { getRequestByOrderId } from "@/lib/polkadotProvider/query/service-request"
import { finalizeServiceRequest } from "@/lib/polkadotProvider/command/service-request"
export default {
Expand Down Expand Up @@ -330,7 +332,8 @@ export default {
...mapState({
mnemonic: state => state.substrate.mnemonicData,
web3: state => state.metamask.web3
web3: state => state.metamask.web3,
lastEventData: (state) => state.substrate.lastEventData
}),
disableRejectButton(){
Expand Down Expand Up @@ -382,6 +385,15 @@ export default {
watch: {
mnemonic(val) {
if (val) this.initialData()
},
async lastEventData(e) {
const dataEvent = JSON.parse(e.data.toString())
if (dataEvent[0].sellerId === this.pair.address) {
if (e.method === "OrderFulfilled" && dataEvent[0].orderFlow === "StakingRequestService" ){
await this.finalizeOrder(dataEvent[0].id)
}
}
}
},
Expand Down Expand Up @@ -494,6 +506,11 @@ export default {
this.sendingNotification()
},
async finalizeOrder(id) {
const requestId = await getRequestByOrderId(this.api, id)
await finalizeServiceRequest(this.api, this.pair, requestId)
},
addFileUploadEventListener(fileInputRef, fileType) {
this.hasGenomeError = []
this.hasReportError = []
Expand Down

0 comments on commit ea465a8

Please sign in to comment.