Skip to content

Handle the "cancelled" status, lower status polling interval from 10s to 5s, don't mark a tx as cancelled immediately, track uuid #63

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

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 5 additions & 10 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const { safelyExecute } = util;
const SECOND = 1000;
const MINUTE = SECOND * 60;

export const DEFAULT_INTERVAL = SECOND * 10;
export const DEFAULT_INTERVAL = SECOND * 5;
export const CANCELLABLE_INTERVAL = MINUTE;

export interface SmartTransactionsControllerConfig extends BaseConfig {
Expand Down Expand Up @@ -235,6 +235,7 @@ export default class SmartTransactionsController extends BaseController<
}

const sensitiveProperties = {
uuid: updatedSmartTransaction.uuid,
stx_status: updatedSmartTransaction.status,
token_from_address: updatedSmartTransaction.txParams?.from,
token_from_symbol: updatedSmartTransaction.sourceTokenSymbol,
Expand Down Expand Up @@ -605,21 +606,15 @@ export default class SmartTransactionsController extends BaseController<
return data;
}

// ! This should return if the cancellation was on chain or not (for nonce management)
// * After this successful call client must update nonce representative
// * in transaction controller external transactions list
// ! Ask backend API to make this endpoint a POST
// TODO: This should return if the cancellation was on chain or not (for nonce management)
// After this successful call client must update nonce representative
// in transaction controller external transactions list
async cancelSmartTransaction(uuid: string): Promise<void> {
const { chainId } = this.config;
await this.fetch(getAPIRequestURL(APIType.CANCEL, chainId), {
method: 'POST',
body: JSON.stringify({ uuid }),
});

this.updateSmartTransaction({
uuid,
status: SmartTransactionStatuses.CANCELLED_USER_CANCELLED,
});
}

async fetchLiveness(): Promise<boolean> {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum SmartTransactionStatuses {
SUCCESS = 'success',
REVERTED = 'reverted',
UNKNOWN = 'unknown',
CANCELLED = 'cancelled',
CANCELLED_WOULD_REVERT = 'cancelled_would_revert',
CANCELLED_TOO_CHEAP = 'cancelled_too_cheap',
CANCELLED_DEADLINE_MISSED = 'cancelled_deadline_missed',
Expand Down
10 changes: 10 additions & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ describe('src/utils.js', () => {
);
});

it('returns cancelled if minedTx is cancelled', () => {
const statusResponse = {
...createStatusResponse(),
minedTx: SmartTransactionMinedTx.CANCELLED,
};
expect(utils.calculateStatus(statusResponse)).toStrictEqual(
SmartTransactionStatuses.CANCELLED,
);
});

it('returns reverted if minedTx is reverted', () => {
const statusResponse = {
...createStatusResponse(),
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export const calculateStatus = (status: SmartTransactionsStatus) => {
}
} else if (status?.minedTx === SmartTransactionMinedTx.SUCCESS) {
return SmartTransactionStatuses.SUCCESS;
} else if (status?.minedTx === SmartTransactionMinedTx.CANCELLED) {
return SmartTransactionStatuses.CANCELLED;
} else if (status?.minedTx === SmartTransactionMinedTx.REVERTED) {
return SmartTransactionStatuses.REVERTED;
} else if (status?.minedTx === SmartTransactionMinedTx.UNKNOWN) {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"rootDir": "src",
"sourceMap": true,
"strict": true,
"target": "ES2017"
"target": "ES2017",
"skipLibCheck": true
},
"exclude": ["./src/**/*.test.ts"],
"include": ["./src/**/*.ts"]
Expand Down