Skip to content

Commit

Permalink
Fetch rewards for evm account
Browse files Browse the repository at this point in the history
  • Loading branch information
bobo-k2 committed Dec 22, 2023
1 parent 0bda4ed commit ca11ac7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,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
13 changes: 13 additions & 0 deletions src/staking-v3/logic/services/DappStakingServiceEvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class DappStakingServiceEvm extends DappStakingService implements IDappSt
});
}

// @inheritdoc
public async getStakerInfo(
address: string,
includePreviousPeriods: boolean
Expand All @@ -61,6 +62,18 @@ export class DappStakingServiceEvm extends DappStakingService implements IDappSt
return await super.getStakerInfo(ss58Address, includePreviousPeriods);
}

// @inheritdoc
public async getStakerRewards(senderAddress: string): Promise<bigint> {
const ss58Address = await this.getSS58Address(senderAddress);
return await super.getStakerRewards(ss58Address);
}

// @inheritdoc
public async getBonusRewards(senderAddress: string): Promise<bigint> {
const ss58Address = await this.getSS58Address(senderAddress);
return await super.getBonusRewards(ss58Address);
}

private async getSS58Address(evmAddress: string): Promise<string> {
return await this.accountUnificationRepository.getConvertedNativeAddress(evmAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class AccountUnificationRepository implements IAccountUnificationReposito
Guard.ThrowIfUndefined('evmAddress', evmAddress);

const api = await this.api.getApi();
const nativeAddress = api.query.hasOwnProperty('unifiedAccounts') // hasProperty(api.query, 'unifiedAccounts')
const nativeAddress = hasProperty(api.query, 'unifiedAccounts')
? await api.query.unifiedAccounts.evmToNative<AccountId32>(evmAddress)
: '';

Expand Down

0 comments on commit ca11ac7

Please sign in to comment.