diff --git a/.github/workflows/deploy_develop.yml b/.github/workflows/deploy_develop.yml index df59e9265..fd2bb0751 100644 --- a/.github/workflows/deploy_develop.yml +++ b/.github/workflows/deploy_develop.yml @@ -47,8 +47,6 @@ jobs: ARAGON_PORTIS_DAPP_ID: ${{ secrets.PORTIS_DAPP_ID }} # TODO remove --network-concurrency 1 once use-wallet 0.9.0 is published run: yarn install --frozen-lockfile --network-concurrency 1 && yarn build - - name: Replace fleek storage api url - run: for f in $(find ./public/ -type f); do sed -i 's/storageapi.fleek.co/storageapi2.fleek.co/g' $f; done - name: Deploy fleek id: deploy uses: fleekhq/action-deploy@v1 diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml index ade5d0c39..be511ea58 100644 --- a/.github/workflows/deploy_prod.yml +++ b/.github/workflows/deploy_prod.yml @@ -47,8 +47,6 @@ jobs: ARAGON_PORTIS_DAPP_ID: ${{ secrets.PORTIS_DAPP_ID }} # TODO remove --network-concurrency 1 once use-wallet 0.9.0 is published run: yarn install --frozen-lockfile --network-concurrency 1 && yarn build - - name: Replace fleek storage api url - run: for f in $(find ./public/ -type f); do sed -i 's/storageapi.fleek.co/storageapi2.fleek.co/g' $f; done - name: Deploy fleek id: deploy uses: fleekhq/action-deploy@v1 diff --git a/src/components/SignerPanel/SignerPanel.js b/src/components/SignerPanel/SignerPanel.js index 9cf619502..d6a71f62f 100644 --- a/src/components/SignerPanel/SignerPanel.js +++ b/src/components/SignerPanel/SignerPanel.js @@ -6,7 +6,7 @@ import { Transition, animated } from 'react-spring' import { useWallet } from '../../contexts/wallet' import { ActivityContext } from '../../contexts/ActivityContext' import { AppType, EthereumAddressType } from '../../prop-types' -import { addressesEqual } from '../../util/web3' +import { addressesEqual, getPriorityFeeEstimation } from '../../util/web3' import ConfirmTransaction from './ConfirmTransaction' import ConfirmMsgSign from './ConfirmMsgSign' import SigningStatus from './SigningStatus' @@ -44,6 +44,9 @@ const WEB3_TX_OBJECT_KEYS = new Set([ 'gasPrice', 'data', 'nonce', + 'maxPriorityFeePerGas', + 'gasPrice', + 'maxFeePerGas', ]) const getAppName = (apps, proxyAddress) => { @@ -237,9 +240,13 @@ class SignerPanel extends React.PureComponent { try { if (pretransaction) { + pretransaction = await this.applyGasAndPriorityEstimation( + pretransaction + ) await this.signTransaction(pretransaction, intent, true) } + transaction = await this.applyGasAndPriorityEstimation(transaction) const transactionHash = await this.signTransaction( transaction, intent, @@ -308,6 +315,16 @@ class SignerPanel extends React.PureComponent { } } + // adds maxPriorityFeePerGas, gasPrice and maxFeePerGas to the transaction if the RPC supports these + applyGasAndPriorityEstimation = async transaction => { + const { walletWeb3 } = this.props + const estimatedPriorityFee = await getPriorityFeeEstimation(walletWeb3) + return { + ...transaction, + maxPriorityFeePerGas: estimatedPriorityFee, + } + } + render() { const { account, apps, walletProviderId, walletWeb3 } = this.props diff --git a/src/onboarding/Create/Create.js b/src/onboarding/Create/Create.js index 247acfb69..fe5d4c14c 100644 --- a/src/onboarding/Create/Create.js +++ b/src/onboarding/Create/Create.js @@ -31,6 +31,7 @@ import { getIpfsGateway } from '../../local-settings' import { web3Provider } from '../../Web3Provider' import { trackEvent, events } from '../../analytics' import { completeDomain } from '../../check-domain' +import { getPriorityFeeEstimation } from '../../util/web3' const MAX_RETRY = 5 @@ -269,6 +270,7 @@ function useTemplateRepoInformation(templateRepoAddress, setError) { function useDeploymentState( account, applyEstimateGas, + applyEstimatePriorityFee, attempts, status, template, @@ -341,6 +343,7 @@ function useDeploymentState( } try { transaction = await applyEstimateGas(transaction) + transaction = await applyEstimatePriorityFee(transaction) } catch (_) {} if (!cancelled) { @@ -509,6 +512,17 @@ const Create = React.memo(function Create({ [web3] ) + const applyEstimatePriorityFee = useCallback( + async transaction => { + const estimatedPriorityFee = await getPriorityFeeEstimation(web3) + return { + ...transaction, + maxPriorityFeePerGas: estimatedPriorityFee, + } + }, + [web3] + ) + const [attempts, setAttempts] = useState(0) const { @@ -519,6 +533,7 @@ const Create = React.memo(function Create({ } = useDeploymentState( account, applyEstimateGas, + applyEstimatePriorityFee, attempts, status, template, diff --git a/src/util/web3.js b/src/util/web3.js index a434a67ed..1da44bc94 100644 --- a/src/util/web3.js +++ b/src/util/web3.js @@ -256,6 +256,29 @@ export function transformAddresses(str, callback) { ) } +/** + * Calculates the current priority fee estimation + * + * @export + * @param {*} web3 The connected web3 instance + * @return {number | undefined} Returns the estimated priority fee or undefined + */ +export async function getPriorityFeeEstimation(web3) { + const priorityFeeHistory = await web3.eth.getFeeHistory('4', 'latest', [10]) + if (priorityFeeHistory?.reward?.length > 0) { + // takes the top 10 of the last 4 blocks and take the average after removing zero values + const feeHistories = priorityFeeHistory.reward + .map(fee => web3.utils.hexToNumber(fee[0])) + .filter(fee => fee > 0) + if (feeHistories.length > 0) { + return Math.round( + feeHistories.reduce((acc, fee) => acc + fee, 0) / feeHistories.length + ) + } + } + return undefined +} + // Re-export some utilities from web3-utils export { fromWei,