Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wallet calculate gas performance #1794

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lemon-maps-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": patch
"fuels-wallet": patch
---

Sped up gas calculation in SendMachine and TxRequestMachine by merging calculations of default tip and gas limit into a single parallelized promise.
6 changes: 6 additions & 0 deletions .changeset/lovely-kings-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": patch
"fuels-wallet": patch
---

Decrease unnecessarily long delay in tx and send machines while waiting for a possible new user input
6 changes: 6 additions & 0 deletions .changeset/pretty-llamas-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": patch
"fuels-wallet": patch
---

Sped up account balance calculation by making requests in parallel
6 changes: 6 additions & 0 deletions .changeset/slow-bulldogs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": minor
"fuels-wallet": minor
---

Centralized provider logic, avoid creating provider for the same network url
6 changes: 6 additions & 0 deletions .changeset/wise-items-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": patch
"fuels-wallet": patch
---

Sped up gas calculation in SendMachine and TxRequestMachine by using already present information on account/balance from AccountMachine instead of re-fetching
6 changes: 6 additions & 0 deletions .changeset/young-laws-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-wallet/connections": minor
"fuels-wallet": minor
---

Improve wallet transaction performance while calculating gas
11 changes: 8 additions & 3 deletions packages/app/playwright/crx/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ test.describe('Check assets', () => {
});

test('should show valid asset value 0.002000', async () => {
expect(
await page.getByText('0.002000', { exact: true }).isVisible()
).toBeTruthy();
await expect
.poll(
async () => {
return await page.getByText('0.002000', { exact: true }).isVisible();
},
{ timeout: 10000 }
)
.toBeTruthy();
});

