Skip to content

Commit

Permalink
fix: missing deadline in swaps stx status screen (#25779)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

This PR fixes an issue where the STX status screen for a swap was
showing a 0:00 for the timer.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25779?quickstart=1)

Related to: #25063

1. Make sure Smart Transactions is on (Settings > Advanced)
2. Do a Swap
3. Observe that timer is not 0:00 and is a reasonable number

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<!-- [screenshots/recordings] -->

https://github.com/MetaMask/metamask-extension/assets/139582705/26fe6167-614f-4771-b35b-10803bc23fc0

<!-- [screenshots/recordings] -->

https://github.com/MetaMask/metamask-extension/assets/139582705/d92b933d-1011-48b4-bf04-344f275d35db

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Marta Poling <[email protected]>
  • Loading branch information
infiniteflower and martahj committed Sep 4, 2024
1 parent 227d099 commit aaad35f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/scripts/controllers/swaps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CHAIN_IDS } from '../../../../shared/constants/network';
import {
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
FALLBACK_SMART_TRANSACTIONS_DEADLINE,
} from '../../../../shared/constants/smartTransactions';
import {
DEFAULT_ERC20_APPROVE_GAS,
Expand Down Expand Up @@ -918,6 +919,7 @@ export default class SwapsController extends BaseController<
functionName: '_fetchSwapsNetworkConfig',
});
const { refreshRates, parameters = {} } = response || {};
console.log('parameters', parameters);
if (
!refreshRates ||
typeof refreshRates.quotes !== 'number' ||
Expand All @@ -935,6 +937,7 @@ export default class SwapsController extends BaseController<
stxBatchStatus: refreshRates.stxBatchStatus * 1000,
stxStatusDeadline: refreshRates.stxStatusDeadline,
stxMaxFeeMultiplier: parameters.stxMaxFeeMultiplier,
swapsStxStatusDeadline: parameters.stxStatusDeadline,
};
}

Expand Down Expand Up @@ -1061,6 +1064,7 @@ export default class SwapsController extends BaseController<
stxBatchStatus: number;
stxStatusDeadline: number;
stxMaxFeeMultiplier: number;
swapsStxStatusDeadline: number;
} | null = null;

try {
Expand All @@ -1082,6 +1086,9 @@ export default class SwapsController extends BaseController<
_state.swapsState.swapsStxMaxFeeMultiplier =
swapsNetworkConfig?.stxMaxFeeMultiplier ||
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER;
_state.swapsState.swapsStxStatusDeadline =
swapsNetworkConfig?.swapsStxStatusDeadline ||
FALLBACK_SMART_TRANSACTIONS_DEADLINE;
});
}

Expand Down
2 changes: 2 additions & 0 deletions app/scripts/controllers/swaps/swaps.constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
FALLBACK_SMART_TRANSACTIONS_DEADLINE,
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
} from '../../../../shared/constants/smartTransactions';
Expand Down Expand Up @@ -44,6 +45,7 @@ export function getDefaultSwapsControllerState(): SwapsControllerState {
swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
swapsQuotePrefetchingRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
swapsStxBatchStatusRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxStatusDeadline: FALLBACK_SMART_TRANSACTIONS_DEADLINE,
swapsStxGetTransactionsRefreshTime:
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxMaxFeeMultiplier: FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/controllers/swaps/swaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ describe('SwapsController', function () {
const swapsQuotePrefetchingRefreshTime = 0;
const swapsStxBatchStatusRefreshTime = 0;
const swapsStxGetTransactionsRefreshTime = 0;
const swapsStxStatusDeadline = 0;
swapsController.__test__updateState({
swapsState: {
...swapsController.state.swapsState,
Expand All @@ -1182,6 +1183,7 @@ describe('SwapsController', function () {
swapsQuotePrefetchingRefreshTime,
swapsStxBatchStatusRefreshTime,
swapsStxGetTransactionsRefreshTime,
swapsStxStatusDeadline,
},
});

Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export const SENTRY_BACKGROUND_STATE = {
swapsQuotePrefetchingRefreshTime: true,
swapsQuoteRefreshTime: true,
swapsStxBatchStatusRefreshTime: true,
swapsStxStatusDeadline: true,
swapsStxGetTransactionsRefreshTime: true,
swapsStxMaxFeeMultiplier: true,
swapsUserFeeLevel: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@
"swapsQuoteRefreshTime": 60000,
"swapsQuotePrefetchingRefreshTime": 60000,
"swapsStxBatchStatusRefreshTime": 10000,
"swapsStxStatusDeadline": 180,
"swapsStxGetTransactionsRefreshTime": 10000,
"swapsStxMaxFeeMultiplier": 2,
"swapsFeatureFlags": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
"swapsQuoteRefreshTime": 60000,
"swapsQuotePrefetchingRefreshTime": 60000,
"swapsStxBatchStatusRefreshTime": 10000,
"swapsStxStatusDeadline": 180,
"swapsStxGetTransactionsRefreshTime": 10000,
"swapsStxMaxFeeMultiplier": 2,
"swapsFeatureFlags": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export default function SmartTransactionStatusPage() {
cancellationFeeWei =
latestSmartTransaction?.statusMetadata?.cancellationFeeWei;
}

const [timeLeftForPendingStxInSec, setTimeLeftForPendingStxInSec] = useState(
swapsNetworkConfig.stxStatusDeadline,
);
Expand Down

0 comments on commit aaad35f

Please sign in to comment.