Skip to content

Commit

Permalink
fix merged conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gluneau committed Nov 23, 2023
1 parent a227bc6 commit c3e3ec9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
48 changes: 7 additions & 41 deletions src/staking-v3/components/Vote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default defineComponent({
ModalSelectDapp,
},
setup() {
const { constants, ledger, totalStake, hasRewards, rewards, claimLockAndStake } =
const { constants, ledger, totalStake, hasRewards, rewards, claimLockAndStake, canStake } =
useDappStaking();
const { registeredDapps } = useDapps();
const { nativeTokenSymbol } = useNetworkInfo();
Expand Down Expand Up @@ -167,39 +167,6 @@ export default defineComponent({
const protocolState = computed(() => store.getters['stakingV3/getProtocolState']);
const balanceBN = computed(() => new BN(useableBalance.value.toString()));
// TODO this should be moved to useDappStaking.
const canConfirm = (): [boolean, string] => {
const stakeAmountBN = new BN(
ethers.utils.parseEther(stakeAmount.value.toString()).toString()
);
if (!selectedDapp.value?.address) {
// Prevents NoDappSelected
return [false, t('stakingV3.noDappSelected')];
} else if (stakeAmount.value <= 0) {
// Prevents dappStaking.ZeroAmount
return [false, t('stakingV3.dappStaking.ZeroAmount')];
} else if (stakeAmountBN.gt(balanceBN.value)) {
// Prevents dappStaking.UnavailableStakeFunds
return [false, t('stakingV3.dappStaking.UnavailableStakeFunds')];
} else if (protocolState.value?.maintenance) {
// Prevents dappStaking.Disabled
return [false, t('stakingV3.dappStaking.Disabled')];
} else if (hasRewards.value) {
// Prevents dappStaking.UnclaimedRewards
// May want to auto claim rewards here
return [false, t('stakingV3.dappStaking.UnclaimedRewards')];
} else if (
// Prevents dappStaking.PeriodEndsInNextEra
protocolState.value?.periodInfo.subperiod === PeriodType.BuildAndEarn &&
protocolState.value.periodInfo.subperiodEndEra <= protocolState.value.era + 1
) {
return [false, t('stakingV3.dappStaking.PeriodEndsNextEra')];
} // Prevents dappStaking.TooManyStakedContracts
return [true, ''];
};
const handleDappsSelected = (dapps: Dapp[]): void => {
selectedDapps.value = dapps;
};
Expand All @@ -219,10 +186,10 @@ export default defineComponent({
const canAddDapp = computed<boolean>((): boolean => selectedDappAddress.value === '');
const confirm = async (): Promise<void> => {
const [result, error] = canConfirm();
if (!result) {
throw error;
}
// const [result, error] = canStake(dapp.address, dapp.amount);
// if (!result) {
// throw error;
// }
const stakeInfo = new Map<string, number>();
selectedDapps.value.forEach((dapp) => {
Expand Down Expand Up @@ -272,7 +239,6 @@ export default defineComponent({
remainLockedToken,
hasRewards,
errorMessage,
canConfirm,
rewards,
selectedDapps,
isModalSelectDapp,
Expand All @@ -287,8 +253,8 @@ export default defineComponent({
},
computed: {
isConfirmable() {
let confirmable = false;
[confirmable, this.errorMessage] = this.canConfirm();
let confirmable = true;
// [confirmable, this.errorMessage] = this.canStake(dapp.address, dapp.amount);
return confirmable;
},
},
Expand Down
12 changes: 5 additions & 7 deletions src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,18 @@ export function useDappStaking() {
return dapp?.chain.state;
};

const canStake = async (
dappAddress: string,
amount: number,
ignoreCanClaim = false
): Promise<[boolean, string]> => {

const getCurrentEraInfo = async (): Promise<void> => {
const stakingRepo = container.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3);
const eraInfo = await stakingRepo.getCurrentEraInfo();

store.commit('stakingV3/setCurrentEraInfo', eraInfo);
};

const canStake = async (amount: number): Promise<[boolean, string]> => {
const canStake = async (
dappAddress: string,
amount: number,
ignoreCanClaim = false
): Promise<[boolean, string]> => {
const stakeAmount = new BN(ethers.utils.parseEther(amount.toString()).toString());
const balanceBN = new BN(useableBalance.value.toString());
const stakingRepo = container.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3);
Expand Down

0 comments on commit c3e3ec9

Please sign in to comment.