Skip to content

Commit

Permalink
feat: adjust conversion and mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
ciniiia committed Oct 20, 2022
1 parent cf9e253 commit 8ffc2c2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 22 deletions.
9 changes: 7 additions & 2 deletions src/lib/api/conversion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import apiClientRequest from "@/lib/api"

export const getConversionCache = async () => {
const { data } = await apiClientRequest.get(`/conversion/cache`)
export const getConversionCache = async (from, to) => {
const { data } = await apiClientRequest.get(`/conversion/cache`, {
params: {
from,
to
}
})
return data
}
37 changes: 37 additions & 0 deletions src/lib/serviceHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export default {
data: () => ({
isLoading: false,
isErrors: null
}),

computed: {
loadingPlaceholder() {
return this.isLoading ? "Loading Data..." : ""
}
},

methods: {
/**
* Dispatch wrapper that marks the action as loading & parses errors
* @param action
* @param args
* @returns {Promise<*>}
*/
async dispatch(action, ...args) {
this.isLoading = true
try {
const response = await action.apply(this, args)

return Promise.resolve(response)
} catch (error) {
this.isErrors = error

console.error(`[${error?.response?.status}] Something went wrong, Please try again later!`)

return Promise.reject(error)
} finally {
this.isLoading = false
}
}
}
}
2 changes: 1 addition & 1 deletion src/views/Dashboard/Lab/Account/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ import CryptoJS from "crypto-js"
import { u8aToHex } from "@polkadot/util"
import Certification from "./Certification"
import {uploadFile, getFileUrl} from "@/lib/pinata-proxy"
import serviceHandler from "@/lib/metamask/mixins/serviceHandler"
import serviceHandler from "@/lib/serviceHandler"
import DialogUnstake from "@/components/Dialog/DialogUnstake"
import { generalDebounce } from "@/utils"
import Dialog from "@/components/Dialog"
Expand Down
11 changes: 5 additions & 6 deletions src/views/Dashboard/Lab/Registration/Services/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export default {
data: () => ({
serviceId: "",
currentDAIprice: 0,
usdRate: 0,
document: {
category: "",
dnaCollectionProcess: "",
Expand All @@ -342,7 +342,7 @@ export default {
isLoading: false,
isSubmiting: false,
isUploading: false,
currencyList: ["DAI", "Ethereum", "USN", "USDT"],
currencyList: ["USN", "USDT"],
listExpectedDuration: [
{ text: "Hours", value: "Hours" },
{ text: "Days", value: "Days" }
Expand All @@ -364,8 +364,7 @@ export default {
async created() {
this.dnaCollectionProcessList = (await getDNACollectionProcess()).data
await this.getServiceCategory()
const { daiToUsd } = await getConversionCache()
this.currentDAIprice = daiToUsd ?? 1
this.usdRate = await getConversionCache(this.document.currency, "USD")
},
computed: {
Expand All @@ -383,11 +382,11 @@ export default {
}),
priceHint() {
return `${this.document.price} ${this.document.currency} = ${(this.currentDAIprice * this.document.price).toFixed(4)} USD`
return `${this.document.price} ${this.document.currency} = ${(this.usdRate * this.document.price).toFixed(4)} USD`
},
qcPriceHint() {
return `${this.document.qcPrice} ${this.document.currency} = ${(this.currentDAIprice * this.document.qcPrice).toFixed(4)} USD`
return `${this.document.qcPrice} ${this.document.currency} = ${(this.usdRate * this.document.qcPrice).toFixed(4)} USD`
},
fieldRequiredRule() {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Dashboard/Lab/Registration/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ import { uploadFile, getFileUrl } from "@/lib/pinata-proxy"
import Certification from "./Certification"
import Stepper from "./Stepper"
import { getLocations, getStates, getCities } from "@/lib/api"
import serviceHandler from "@/lib/metamask/mixins/serviceHandler"
import serviceHandler from "@/lib/serviceHandler"
import Kilt from "@kiltprotocol/sdk-js"
import CryptoJS from "crypto-js"
import { u8aToHex } from "@polkadot/util"
Expand Down
11 changes: 5 additions & 6 deletions src/views/Dashboard/Lab/Services/Add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export default {
kitPurchaseLink: null,
imageUrl: "",
testResultSampleUrl: "",
currentDAIprice: 0,
usdRate: 0,
statusLab: null,
labInfo: null,
messageWarning: {},
Expand All @@ -322,7 +322,7 @@ export default {
listCategories:[],
isLoading: false,
showModalAlert: false,
currencyList: ["DAI", "Ethereum", "USN", "USDT"],
currencyList: ["USN", "USDT"],
listExpectedDuration: ["Hours", "Days"],
dnaCollectionProcessList: [],
isBiomedical: false,
Expand All @@ -341,11 +341,11 @@ export default {
}),
priceHint() {
return `${this.document.price} ${this.document.currency} = ${(this.currentDAIprice * this.document.price).toFixed(4)} USD`
return `${this.document.price} ${this.document.currency} = ${(this.usdRate * this.document.price).toFixed(4)} USD`
},
qcPriceHint() {
return `${this.document.qcPrice} ${this.document.currency} = ${(this.currentDAIprice * this.document.qcPrice).toFixed(4)} USD`
return `${this.document.qcPrice} ${this.document.currency} = ${(this.usdRate * this.document.qcPrice).toFixed(4)} USD`
},
hasServicePayload() {
Expand Down Expand Up @@ -398,8 +398,7 @@ export default {
this.validate()
this.prefillValues()
await this.getServiceCategory()
const { daiToUsd } = await getConversionCache()
this.currentDAIprice = daiToUsd ?? 1
this.usdRate = await getConversionCache(this.document.currency, "USD")
},
methods: {
Expand Down
11 changes: 5 additions & 6 deletions src/views/Dashboard/Lab/Services/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ export default {
files: [],
testResultSampleFile:[],
isLoading: false,
currentDAIprice: 0,
usdRate: 0,
isUploading: false,
currencyList: ["DAI", "Ethereum", "USN", "USDT"],
currencyList: ["USN", "USDT"],
currencyType: "",
listExpectedDuration: ["Hours", "Days"],
listCategories: [],
Expand All @@ -317,11 +317,11 @@ export default {
}),
priceHint() {
return `${this.document.price} ${this.document.currency} = ${(this.currentDAIprice * this.document.price).toFixed(4)} USD`
return `${this.document.price} ${this.document.currency} = ${(this.usdRate * this.document.price).toFixed(4)} USD`
},
qcPriceHint() {
return `${this.document.qcPrice} ${this.document.currency} = ${(this.currentDAIprice * this.document.qcPrice).toFixed(4)} USD`
return `${this.document.qcPrice} ${this.document.currency} = ${(this.usdRate * this.document.qcPrice).toFixed(4)} USD`
},
fieldRequiredRule() {
Expand Down Expand Up @@ -397,8 +397,7 @@ export default {
this.id = this.$route.params.id
await this.getServiceCategory()
await this.getService(this.$route.params.id)
const { daiToUsd } = await getConversionCache()
this.currentDAIprice = daiToUsd ?? 1
this.usdRate = await getConversionCache(this.document.currency, "USD")
},
methods: {
Expand Down

0 comments on commit 8ffc2c2

Please sign in to comment.