From 08d26d5bf8b7a62b32b4bcf5b55385647523d35d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 17 May 2024 11:33:07 +0200 Subject: [PATCH 1/2] Generated diff for 2024-05-17 (#2510) Co-authored-by: GitHub Actions --- firefly.diff | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/firefly.diff b/firefly.diff index ddfdd8c360..ae40a76865 100644 --- a/firefly.diff +++ b/firefly.diff @@ -71,6 +71,7 @@ delete mode 100644 packages/desktop/components/buttons/index.js delete mode 100644 packages/desktop/components/buttons/menu-buttons/AccountActionsButton.svelte delete mode 100644 packages/desktop/components/buttons/menu-buttons/index.js + delete mode 100644 packages/desktop/components/buttons/popup-buttons/FaucetRequestButton.svelte delete mode 100644 packages/desktop/components/buttons/popup-buttons/ImportErc20TokenButton.svelte delete mode 100644 packages/desktop/components/buttons/popup-buttons/RefreshTokenMetadataButton.svelte delete mode 100644 packages/desktop/components/drawers/network-config/NetworkConfigDrawerRouter.svelte @@ -189,7 +190,6 @@ rename packages/desktop/views/dashboard/collectibles/{index.js => index.ts} (100%) rename packages/desktop/views/dashboard/collectibles/views/{index.js => index.ts} (67%) rename packages/desktop/{components/buttons/popup-buttons => views/dashboard/developer/components}/CreateAliasButton.svelte (74%) - rename packages/desktop/{components/buttons/popup-buttons => views/dashboard/developer/components}/FaucetRequestButton.svelte (69%) rename packages/desktop/{components/buttons/popup-buttons => views/dashboard/developer/components}/MintNativeTokenButton.svelte (76%) rename packages/desktop/{components/buttons/popup-buttons => views/dashboard/developer/components}/MintNftButton.svelte (72%) rename packages/desktop/{components/buttons/popup-buttons => views/dashboard/developer/components}/TestDeepLinkButton.svelte (72%) @@ -1104,6 +1104,7 @@ delete mode 100644 packages/shared/lib/core/layer-2/constants/gas-multiplier.constant.ts delete mode 100644 packages/shared/lib/core/layer-2/enums/allowance.enum.ts delete mode 100644 packages/shared/lib/core/layer-2/enums/destination-network.enum.ts + delete mode 100644 packages/shared/lib/core/layer-2/enums/index.ts delete mode 100644 packages/shared/lib/core/layer-2/helpers/encodeAddress.ts delete mode 100644 packages/shared/lib/core/layer-2/helpers/encodeAssetAllowance.ts delete mode 100644 packages/shared/lib/core/layer-2/helpers/encodeSmartContractParameters.ts @@ -1164,6 +1165,7 @@ delete mode 100644 packages/shared/lib/core/market/utils/index.ts delete mode 100644 packages/shared/lib/core/network/actions/addOfficialNodesToClientOptions.ts delete mode 100644 packages/shared/lib/core/network/actions/chain-polling.ts + delete mode 100644 packages/shared/lib/core/network/actions/getAndUpdateNodeInfo.ts delete mode 100644 packages/shared/lib/core/network/actions/network-polling.ts delete mode 100644 packages/shared/lib/core/network/actions/showNetworkIssueNotification.ts delete mode 100644 packages/shared/lib/core/network/actions/toggleDisabledNodeInClientOptions.ts @@ -1204,6 +1206,7 @@ delete mode 100644 packages/shared/lib/core/network/stores/index.ts delete mode 100644 packages/shared/lib/core/network/stores/network-status.store.ts delete mode 100644 packages/shared/lib/core/network/stores/network.store.ts + delete mode 100644 packages/shared/lib/core/network/stores/node-info.store.ts delete mode 100644 packages/shared/lib/core/network/stores/selected-chain.store.ts delete mode 100644 packages/shared/lib/core/network/tests/network.test.ts delete mode 100644 packages/shared/lib/core/network/types/chain-configuration.type.ts @@ -1281,6 +1284,7 @@ delete mode 100644 packages/shared/lib/core/profile-manager/utils/validateWalletApiEvent.ts delete mode 100644 packages/shared/lib/core/profile/actions/active-accounts/findActiveAccountWithAddress.ts delete mode 100644 packages/shared/lib/core/profile/actions/active-profile/checkActiveProfileAuth.ts + delete mode 100644 packages/shared/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts delete mode 100644 packages/shared/lib/core/profile/actions/active-profile/getCoinType.ts delete mode 100644 packages/shared/lib/core/profile/actions/active-profile/login.ts delete mode 100644 packages/shared/lib/core/profile/actions/active-profile/setActiveProfile.ts @@ -1301,6 +1305,8 @@ delete mode 100644 packages/shared/lib/core/router/enums/onboarding/storage-protection-setup-route.enum.ts delete mode 100644 packages/shared/lib/core/router/enums/onboarding/stronghold-setup-route.enum.ts delete mode 100644 packages/shared/lib/core/router/enums/settings/network-settings-route.enum.ts + delete mode 100644 packages/shared/lib/core/router/interfaces/router-event.interface.ts + delete mode 100644 packages/shared/lib/core/router/routers/app-router.ts delete mode 100644 packages/shared/lib/core/router/routers/collectibles-router.ts delete mode 100644 packages/shared/lib/core/router/routers/governance-router.ts delete mode 100644 packages/shared/lib/core/router/types/router-manager-extension-function.type.ts @@ -1491,7 +1497,7 @@ rename packages/shared/{components/atoms/iconButtons/index.js => src/components/iconButtons/index.ts} (100%) rename packages/shared/{ => src}/components/inputs/AliasInput.svelte (51%) rename packages/shared/{components/inputs/Dropdown2.svelte => src/components/inputs/Dropdown.svelte} (94%) - rename packages/shared/{ => src}/components/inputs/NodeInput.svelte (79%) + rename packages/shared/{ => src}/components/inputs/NodeInput.svelte (75%) rename packages/shared/{ => src}/components/inputs/OptionalInput.svelte (52%) rename packages/shared/{ => src}/components/inputs/SliderInput.svelte (56%) rename packages/shared/{ => src}/components/interfaces/index.ts (63%) @@ -1626,7 +1632,7 @@ rename packages/shared/{ => src}/lib/contexts/onboarding/constants/temporary-profile-manager-directory-name.constant.ts (100%) rename packages/shared/{ => src}/lib/contexts/onboarding/enums/create-profile-type.enum.ts (100%) rename packages/shared/{ => src}/lib/contexts/onboarding/enums/index.ts (79%) - rename packages/shared/{lib/core/network/enums/network-id.enum.ts => src/lib/contexts/onboarding/enums/onboarding-network-type.enum.ts} (72%) + rename packages/shared/{lib/core/network/enums/network-id.enum.ts => src/lib/contexts/onboarding/enums/onboarding-network-type.enum.ts} (57%) rename packages/shared/{ => src}/lib/contexts/onboarding/enums/onboarding-type.enum.ts (100%) rename packages/shared/{ => src}/lib/contexts/onboarding/enums/restore-profile-type.enum.ts (100%) rename packages/shared/{ => src}/lib/contexts/onboarding/enums/shimmer-claiming-account-state.enum.ts (100%) @@ -1669,7 +1675,7 @@ rename packages/shared/{ => src}/lib/contexts/onboarding/utils/sumTotalClaimedRewards.ts (75%) rename packages/shared/{ => src}/lib/contexts/onboarding/utils/sumTotalUnclaimedRewards.ts (86%) rename packages/shared/{ => src}/lib/contexts/onboarding/utils/validateBackupFile.ts (100%) - rename packages/shared/{ => src}/lib/contexts/settings/actions/deleteProfile.ts (69%) + rename packages/shared/{ => src}/lib/contexts/settings/actions/deleteProfile.ts (63%) rename packages/shared/{ => src}/lib/contexts/settings/actions/index.ts (100%) rename packages/shared/{ => src}/lib/contexts/settings/constants/index.ts (100%) rename packages/shared/{ => src}/lib/contexts/settings/index.ts (100%) @@ -1848,7 +1854,6 @@ rename packages/shared/{ => src}/lib/core/layer-2/constants/transfer-allowance.constant.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/enums/abi-type.enum.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/enums/contract-type.enum.ts (77%) - rename packages/shared/{ => src}/lib/core/layer-2/enums/index.ts (55%) rename packages/shared/{ => src}/lib/core/layer-2/enums/state-mutability-type.enum.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/errors/index.ts (100%) rename packages/shared/{ => src}/lib/core/layer-2/errors/layer1-recipient.error.ts (100%) @@ -1902,8 +1907,7 @@ rename packages/shared/{ => src}/lib/core/market/types/market-prices.type.ts (100%) rename packages/shared/{ => src}/lib/core/network/actions/addNodeToClientOptions.ts (76%) rename packages/shared/{ => src}/lib/core/network/actions/editNodeInClientOptions.ts (82%) - rename packages/shared/{ => src}/lib/core/network/actions/getAndUpdateNodeInfo.ts (85%) - rename packages/shared/{ => src}/lib/core/network/actions/index.ts (63%) + rename packages/shared/{ => src}/lib/core/network/actions/index.ts (56%) rename packages/shared/{ => src}/lib/core/network/actions/removeNodeFromClientOptions.ts (63%) rename packages/shared/{ => src}/lib/core/network/actions/toggleLocalPowInClientOptions.ts (84%) rename packages/shared/{ => src}/lib/core/network/actions/togglePrimaryNodeInClientOptions.ts (63%) @@ -1926,7 +1930,6 @@ rename packages/shared/{lib/core/network/interfaces/chain-metadata.interface.ts => src/lib/core/network/interfaces/isc-chain-metadata.interface.ts} (76%) rename packages/shared/{ => src}/lib/core/network/interfaces/node-info-response.interface.ts (62%) rename packages/shared/{ => src}/lib/core/network/interfaces/protocol.interface.ts (62%) - rename packages/shared/{ => src}/lib/core/network/stores/node-info.store.ts (83%) rename packages/shared/{ => src}/lib/core/network/types/network-metadata.type.ts (100%) rename packages/shared/{ => src}/lib/core/network/types/web3-provider.type.ts (100%) rename packages/shared/{ => src}/lib/core/network/utils/checkNodeUrlValidity.ts (95%) @@ -2003,14 +2006,13 @@ rename packages/shared/{ => src}/lib/core/profile/actions/active-accounts/index.ts (100%) rename packages/shared/{ => src}/lib/core/profile/actions/active-accounts/updateActiveAccountPersistedData.ts (63%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/checkAndRemoveProfilePicture.ts (100%) - rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/checkAndUpdateActiveProfileNetwork.ts (54%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/getBaseToken.ts (81%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/getNetworkHrp.ts (100%) - rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/index.ts (92%) + rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/index.ts (84%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/loadAccounts.ts (68%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/loadPersistedProfileIntoActiveProfile.ts (74%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/lockStronghold.ts (88%) - rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/logout.ts (66%) + rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/logout.ts (67%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/migrateStrongholdFromActiveProfile.ts (100%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/reflectLockedStronghold.ts (92%) rename packages/shared/{ => src}/lib/core/profile/actions/active-profile/resetActiveProfile.ts (59%) @@ -2056,7 +2058,7 @@ rename packages/shared/{ => src}/lib/core/profile/utils/validateProfileName.ts (100%) rename packages/shared/{ => src}/lib/core/router/actions/index.ts (100%) rename packages/shared/{ => src}/lib/core/router/classes/index.ts (100%) - rename packages/shared/{ => src}/lib/core/router/classes/router.class.ts (80%) + rename packages/shared/{ => src}/lib/core/router/classes/router.class.ts (75%) rename packages/shared/{ => src}/lib/core/router/classes/subrouter.class.ts (63%) rename packages/{mobile/lib/routers => shared/src/lib/core/router}/enums/app-route.enum.ts (100%) rename packages/shared/{ => src}/lib/core/router/enums/collectibles-route.enum.ts (100%) @@ -2082,19 +2084,17 @@ rename packages/shared/{ => src}/lib/core/router/enums/settings/security-settings-route.enum.ts (64%) rename packages/shared/{ => src}/lib/core/router/enums/settings/settings-route.enum.ts (72%) rename packages/shared/{ => src}/lib/core/router/index.ts (100%) - rename packages/shared/{ => src}/lib/core/router/interfaces/index.ts (100%) - rename packages/shared/{ => src}/lib/core/router/interfaces/router-event.interface.ts (67%) + rename packages/shared/{ => src}/lib/core/router/interfaces/index.ts (75%) rename packages/shared/{ => src}/lib/core/router/interfaces/router-manager-options.interface.ts (100%) rename packages/shared/{ => src}/lib/core/router/interfaces/router-manager.interface.ts (78%) - rename packages/shared/{ => src}/lib/core/router/interfaces/router.interface.ts (100%) - rename packages/shared/{ => src}/lib/core/router/routers/app-router.ts (63%) + rename packages/shared/{ => src}/lib/core/router/interfaces/router.interface.ts (50%) rename packages/shared/{ => src}/lib/core/router/routers/dashboard-router.ts (62%) rename packages/shared/{ => src}/lib/core/router/routers/index.ts (100%) rename packages/shared/{ => src}/lib/core/router/routers/settings-router.ts (56%) rename packages/shared/{ => src}/lib/core/router/stores/index.ts (100%) rename packages/shared/{ => src}/lib/core/router/stores/router-manager.store.ts (53%) rename packages/shared/{ => src}/lib/core/router/subrouters/index.ts (100%) - rename packages/shared/{ => src}/lib/core/router/subrouters/login-router.ts (70%) + rename packages/shared/{ => src}/lib/core/router/subrouters/login-router.ts (64%) rename packages/shared/{ => src}/lib/core/router/types/index.ts (100%) rename packages/shared/{ => src}/lib/core/router/types/router-manager-extension.type.ts (100%) rename packages/shared/{ => src}/lib/core/stronghold/actions/index.ts (100%) @@ -2183,7 +2183,7 @@ rename packages/shared/{ => src}/lib/core/utils/stores/currencies.store.ts (100%) rename packages/shared/{ => src}/lib/core/utils/stores/exchange-rates.store.ts (100%) rename packages/shared/{ => src}/lib/core/utils/stores/index.ts (100%) - rename packages/shared/{ => src}/lib/core/utils/string.ts (60%) + rename packages/shared/{ => src}/lib/core/utils/string.ts (59%) rename packages/shared/{ => src}/lib/core/utils/tests/convert.test.ts (60%) rename packages/shared/{ => src}/lib/core/utils/tests/crypto.test.ts (100%) rename packages/shared/{ => src}/lib/core/utils/tests/date.test.ts (100%) @@ -2263,7 +2263,7 @@ rename packages/shared/{ => src}/locales/lv.json (52%) rename packages/shared/{ => src}/locales/mk.json (52%) rename packages/shared/{ => src}/locales/no.json (52%) - rename packages/shared/{ => src}/locales/pl.json (52%) + rename packages/shared/{ => src}/locales/pl.json (51%) rename packages/shared/{ => src}/locales/pt-PT.json (52%) rename packages/shared/{ => src}/locales/ro.json (52%) rename packages/shared/{ => src}/locales/sk.json (51%) @@ -2273,7 +2273,7 @@ rename packages/shared/{ => src}/locales/uk.json (50%) rename packages/shared/{ => src}/locales/ur.json (52%) rename packages/shared/{ => src}/locales/vi.json (51%) - rename packages/shared/{ => src}/locales/zh-CN.json (51%) + rename packages/shared/{ => src}/locales/zh-CN.json (50%) rename packages/shared/{ => src}/locales/zh-TW.json (52%) delete mode 100644 packages/shared/style/style.scss rename packages/shared/{lib/tests/__mocks__ => test/mocks}/account.mock.ts (53%) From 16cc81931cfd1fd96c3df5b034043baf30603a89 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 17 May 2024 11:02:19 +0100 Subject: [PATCH 2/2] feat: add gas selector to transaction flow (#2491) * feat: get gas prices from blockscout Co-authored-by: Tuditi * fix: convert gas prices to wei * temp: allow user to set gas speed on transaction summary * feat: allow user to set gas speed on transaction summary * fix: don't allow gas prices less than average * feta: improve gas price fetching * chore: rename * chore: set gas fee in TxSummaryView * chore: remove redundant prop * feat: select gas speed during dapp initiated transaction * chore: fix required gas price & cleanup * chore: improve type safety * chore: set max instead of estimated gas * chore: merge required and slow * fix: convert bigInt to hex * feat: disable gas selection if isTransferring * fix: precision issue --------- Co-authored-by: Tuditi Co-authored-by: Tuditi Co-authored-by: Tuditi <45079109+Tuditi@users.noreply.github.com> --- .../popups/EvmTransactionFromDappPopup.svelte | 73 +++++++++++++------ .../views/TransactionSummaryView.svelte | 46 +++++++++--- .../components/EvmTransactionDetails.svelte | 49 ++++++++++--- .../components/EvmTransactionSummary.svelte | 22 +++--- .../components/SetTransactionFeeMenu.svelte | 72 ++++++++++++++++++ .../views/components/{index.js => index.ts} | 0 .../blockscout/api/blockscout.api.ts | 8 ++ .../interfaces/blockscout-stats.interface.ts | 18 +++++ .../auxiliary/blockscout/interfaces/index.ts | 1 + .../actions/canAccountMakeEvmTransaction.ts | 2 +- .../src/lib/core/layer-2/actions/setGasFee.ts | 8 +- .../core/layer-2/constants/wei.constants.ts | 0 .../lib/core/layer-2/enums/gas-speed.enum.ts | 6 ++ .../src/lib/core/layer-2/enums/index.ts | 1 + .../gas-prices-by-speed.interface.ts | 8 ++ .../src/lib/core/layer-2/interfaces/index.ts | 1 + .../layer-2/utils/buildEvmTransactionData.ts | 2 +- .../core/layer-2/utils/convertGweiToWei.ts | 5 ++ .../src/lib/core/layer-2/utils/index.ts | 1 + .../core/network/classes/evm-network.class.ts | 30 +++++++- .../interfaces/evm-network.interface.ts | 4 +- .../lib/core/network/utils/isEvmNetwork.ts | 5 +- .../utils/send/validateSendConfirmation.ts | 8 +- packages/shared/src/locales/en.json | 5 +- 24 files changed, 311 insertions(+), 64 deletions(-) create mode 100644 packages/desktop/views/dashboard/send-flow/views/components/SetTransactionFeeMenu.svelte rename packages/desktop/views/dashboard/send-flow/views/components/{index.js => index.ts} (100%) create mode 100644 packages/shared/src/lib/auxiliary/blockscout/interfaces/blockscout-stats.interface.ts delete mode 100644 packages/shared/src/lib/core/layer-2/constants/wei.constants.ts create mode 100644 packages/shared/src/lib/core/layer-2/enums/gas-speed.enum.ts create mode 100644 packages/shared/src/lib/core/layer-2/interfaces/gas-prices-by-speed.interface.ts create mode 100644 packages/shared/src/lib/core/layer-2/utils/convertGweiToWei.ts diff --git a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte index d2e7d08e26..67ecf7bc85 100644 --- a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte @@ -1,38 +1,39 @@ {/if} diff --git a/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte b/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte index c018d99f80..fb721fce51 100644 --- a/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte @@ -10,7 +10,7 @@ import { IEvmNetwork, getNetwork, isEvmNetwork } from '@core/network' import { checkActiveProfileAuth } from '@core/profile/actions' import { getActiveProfileId, getIsActiveLedgerProfile } from '@core/profile/stores' - import { truncateString } from '@core/utils' + import { Converter, MILLISECONDS_PER_SECOND, truncateString } from '@core/utils' import { SendFlowParameters, SubjectType } from '@core/wallet' import { createEvmTransactionFromSendFlowParameters, @@ -22,14 +22,20 @@ import { sendFlowParameters } from '@core/wallet/stores' import { validateSendConfirmation } from '@core/wallet/utils' import { closePopup, modifyPopupState } from '@desktop/auxiliary/popup' - import { onMount } from 'svelte' + import { onDestroy, onMount } from 'svelte' import { sendFlowRouter } from '../send-flow.router' import { EvmTransactionSummary, StardustToEvmTransactionSummary, StardustTransactionSummary } from './components' import { TransactionSummaryProps } from './types' + import { GasSpeed, IGasPricesBySpeed } from '@core/layer-2' - export let transactionSummaryProps: TransactionSummaryProps + export let transactionSummaryProps: TransactionSummaryProps | undefined let { _onMount, preparedOutput, preparedTransaction } = transactionSummaryProps ?? {} + let selectedGasSpeed = GasSpeed.Required + let gasPrices: IGasPricesBySpeed = { + [GasSpeed.Required]: Converter.bigIntLikeToBigInt(preparedTransaction?.gasPrice as number), + } + $: void prepareTransactions($sendFlowParameters) $: isSourceNetworkLayer2 = !!evmNetwork $: isDestinationNetworkLayer2 = isEvmNetwork($sendFlowParameters?.destinationNetworkId) @@ -41,8 +47,8 @@ let recipientAddress: string let evmNetwork: IEvmNetwork | undefined - async function prepareTransactions(sendFlowParameters: SendFlowParameters): Promise { - if (_onMount) { + async function prepareTransactions(sendFlowParameters: SendFlowParameters | undefined): Promise { + if (_onMount || !sendFlowParameters || !$selectedAccount) { // The unlock stronghold/ledger flow passes the _onMount prop and the preparedTransactions return } @@ -51,7 +57,7 @@ const { recipient } = sendFlowParameters recipientAddress = - recipient.type === SubjectType.Account + recipient?.type === SubjectType.Account ? recipient.account.name : truncateString(recipient?.address, 6, 6) @@ -90,8 +96,15 @@ } } + async function setGasPrices(): Promise { + const _gasPrices = await evmNetwork?.getGasPrices() + if (_gasPrices) { + gasPrices = { ...gasPrices, ..._gasPrices } + } + } + async function onConfirmClick(): Promise { - if (!isValidTransaction()) { + if (!isValidTransaction() || !$selectedAccount) { return } @@ -104,7 +117,10 @@ try { busy = true modifyPopupState({ preventClose: true }) - if (isSourceNetworkLayer2) { + if (preparedTransaction && evmNetwork) { + preparedTransaction.gasPrice = Converter.bigIntToHex( + gasPrices?.[selectedGasSpeed] ?? gasPrices.required + ) const signedTransaction = await signEvmTransaction(preparedTransaction, evmNetwork, $selectedAccount) const profileId = getActiveProfileId() const account = getSelectedAccount() @@ -116,7 +132,7 @@ profileId, account ) - } else { + } else if (preparedOutput) { await signAndSendStardustTransaction(preparedOutput, $selectedAccount) } modifyPopupState({ preventClose: false }, true) @@ -144,8 +160,13 @@ } } + let intervalId: NodeJS.Timeout onMount(async () => { try { + if (isSourceNetworkLayer2 || isDestinationNetworkLayer2) { + await setGasPrices() + intervalId = setInterval(() => void setGasPrices, MILLISECONDS_PER_SECOND * 10) + } if (_onMount) { await _onMount() } else { @@ -157,6 +178,10 @@ hasMounted = true } }) + + onDestroy(() => { + clearInterval(intervalId) + }) {#if isSourceNetworkLayer2 && preparedTransaction && $sendFlowParameters && evmNetwork} {:else if !isSourceNetworkLayer2 && preparedOutput && $sendFlowParameters} {#if isDestinationNetworkLayer2} diff --git a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionDetails.svelte b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionDetails.svelte index 20afafeef8..7bd5113d8a 100644 --- a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionDetails.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionDetails.svelte @@ -1,14 +1,27 @@ +> + {#if gasLimit} + +
+ +
+
+ {/if} +
diff --git a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte index a9ab904ba8..35dceb3371 100644 --- a/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/components/EvmTransactionSummary.svelte @@ -1,21 +1,18 @@ + + + + diff --git a/packages/desktop/views/dashboard/send-flow/views/components/index.js b/packages/desktop/views/dashboard/send-flow/views/components/index.ts similarity index 100% rename from packages/desktop/views/dashboard/send-flow/views/components/index.js rename to packages/desktop/views/dashboard/send-flow/views/components/index.ts diff --git a/packages/shared/src/lib/auxiliary/blockscout/api/blockscout.api.ts b/packages/shared/src/lib/auxiliary/blockscout/api/blockscout.api.ts index 08ca5cfb72..56f684874b 100644 --- a/packages/shared/src/lib/auxiliary/blockscout/api/blockscout.api.ts +++ b/packages/shared/src/lib/auxiliary/blockscout/api/blockscout.api.ts @@ -7,6 +7,7 @@ import { IBlockscoutApi, IBlockscoutAsset, IBlockscoutAssetDto, + IBlockscoutStats, IBlockscoutTokenInfo, IBlockscoutTokenInfoDto, IBlockscoutTransaction, @@ -61,6 +62,13 @@ export class BlockscoutApi extends BaseApi implements IBlockscoutApi { ) } + async getStats(): Promise { + const response = await this.get('stats') + if (response) { + return this.get('stats') + } + } + async getAssetMetadata(assetAddress: string): Promise { const response = await this.get(`tokens/${assetAddress}`) if (response) { diff --git a/packages/shared/src/lib/auxiliary/blockscout/interfaces/blockscout-stats.interface.ts b/packages/shared/src/lib/auxiliary/blockscout/interfaces/blockscout-stats.interface.ts new file mode 100644 index 0000000000..0b41055089 --- /dev/null +++ b/packages/shared/src/lib/auxiliary/blockscout/interfaces/blockscout-stats.interface.ts @@ -0,0 +1,18 @@ +export interface IBlockscoutStats { + total_blocks: string + total_addresses: string + total_transactions: string + average_block_time: number + coin_price: string + total_gas_used: string + transactions_today: string + gas_used_today: string + gas_prices: { + slow: number + average: number + fast: number + } + static_gas_price: string + market_cap: string + network_utilization_percentage: number +} diff --git a/packages/shared/src/lib/auxiliary/blockscout/interfaces/index.ts b/packages/shared/src/lib/auxiliary/blockscout/interfaces/index.ts index e6cefdfe6f..24a572aecd 100644 --- a/packages/shared/src/lib/auxiliary/blockscout/interfaces/index.ts +++ b/packages/shared/src/lib/auxiliary/blockscout/interfaces/index.ts @@ -1,3 +1,4 @@ +export * from './blockscout-stats.interface' export * from './blockscout-address-param.interface' export * from './blockscout-api.interface' export * from './blockscout-asset.interface' diff --git a/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts b/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts index 78cad3375e..f8272f6aeb 100644 --- a/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts +++ b/packages/shared/src/lib/core/layer-2/actions/canAccountMakeEvmTransaction.ts @@ -12,7 +12,7 @@ export async function canAccountMakeEvmTransaction( const gasLimit = Math.floor( FALLBACK_ESTIMATED_GAS[sendFlowType ?? SendFlowType.BaseCoinTransfer] * GAS_LIMIT_MULTIPLIER ) - const gasPrice = await network.getGasPrice() + const gasPrice = await network.getRequiredGasPrice() if (gasPrice === undefined) { return false } diff --git a/packages/shared/src/lib/core/layer-2/actions/setGasFee.ts b/packages/shared/src/lib/core/layer-2/actions/setGasFee.ts index 13978af091..a9f9db3da8 100644 --- a/packages/shared/src/lib/core/layer-2/actions/setGasFee.ts +++ b/packages/shared/src/lib/core/layer-2/actions/setGasFee.ts @@ -5,7 +5,13 @@ import { calculateMaxGasFeeFromTransactionData } from '@core/layer-2/utils' import { getEvmNetwork, isEvmNetwork } from '@core/network' import { SendFlowParameters, createEvmTransactionFromSendFlowParameters, updateSendFlowParameters } from '@core/wallet' -export async function setGasFee(sendFlowParams: SendFlowParameters, account: IAccountState): Promise { +export async function setGasFee( + sendFlowParams: SendFlowParameters | undefined, + account: IAccountState | undefined +): Promise { + if (!sendFlowParams || !account) { + throw new Error('Send flow parameter or account is undefined!') + } try { if (sendFlowParams.gasFee) { return diff --git a/packages/shared/src/lib/core/layer-2/constants/wei.constants.ts b/packages/shared/src/lib/core/layer-2/constants/wei.constants.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/shared/src/lib/core/layer-2/enums/gas-speed.enum.ts b/packages/shared/src/lib/core/layer-2/enums/gas-speed.enum.ts new file mode 100644 index 0000000000..b0a85813d4 --- /dev/null +++ b/packages/shared/src/lib/core/layer-2/enums/gas-speed.enum.ts @@ -0,0 +1,6 @@ +export enum GasSpeed { + Fast = 'fast', + Average = 'average', + Slow = 'slow', + Required = 'required', +} diff --git a/packages/shared/src/lib/core/layer-2/enums/index.ts b/packages/shared/src/lib/core/layer-2/enums/index.ts index 3a133f5864..2d35c2a71a 100644 --- a/packages/shared/src/lib/core/layer-2/enums/index.ts +++ b/packages/shared/src/lib/core/layer-2/enums/index.ts @@ -4,5 +4,6 @@ export * from './asset-type.enum' export * from './contract-type.enum' export * from './erc721-interface-id.enum' export * from './evm-error-message.enum' +export * from './gas-speed.enum' export * from './parsed-smart-contract-type.enum' export * from './state-mutability-type.enum' diff --git a/packages/shared/src/lib/core/layer-2/interfaces/gas-prices-by-speed.interface.ts b/packages/shared/src/lib/core/layer-2/interfaces/gas-prices-by-speed.interface.ts new file mode 100644 index 0000000000..35c505a525 --- /dev/null +++ b/packages/shared/src/lib/core/layer-2/interfaces/gas-prices-by-speed.interface.ts @@ -0,0 +1,8 @@ +import { GasSpeed } from '../enums' + +export interface IGasPricesBySpeed { + [GasSpeed.Fast]?: bigint + [GasSpeed.Average]?: bigint + [GasSpeed.Slow]?: bigint + [GasSpeed.Required]: bigint +} diff --git a/packages/shared/src/lib/core/layer-2/interfaces/index.ts b/packages/shared/src/lib/core/layer-2/interfaces/index.ts index 3331d84235..4fe67ed87a 100644 --- a/packages/shared/src/lib/core/layer-2/interfaces/index.ts +++ b/packages/shared/src/lib/core/layer-2/interfaces/index.ts @@ -4,6 +4,7 @@ export * from './erc721-safe-transfer-method-inputs.interface' export * from './evm-address.interface' export * from './evm-signature.interface' export * from './evm-transaction-data.interface' +export * from './gas-prices-by-speed.interface' export * from './isc-call-method-inputs.interface' export * from './isc-send-method-inputs.interface' export * from './layer-2-asset-allowance.interface' diff --git a/packages/shared/src/lib/core/layer-2/utils/buildEvmTransactionData.ts b/packages/shared/src/lib/core/layer-2/utils/buildEvmTransactionData.ts index 2d0e34942a..6195e7c999 100644 --- a/packages/shared/src/lib/core/layer-2/utils/buildEvmTransactionData.ts +++ b/packages/shared/src/lib/core/layer-2/utils/buildEvmTransactionData.ts @@ -11,7 +11,7 @@ export async function buildEvmTransactionData( data: string | undefined ): Promise { const nonce = await evmNetwork.provider.eth.getTransactionCount(originAddress) - const gasPrice = await evmNetwork.provider.eth.getGasPrice() + const gasPrice = await evmNetwork.getRequiredGasPrice() const hexGasPrice = Converter.decimalToHex(Number(gasPrice), true) const estimatedGas = await evmNetwork.provider.eth.estimateGas({ from: originAddress, diff --git a/packages/shared/src/lib/core/layer-2/utils/convertGweiToWei.ts b/packages/shared/src/lib/core/layer-2/utils/convertGweiToWei.ts new file mode 100644 index 0000000000..5c441c858d --- /dev/null +++ b/packages/shared/src/lib/core/layer-2/utils/convertGweiToWei.ts @@ -0,0 +1,5 @@ +const WEI_PER_GWEI = 1000000000 + +export function convertGweiToWei(gwei: number): bigint { + return BigInt(Math.round(gwei * WEI_PER_GWEI)) +} diff --git a/packages/shared/src/lib/core/layer-2/utils/index.ts b/packages/shared/src/lib/core/layer-2/utils/index.ts index 57d6d77d33..3139e558cd 100644 --- a/packages/shared/src/lib/core/layer-2/utils/index.ts +++ b/packages/shared/src/lib/core/layer-2/utils/index.ts @@ -4,6 +4,7 @@ export * from './buildEvmTransactionDataForNft' export * from './buildEvmTransactionDataForToken' export * from './calculateEstimatedGasFeeFromTransactionData' export * from './calculateMaxGasFeeFromTransactionData' +export * from './convertGweiToWei' export * from './fetchIscAssetsForAccount' export * from './fetchEvmBalancesForAllAccounts' export * from './getEvmTokenMetadata' diff --git a/packages/shared/src/lib/core/network/classes/evm-network.class.ts b/packages/shared/src/lib/core/network/classes/evm-network.class.ts index 7ffba4f6d0..5cd7042c7b 100644 --- a/packages/shared/src/lib/core/network/classes/evm-network.class.ts +++ b/packages/shared/src/lib/core/network/classes/evm-network.class.ts @@ -18,6 +18,9 @@ import Web3 from 'web3' import { ChainId, NetworkHealth, NetworkNamespace, NetworkType } from '../enums' import { IBaseEvmNetworkConfiguration, IBlock, IEvmNetwork } from '../interfaces' import { EvmNetworkId, EvmNetworkType, Web3Provider } from '../types' +import { BlockscoutApi } from '@auxiliary/blockscout/api' +import { convertGweiToWei } from '@core/layer-2/utils' +import { IGasPricesBySpeed } from '@core/layer-2' export class EvmNetwork implements IEvmNetwork { public readonly provider: Web3Provider @@ -35,6 +38,8 @@ export class EvmNetwork implements IEvmNetwork { public health: Writable = writable(NetworkHealth.Operational) public statusPoll: number | undefined + private gasPrices: IGasPricesBySpeed | undefined + constructor({ id, namespace, @@ -99,7 +104,7 @@ export class EvmNetwork implements IEvmNetwork { return new this.provider.eth.Contract(abi, address) } - async getGasPrice(): Promise { + async getRequiredGasPrice(): Promise { try { const gasPrice = await this.provider.eth.getGasPrice() return BigInt(gasPrice) @@ -108,6 +113,29 @@ export class EvmNetwork implements IEvmNetwork { } } + async getGasPrices(): Promise { + try { + const required = (await this.getRequiredGasPrice()) ?? BigInt(0) + let gasPrices: IGasPricesBySpeed = { required } + try { + const blockscoutApi = new BlockscoutApi(this.id) + const stats = await blockscoutApi.getStats() + + Object.entries(stats?.gas_prices ?? {}).forEach(([key, value]) => { + const gasInWei = convertGweiToWei(value) + gasPrices[key] = gasInWei > required ? gasInWei : required + }) + } catch (err) { + console.error(err) + gasPrices = { ...this.gasPrices, required } + } + this.gasPrices = gasPrices + return gasPrices + } catch (err) { + console.error('Failed to fetch required gas prices!', err) + } + } + async getLatestBlock(): Promise { const number = await this.provider.eth.getBlockNumber() return this.provider.eth.getBlock(number) diff --git a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts index 755944d7eb..6cfa56ccea 100644 --- a/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/evm-network.interface.ts @@ -9,6 +9,7 @@ import { IBaseNetwork, IBaseNetworkMetadata } from './base-network.interface' import { IBlock } from './block.interface' import { IIscChainMetadata } from './isc-chain-metadata.interface' import { BigIntLike } from '@ethereumjs/util' +import { IGasPricesBySpeed } from '@core/layer-2' export interface IIscChain extends IEvmNetwork { type: NetworkType.Isc @@ -32,7 +33,8 @@ export interface IEvmNetwork extends IBaseNetwork, IBaseNetworkMetadata { provider: Web3Provider - getGasPrice(): Promise + getRequiredGasPrice(): Promise + getGasPrices(): Promise getBalance(account: IAccountState): Promise getNftsForAccount(account: IAccountState): Promise diff --git a/packages/shared/src/lib/core/network/utils/isEvmNetwork.ts b/packages/shared/src/lib/core/network/utils/isEvmNetwork.ts index c002261e2b..1c3b1c34ae 100644 --- a/packages/shared/src/lib/core/network/utils/isEvmNetwork.ts +++ b/packages/shared/src/lib/core/network/utils/isEvmNetwork.ts @@ -2,6 +2,9 @@ import { NetworkNamespace } from '../enums' import { EvmNetworkId, NetworkId } from '../types' import { getSplitNetworkId } from './getSplitNetworkId' -export function isEvmNetwork(networkId: NetworkId): networkId is EvmNetworkId { +export function isEvmNetwork(networkId: NetworkId | undefined): networkId is EvmNetworkId { + if (!networkId) { + return false + } return getSplitNetworkId(networkId)?.namespace === NetworkNamespace.Evm } diff --git a/packages/shared/src/lib/core/wallet/utils/send/validateSendConfirmation.ts b/packages/shared/src/lib/core/wallet/utils/send/validateSendConfirmation.ts index 425bd29a7a..4020a516f2 100644 --- a/packages/shared/src/lib/core/wallet/utils/send/validateSendConfirmation.ts +++ b/packages/shared/src/lib/core/wallet/utils/send/validateSendConfirmation.ts @@ -8,9 +8,13 @@ import { } from '@contexts/wallet' import { convertUnixTimestampToDate, isFutureDateTime } from '@core/utils' -export function validateSendConfirmation(output: Output): void { +export function validateSendConfirmation(output: Output | undefined): void { + if (!output) { + throw new Error('Output is undefined!') + } + const parseNumber: (value: string) => number = (value: string) => parseInt(value, 10) ?? 0 - const amount = parseNumber(output?.amount) + const amount = parseNumber(output.amount) const balance = parseNumber(getSelectedAccount()?.balances?.baseCoin.available.toString() ?? '0') const expirationDateTime = getDateFromUnlockCondition(output, UnlockConditionType.Expiration) diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json index efecc6e730..3fefe4d93b 100644 --- a/packages/shared/src/locales/en.json +++ b/packages/shared/src/locales/en.json @@ -1725,7 +1725,10 @@ "appName": "App name", "question": "Question", "id": "ID", - "location": "Location" + "location": "Location", + "slow": "Slow", + "average": "Average", + "fast": "Fast" }, "filters":{ "title": "Filters",