Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/merge dev to main #80

Merged
merged 11 commits into from
Jul 30, 2024
19 changes: 7 additions & 12 deletions src/common/modals/compositions/ChangeLockModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,24 @@ const clearFields = () => {
form.lockPeriod = ''
}

const init = () => {
if (!props.isShown) {
return
}
form.lockPeriod = new Time().isAfter(
userPoolData.value?.claimLockEnd?.toString() ?? 0,
)
? ''
: userPoolData.value?.claimLockEnd?.toString() ?? ''
}

watch(
() => [
props.poolId,
form.lockPeriod,
web3ProvidersStore.provider.selectedAddress,
web3ProvidersStore.provider.chainId,
userPoolData.value?.claimLockEnd,
],
() => fetchExpectedMultiplier(form.lockPeriod),
{ immediate: true },
)

watch(() => props.isShown, init)
watch(
() => [props.isShown, userPoolData.value?.claimLockEnd],
() => {
form.lockPeriod = String(userPoolData.value?.claimLockEnd.toNumber() || '')
},
)
</script>

<style lang="scss" scoped>
Expand Down
1 change: 1 addition & 0 deletions src/common/modals/compositions/DepositModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ withDefaults(
isShown: boolean
poolId: number
minStake: BigNumber
claimLockEnd: string
isCloseByClickOutside?: boolean
}>(),
{
Expand Down
8 changes: 7 additions & 1 deletion src/composables/use-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type BigNumber, type Erc1967ProxyType } from '@/types'
import { useTimestamp } from '@vueuse/core'
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { ethers } from 'ethers'
import { Time } from '@distributedlab/tools'

const MULTIPLIER_SCALE = 21 //digits
const REWARDS_DIVIDER = 10000
Expand Down Expand Up @@ -157,11 +158,16 @@ export const usePool = (poolId: number) => {

const fetchExpectedMultiplier = async (lockPeriod: string) => {
try {
const lockStart = new Time().isAfter(
userPoolData.value?.claimLockStart.toString(),
)
? new Time().timestamp
: userPoolData.value?.claimLockStart.toString() ?? 0
const multiplier =
//eslint-disable-next-line max-len
await web3ProvidersStore.erc1967ProxyContract.providerBased.value.getClaimLockPeriodMultiplier(
poolId,
0,
lockStart,
lockPeriod || 0,
)
expectedRewardsMultiplier.value = humanizeRewards(multiplier)
Expand Down
19 changes: 13 additions & 6 deletions src/forms/DepositForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ const allowances = reactive<Record<CURRENCIES, BigNumber | null>>({
})

const { t } = useI18n()
const { expectedRewardsMultiplier, fetchExpectedMultiplier } = usePool(
props.poolId,
)
const { expectedRewardsMultiplier, fetchExpectedMultiplier, userPoolData } =
usePool(props.poolId)
const web3ProvidersStore = useWeb3ProvidersStore()

const action = computed<ACTIONS>(() => {
Expand Down Expand Up @@ -304,18 +303,26 @@ const init = async (): Promise<void> => {
ErrorHandler.process(error)
}

form.lockPeriod = String(userPoolData.value?.claimLockEnd.toNumber() || '')

isInitializing.value = false
}

watch(
() => [
props.poolId,
web3ProvidersStore.erc1967ProxyContract.providerBased.value.address,
web3ProvidersStore.provider.selectedAddress,
form.lockPeriod,
userPoolData.value?.claimLockEnd,
],
() => fetchExpectedMultiplier(form.lockPeriod),
{ immediate: true },
async () => {
if (!form.lockPeriod) {
form.lockPeriod = String(
userPoolData.value?.claimLockEnd.toNumber() || '',
)
}
await fetchExpectedMultiplier(form.lockPeriod)
},
)

onMounted(() => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/HomePage/views/PublicPoolView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
v-model:is-shown="isDepositModalShown"
:pool-id="poolId"
:min-stake="poolData.minimalStake"
:claim-lock-end="userPoolData?.claimLockEnd?.toString() ?? ''"
/>
</div>
</transition>
Expand Down
Loading