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

feat: added EVM supports #1102

Merged
merged 18 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
.eslintrc.js
babel.config.js
/src-ssr
/src-pwa
/tests/polkadot_wallet
/tests/metamask_wallet
14 changes: 9 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import { useAccount, useAppRouter } from 'src/hooks';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import {
AccountLedgerChangedMessage,
IDappStakingRepository,
IDappStakingService,
ProtocolStateChangedMessage,
} from './staking-v3';
import { useDappStaking, useDapps } from './staking-v3/hooks';
Expand Down Expand Up @@ -179,15 +179,19 @@ export default defineComponent({

// Handle wallet change so we can inject proper wallet
let previousAddress: string | undefined = undefined;
watch([isEthWallet, currentWallet, isH160, currentAccountName], () => {
watch([isEthWallet, currentWallet, isH160, currentAccountName], async () => {
setCurrentWallet(isEthWallet.value, currentWallet.value);

// Subscribe to an account specific dApp staking v3 data.
if (!isDappStakingV3.value) return;

// Memo: Can't use senderSs58Account here because unified account is not stored to vuex yet
// and senderSs58Account contains evm mapped address which is incorrect for unified account.
if (currentAccount.value && currentAccount.value !== previousAddress) {
container
.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3)
.startAccountLedgerSubscription(currentAccount.value);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.startAccountLedgerSubscription(currentAccount.value);
fetchStakerInfoToStore();
getAllRewards();
fetchTiersConfigurationToStore();
Expand Down
4 changes: 3 additions & 1 deletion src/staking-v3/components/Vote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ export default defineComponent({
}

if (selectedDappAddress.value) {
const dapp = dapps.value.find((dapp) => dapp.address === selectedDappAddress.value);
const dapp = dapps.value.find(
(dapp) => dapp.address.toLowerCase() === selectedDappAddress.value.toLowerCase()
);
if (dapp) {
selectedDapps.value = [dapp];
}
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/components/my-staking/MyDapps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default defineComponent({
},
},
setup() {
const { registeredDapps, getDapp } = useDapps();
const { getDapp } = useDapps();
const { navigateToVote, navigateToMove } = useDappStakingNavigation();
const { unstake, unstakeFromUnregistered } = useDappStaking();

Expand Down
63 changes: 43 additions & 20 deletions src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { $api } from 'boot/api';
import { computed } from 'vue';
import { getShortenAddress } from '@astar-network/astar-sdk-core';
import { container } from 'src/v2/common';
import {
AccountLedger,
Expand Down Expand Up @@ -158,13 +157,16 @@ export function useDappStaking() {
: true;

const unstake = async (dapp: CombinedDappInfo, amount: number): Promise<void> => {
const [result, error] = await canUnStake(dapp.chain.address, amount);
if (!result) {
popError(error);
return;
}

const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
// TODO check implementation canStake, canUnstake
// const [result, error] = await canUnStake(dapp.chain.address, amount);
// if (!result) {
// popError(error);
// return;
// }

const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.claimUnstakeAndUnlock(
dapp.chain.address,
amount,
Expand All @@ -180,7 +182,9 @@ export function useDappStaking() {
};

const unstakeFromUnregistered = async (dappAddress: string, dappName: string): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.claimAllAndUnstakeFromUnregistered(
currentAccount.value,
dappAddress,
Expand All @@ -199,7 +203,9 @@ export function useDappStaking() {
};

const claimStakerRewards = async (): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.claimStakerRewards(currentAccount.value, 'success');
const staker = await stakingService.getStakerRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, staker });
Expand All @@ -211,7 +217,9 @@ export function useDappStaking() {
unstakeFromAddress: string,
unstakeAmount: bigint
): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();

await stakingService.claimLockAndStake(
currentAccount.value,
Expand All @@ -230,15 +238,19 @@ export function useDappStaking() {
};

const claimBonusRewards = async (): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();

await stakingService.claimBonusRewards(currentAccount.value, 'success');
const bonus = await stakingService.getBonusRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, bonus });
};

const claimDappRewards = async (contractAddress: string): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);

const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
if (contractAddress) {
await stakingService.claimDappRewards(contractAddress, currentAccount.value, 'success');
const dApp = await stakingService.getDappRewards(contractAddress);
Expand All @@ -249,7 +261,10 @@ export function useDappStaking() {
};

const claimStakerAndBonusRewards = async (): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();

await stakingService.claimStakerAndBonusRewards(
currentAccount.value,
t('stakingV3.claimRewardSuccess')
Expand All @@ -260,13 +275,17 @@ export function useDappStaking() {
};

const withdraw = async (): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.claimUnlockedTokens(currentAccount.value, t('stakingV3.withdrawSuccess'));
getCurrentEraInfo();
};

const relock = async (): Promise<void> => {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.relockUnlockingTokens(currentAccount.value, t('stakingV3.relockSuccess'));
};

Expand All @@ -280,7 +299,9 @@ export function useDappStaking() {
};

const getAllRewards = async (): Promise<void> => {
const stakingV3service = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
const stakingV3service = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
const ownedContractAddress = getOwnedDappAddress();

let staker = BigInt(0);
Expand Down Expand Up @@ -439,8 +460,10 @@ export function useDappStaking() {
return;
}

const stakingRepo = container.get<IDappStakingRepository>(Symbols.DappStakingRepositoryV3);
const stakerInfo = await stakingRepo.getStakerInfo(currentAccount.value, false);
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
const stakerInfo = await stakingService.getStakerInfo(currentAccount.value, false);

store.commit('stakingV3/setStakerInfo', stakerInfo, { root: true });
};
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/hooks/useDappStakingNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function useDappStakingNavigation() {

const navigateToVote = (dAppAddress: string | undefined = undefined): void => {
const base = networkParam + Path.DappStaking + Path.Vote;
router.push(`${base}?dappAddress=${dAppAddress ?? ''}`);
router.push(`${base}?dappAddress=${dAppAddress?.toLowerCase() ?? ''}`);
};

const navigateToMove = (dAppAddress: string): void => {
Expand Down
Loading
Loading