-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ref, reactive, computed, watch } from '@vue/composition-api'; | ||
import debounce from 'debounce-promise'; | ||
import {getDiscountForHolder as _getDiscountForHolder} from '@/api/hub.js'; | ||
|
||
export default function useHubDiscount() { | ||
// two different debounced functions | ||
const debouncedGetDiscountMinter = makeDebouncedGetDiscount(); | ||
const debouncedGetDiscountEth = makeDebouncedGetDiscount(); | ||
|
||
const discountProps = reactive({ | ||
minterAddress: '', | ||
ethAddress: '', | ||
}); | ||
const discountMinter = ref(0); | ||
const discountEth = ref(0); | ||
const discount = computed(() => { | ||
return Math.max(discountEth.value, discountMinter.value); | ||
}); | ||
|
||
const getMinterDiscount = async () => { | ||
discountMinter.value = await debouncedGetDiscountMinter(discountProps.minterAddress); | ||
}; | ||
const getEthDiscount = async () => { | ||
discountEth.value = await debouncedGetDiscountEth(discountProps.ethAddress); | ||
}; | ||
|
||
watch(() => discountProps.minterAddress, getMinterDiscount); | ||
watch(() => discountProps.ethAddress, getEthDiscount); | ||
|
||
return { | ||
discount, | ||
discountProps, | ||
}; | ||
} | ||
|
||
function getDiscountForHolder(address) { | ||
return _getDiscountForHolder(address) | ||
.catch((error) => { | ||
console.log(error); | ||
return 0; | ||
}); | ||
} | ||
|
||
function makeDebouncedGetDiscount() { | ||
return debounce(getDiscountForHolder, 1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Vue from 'vue'; | ||
import VueCompositionAPI from '@vue/composition-api'; | ||
|
||
Vue.use(VueCompositionAPI); |