Skip to content

Commit

Permalink
fix: bugs on request test (#470)
Browse files Browse the repository at this point in the history
* fix: bugs on request testt

* fix: typo on navbar

* fix: remove console
  • Loading branch information
ciniiia authored Jun 10, 2022
1 parent 745d347 commit e858020
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 95 deletions.
133 changes: 81 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/common/lib/metamask/escrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export async function sendPaymentOrder(api, orderId, ethAccount, sellerEth) {
const payAmount = Number(testingPrice) + Number(qcPrice)
const escrowAddress = process.env.VUE_APP_DEBIO_ESCROW_ETH_ADDRESS


const txData = contracEscrowInterface.methods
.payOrder(
orderId,
Expand Down
31 changes: 13 additions & 18 deletions src/views/Dashboard/Customer/Home/RequestTest/PaymentDetailCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
.menu-card__details
.menu-card__sub-title Service Price
.menu-card__price
| {{ servicePrice }}
| {{ currency }}
| {{ dataService.servicePrice }}
| {{ dataService.currency }}


.menu-card__details
.menu-card__sub-title Quality Control Price
.menu-card__price
| {{ qcPrice }}
| {{ currency }}
| {{ dataService.qcPrice }}
| {{ dataService.currency }}


.menu-card__operation +
hr.menu-card__line

.menu-card__details
.menu-card__sub-title-medium Total Price
.menu-card__price-medium
| {{ totalPrice }}
| {{ currency}}
| {{ dataService.totalPrice }}
| {{ dataService.currency}}


.menu-card__details(v-if="stakingFlow")
Expand Down Expand Up @@ -58,7 +59,7 @@
| {{ currency }}

div(class="text-center" v-if="!isCancelled")
div(v-if="!success" class="mt-3 d-flex justify-center align-center")
div(v-if="!success && !isCreated" class="mt-3 d-flex justify-center align-center")
ui-debio-button(
:class="setMargin"
color="secondary"
Expand All @@ -85,7 +86,7 @@
@click="toEtherscan"
) View Etherscan

div(v-if="success && status === 'Unpaid'" class="d-flex justify-space-between align-center pa-4 mt-8 me-3")
div(v-if="status === 'Unpaid'" class="d-flex justify-space-between align-center pa-4 mt-8 me-3")
ui-debio-button(
color="secondary"
width="46%"
Expand All @@ -106,6 +107,7 @@
template
PaymentReceiptDialog(
:show="showReceipt"
:serviceDetail="dataService"
@onContinue="onContinue"
@close="showReceipt = false"
)
Expand Down Expand Up @@ -181,10 +183,7 @@ export default {
isBalanced: false,
excessAmount: 0,
showAlert: false,
servicePrice: 0,
qcPrice: 0,
totalPrice: 0,
currency: "",
isCreated: false,
success: false
}),
Expand All @@ -195,13 +194,9 @@ export default {
this.success = true
}
if (this.dataService.detailPrice) {
this.servicePrice = this.formatPrice((this.dataService.detailPrice.price_components[0].value).replaceAll(",", ""))
this.qcPrice = this.formatPrice((this.dataService.detailPrice.additional_prices[0].value).replaceAll(",", ""))
this.totalPrice = this.formatPrice(this.dataService.price).replaceAll(",", "")
this.currency = this.dataService.currency.toUpperCase()
if(this.$route.params.id) {
this.isCreated = true
}
// get last order id
this.lastOrder = await queryLastOrderHashByCustomer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,51 +217,50 @@ export default {
this.detailOrder = await queryOrderDetailByOrderID(this.api, this.lastOrder)
this.status = this.detailOrder.status
if (this.status === "Unpaid" && !this.$route.params.id) {
this.show = false
this.showAlert = true
this.closeDialog()
return
}
}
this.ethAccount = await startApp()
const ethAddress = await queryEthAdressByAccountId(this.api, this.wallet.address)
if (this.ethAccount.currentAccount === "no_install") {
this.isLoading = false
this.show = false
this.password = ""
this.showError = true
this.error = "Please install MetaMask!"
this.errorMsg = "Please install MetaMask!"
this.closeDialog()
return
}
// cek kalo udah binding wallet
if (!this.metamaskWalletAddress) {
this.isLoading = false
this.show = false
this.password = ""
if (ethAddress !== this.ethAccount.accountList[0]) {
this.showError = true
this.error = "Metamask has no address ETH."
this.errorMsg = "Please connect your wallet"
this.closeDialog()
return
}
// check ETH Balance
const balance = await getBalanceETH(this.metamaskWalletAddress)
const balance = await getBalanceETH(ethAddress)
if (balance <= 0 ) {
this.isLoading = false
this.show = false
this.password = ""
this.showError = true
this.error = "You don't have enough ETH"
this.errorMsg = "You don't have enough ETH"
this.closeDialog()
return
}
// check DAI Balance
const daiBalance = await getBalanceDAI(this.metamaskWalletAddress)
const daiBalance = await getBalanceDAI(ethAddress)
if (Number(daiBalance) < Number(this.selectedService.totalPrice)) {
this.isLoading = false
this.show = false
this.password = ""
this.showError = true
this.error = "You don't have enough DAI"
this.errorMsg = "You don't have enough DAI"
this.closeDialog()
return
}
Expand Down Expand Up @@ -293,8 +292,7 @@ export default {
this.showError = true
this.errorTitle = error.title
this.errorMsg = error.message
this.show = false
}
}
},
async payOrder () {
Expand All @@ -305,19 +303,18 @@ export default {
this.wallet.address
)
this.detailOrder = await queryOrderDetailByOrderID(this.api, this.lastOrder)
const ethAddress = await queryEthAdressByAccountId(this.api, this.wallet.address)
const stakingAmountAllowance = await checkAllowance(ethAddress)
const stakingAmountAllowance = await checkAllowance(this.metamaskWalletAddress)
const totalPrice = this.selectedService.price
if (stakingAmountAllowance < totalPrice ) {
if (stakingAmountAllowance < this.selectedService.totalPrice ) {
const txHash = await approveDaiStakingAmount(
this.metamaskWalletAddress,
totalPrice
ethAddress,
this.selectedService.totalPrice
)
await getTransactionReceiptMined(txHash)
}
this.txHash = await sendPaymentOrder(this.api, this.lastOrder, this.metamaskWalletAddress, this.ethSellerAddress)
this.txHash = await sendPaymentOrder(this.api, this.lastOrder, ethAddress, this.ethSellerAddress)
await getTransactionReceiptMined(this.txHash)
await postTxHash(this.lastOrder, this.txHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export default {
PaymentDetailCard
},
mounted() {
if (!this.selectedService) {
this.$router.push({ name: "customer-payment-history" })
}
},
computed: {
...mapState({
selectedService: (state) => state.testRequest.products,
Expand Down

0 comments on commit e858020

Please sign in to comment.