test('should show USDCIcon AlertTriangle', async () => {
Expand Down
57 changes: 32 additions & 25 deletions packages/app/playwright/e2e/SendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ test.describe('SendTransaction', () => {

const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

Expand Down Expand Up @@ -95,8 +93,6 @@ test.describe('SendTransaction', () => {
// make sure the button is enabled
const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

Expand Down Expand Up @@ -140,8 +136,6 @@ test.describe('SendTransaction', () => {

const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

Expand Down Expand Up @@ -173,12 +167,9 @@ test.describe('SendTransaction', () => {

// Waiting button change to Review in order to ensure that fee amount is updated
await page.waitForSelector('button:has-text("Review")');
await page.waitForTimeout(1000);

const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

Expand Down Expand Up @@ -215,12 +206,9 @@ test.describe('SendTransaction', () => {

// Waiting button change to Review in order to change fee amount
await page.waitForSelector('button:has-text("Review")');
await page.waitForTimeout(1000);

const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

Expand Down Expand Up @@ -253,27 +241,38 @@ test.describe('SendTransaction', () => {

// Waiting button change to Review in order to ensure that fee amount is updated
await page.waitForSelector('button:has-text("Review")');
await page.waitForTimeout(1000);

// Selecting and extracting regular fee amount
await expect
.poll(
async () => {
return await getByAriaLabel(page, 'fee value:Regular').isVisible();
},
{ timeout: 10000 }
)
.toBeTruthy();
const regularFeeComponent = getByAriaLabel(page, 'fee value:Regular');
await regularFeeComponent.click();

// Waiting button change to Review in order to ensure that fee amount is updated
await page.waitForSelector('button:has-text("Review")');
await page.waitForTimeout(1000);

const btnLocatorBeforeApprv = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocatorBeforeApprv);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocatorBeforeApprv);
await btnLocatorBeforeApprv.click();

// Waiting button change to Approve in order to get updated fee amount
await page.waitForSelector('button:has-text("Submit")');
await page.waitForTimeout(1000);

await expect
.poll(
async () => {
return await getButtonByText(page, 'Back').isVisible();
},
{ timeout: 10000 }
)
.toBeTruthy();
// Going back to select other fee value
await getButtonByText(page, 'Back').click();

Expand All @@ -283,27 +282,37 @@ test.describe('SendTransaction', () => {

// Waiting button change to Review in order to change fee amount
await page.waitForSelector('button:has-text("Review")');
await page.waitForTimeout(1000);

const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

// Waiting button change to Approve in order to get updated fee amount
await page.waitForSelector('button:has-text("Submit")');
await page.waitForTimeout(1000);

await hasText(page, '0.001 ETH');

await page.waitForTimeout(1000);
await expect
.poll(
async () => {
return await getButtonByText(page, 'Submit').isEnabled();
},
{ timeout: 10000 }
)
.toBeTruthy();
await getButtonByText(page, 'Submit').click();
await hasText(page, '0.001 ETH');

// Wait for transaction to be confirmed
await hasText(page, 'success');
await expect
.poll(
async () => {
return await hasText(page, 'success');
},
{ timeout: 10000 }
)
.toBeTruthy();
});

test('Send max amount transaction', async () => {
Expand Down Expand Up @@ -343,8 +352,6 @@ test.describe('SendTransaction', () => {

const btnLocator = getButtonByText(page, 'Review');

await expectButtonToBeEnabled(btnLocator);
await page.waitForTimeout(5000);
await expectButtonToBeEnabled(btnLocator);
await btnLocator.click();

Expand Down
6 changes: 4 additions & 2 deletions packages/app/src/systems/Account/services/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createProvider } from '@fuel-wallet/connections';
import type {
Account,
AccountBalance,
Expand All @@ -13,6 +12,7 @@ import type { Maybe } from '~/systems/Core/types';
import { db } from '~/systems/Core/utils/database';
import { readFromOPFS } from '~/systems/Core/utils/opfs';
import { getUniqueString } from '~/systems/Core/utils/string';
import { FuelProviderService } from '~/systems/DApp/services/FuelProviderService';
import { getTestNoDexieDbData } from '../utils/getTestNoDexieDbData';

export type AccountInputs = {
Expand Down Expand Up @@ -105,7 +105,9 @@ export class AccountService {
const { account, providerUrl } = input;

try {
const provider = await createProvider(providerUrl!);
const provider = await FuelProviderService.getOrUpdateProvider(
providerUrl!
);
const balances = await getBalances(provider, account.address);
const balanceAssets = await AssetsCache.fetchAllAssets(
provider.getChainId(),
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/systems/DApp/__mocks__/dapp-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createProvider } from '@fuel-wallet/connections';
import { Address, Provider, bn } from 'fuels';
import { Address, bn } from 'fuels';
import { FuelProviderService } from '~/systems/DApp/services/FuelProviderService';
import { TxService } from '~/systems/Transaction/services';

function getAddressFromString(address: string) {
Expand All @@ -13,7 +13,7 @@ export const getMockedTransaction = async (
providerUrl: string
) => {
const destinyAddress = getAddressFromString(destiny);
const provider = await createProvider(providerUrl);
const provider = await FuelProviderService.getOrUpdateProvider(providerUrl);
const transactionRequest = await TxService.createTransfer({
to: destinyAddress.toString(),
amount: bn.parseUnits('0.1'),
Expand Down
35 changes: 14 additions & 21 deletions packages/app/src/systems/DApp/hooks/useTransactionRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,26 @@ const selectors = {
proposedTxRequest(state: TransactionRequestState) {
return state.context.response?.proposedTxRequest;
},
isLoadingAccounts(state: TransactionRequestState) {
return state.matches('fetchingAccount');
},
errors(state: TransactionRequestState) {
if (!state.context.errors) return {};
const simulateTxErrors = state.context.errors?.simulateTxErrors;
const hasSimulateTxErrors = Boolean(simulateTxErrors);
const txApproveError = state.context.errors?.txApproveError;
return { txApproveError, simulateTxErrors, hasSimulateTxErrors };
},
status(externalLoading?: boolean) {
return useCallback(
(state: TransactionRequestState) => {
const isLoading = state.hasTag('loading');
const isClosed = state.matches('done') || state.matches('failed');

if (state.matches('idle')) return TxRequestStatus.idle;
if (externalLoading || isLoading) return TxRequestStatus.loading;
if (state.matches('txFailed')) return TxRequestStatus.failed;
if (state.matches('txSuccess')) return TxRequestStatus.success;
if (state.matches('sendingTx')) return TxRequestStatus.sending;
if (isClosed) return TxRequestStatus.inactive;
return TxRequestStatus.waitingApproval;
},
[externalLoading]
);
status() {
return useCallback((state: TransactionRequestState) => {
const isLoading = state.hasTag('loading');
const isClosed = state.matches('done') || state.matches('failed');

if (state.matches('idle')) return TxRequestStatus.idle;
if (isLoading) return TxRequestStatus.loading;
if (state.matches('txFailed')) return TxRequestStatus.failed;
if (state.matches('txSuccess')) return TxRequestStatus.success;
if (state.matches('sendingTx')) return TxRequestStatus.sending;
if (isClosed) return TxRequestStatus.inactive;
return TxRequestStatus.waitingApproval;
}, []);
},
title(state: TransactionRequestState) {
if (state.matches('txSuccess')) return 'Transaction sent';
Expand Down Expand Up @@ -95,12 +89,11 @@ export function useTransactionRequest(opts: UseTransactionRequestOpts = {}) {
},
});

const isLoadingAccounts = useSelector(service, selectors.isLoadingAccounts);
const account = useSelector(service, selectors.account);
const ctx = useSelector(service, selectors.context);
const errors = useSelector(service, selectors.errors);
const providerUrl = ctx.input.providerUrl;
const txStatusSelector = selectors.status(isLoadingAccounts);
const txStatusSelector = selectors.status();
const txStatus = useSelector(service, txStatusSelector);
const title = useSelector(service, selectors.title);
const txSummarySimulated = useSelector(service, selectors.txSummarySimulated);
Expand Down
Loading
Loading