Skip to content

Commit

Permalink
Account unification - add mapping fee to total costs calculation (#1000)
Browse files Browse the repository at this point in the history
* Add mapping fee to total costs calculation

* Fix for missing AuIcon import

* extra AuIcon import

---------

Co-authored-by: Gregory Luneau <[email protected]>
Co-authored-by: Gregory Luneau <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2023
1 parent 9e0d586 commit bb8c86f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/hooks/wallet/useAccountUnification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useI18n } from 'vue-i18n';
import Web3 from 'web3';
import { AbiItem } from 'web3-utils';
import { useNetworkInfo } from '../useNetworkInfo';
import { IIdentityRepository } from 'src/v2/repositories';
import { IAccountUnificationRepository, IIdentityRepository } from 'src/v2/repositories';
import { UnifiedAccount } from 'src/store/general/state';

const provider = get(window, 'ethereum') as any;
Expand Down Expand Up @@ -369,8 +369,14 @@ export const useAccountUnification = () => {
const getCost = async (): Promise<string> => {
const TOTAL_FIELDS = 5; // account name, avatar address key, avatar address value, token id key, token id value
const identityRepository = container.get<IIdentityRepository>(Symbols.IdentityRepository);
const depositInfo = await identityRepository.getDepositInfo();
const totalDeposit = depositInfo.basic + depositInfo.field * BigInt(TOTAL_FIELDS);
const auRepository = container.get<IAccountUnificationRepository>(
Symbols.AccountUnificationRepository
);
const [depositInfo, mappingFee] = await Promise.all([
identityRepository.getDepositInfo(),
auRepository.getUnificationFee(),
]);
const totalDeposit = depositInfo.basic + depositInfo.field * BigInt(TOTAL_FIELDS) + mappingFee;

return `${ethers.utils.formatEther(totalDeposit.toString())} ${nativeTokenSymbol.value}`;
};
Expand Down
6 changes: 6 additions & 0 deletions src/v2/repositories/IAccountUnificationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ export interface IAccountUnificationRepository {
signature: string,
identityInfo: IdentityData
): Promise<ExtrinsicPayload>;

/**
* Gets an account unification fee.
* @returns Account unification fee.
*/
getUnificationFee(): Promise<bigint>;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { u128 } from '@polkadot/types';
import { buildEvmAddress, isValidEvmAddress, toSS58Address } from '@astar-network/astar-sdk-core';
import { AccountId32, H160 } from '@polkadot/types/interfaces';
import { inject, injectable } from 'inversify';
Expand Down Expand Up @@ -79,4 +80,11 @@ export class AccountUnificationRepository implements IAccountUnificationReposito

return api.tx.utility.batchAll([identityCall, unifyCall]);
}

public async getUnificationFee(): Promise<bigint> {
const api = await this.api.getApi();
const fee = <u128>api.consts.unifiedAccounts.accountMappingStorageFee;

return fee.toBigInt();
}
}

0 comments on commit bb8c86f

Please sign in to comment.