Skip to content

Commit

Permalink
Merge pull request #505 from fairDataSociety/feat/new-gas-estimation
Browse files Browse the repository at this point in the history
Feat/new gas estimation
  • Loading branch information
tomicvladan authored Sep 20, 2023
2 parents eff1cb4 + 9e73b0a commit 42a73c5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
60 changes: 45 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.3.0",
"@fairdatasociety/blossom": "^0.5.0",
"@fairdatasociety/fdp-storage": "^0.11.0",
"@fairdatasociety/fdp-storage": "^0.12.0",
"@headlessui/react": "^1.7.14",
"@metamask/sdk": "^0.5.6",
"@types/react-blockies": "^1.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,7 @@ export default function MetamaskCreateAccount({
};

const getFeePrice = async () => {
const { address } = fdpClientRef.current.account.wallet;
const { publicKey } = fdpClientRef.current.account;

const price = await estimateRegistrationPrice(
username,
address,
publicKey,
network
);
const price = await estimateRegistrationPrice(network);

setMinBalance(price);
};
Expand Down Expand Up @@ -190,7 +182,7 @@ export default function MetamaskCreateAccount({
<>
<div>
{intl.get('YOUR_ACCOUNT_IS')} <br />
<span>
<span className="flex items-center flex-wrap">
{address}
<CopyButton text={address} />
</span>
Expand Down
19 changes: 2 additions & 17 deletions src/utils/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@ import { BigNumber, providers } from 'ethers';
const FDS_DOMAIN = 'fds';

export async function estimateRegistrationPrice(
username: string,
address: string,
publicKey: string,
network: Network
): Promise<BigNumber> {
const provider = new providers.JsonRpcProvider(network.config.rpcUrl);
const ens = new ENS(
// A workaround for gas estimation on sepolia
network.id === Environments.SEPOLIA
? { ...network.config, rpcUrl: 'http://rpc.sepolia.org' }
: network.config,
provider,
FDS_DOMAIN
);
const [gasAmount, gasPrice] = await Promise.all([
ens.registerUsernameEstimateGas(username, address, publicKey),
provider.getFeeData(),
]);

return gasPrice.maxFeePerGas.mul(gasAmount);
const ens = new ENS(network.config, provider, FDS_DOMAIN);
return ens.registerUsernameApproximatePrice();
}

export function getAccountBalance(
Expand Down

0 comments on commit 42a73c5

Please sign in to comment.