Skip to content
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
4 changes: 4 additions & 0 deletions packages/shield-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Make start and stop idempotent ([#6817](https://github.com/MetaMask/core/pull/6817))

### Fixed

- Fixed incorrect endpoint for signature coverage result. ([#6821](https://github.com/MetaMask/core/pull/6821))

## [0.3.1]

### Changed
Expand Down
34 changes: 22 additions & 12 deletions packages/shield-controller/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export class ShieldRemoteBackend implements ShieldBackend {
));
}

const coverageResult = await this.#getCoverageResult(coverageId);
const txCoverageResultUrl = `${this.#baseUrl}/v1/transaction/coverage/result`;
const coverageResult = await this.#getCoverageResult(coverageId, {
coverageResultUrl: txCoverageResultUrl,
});
return {
coverageId,
message: coverageResult.message,
Expand All @@ -109,7 +112,10 @@ export class ShieldRemoteBackend implements ShieldBackend {
));
}

const coverageResult = await this.#getCoverageResult(coverageId);
const signatureCoverageResultUrl = `${this.#baseUrl}/v1/signature/coverage/result`;
const coverageResult = await this.#getCoverageResult(coverageId, {
coverageResultUrl: signatureCoverageResultUrl,
});
return {
coverageId,
message: coverageResult.message,
Expand Down Expand Up @@ -177,13 +183,20 @@ export class ShieldRemoteBackend implements ShieldBackend {

async #getCoverageResult(
coverageId: string,
timeout: number = this.#getCoverageResultTimeout,
pollInterval: number = this.#getCoverageResultPollInterval,
configs: {
coverageResultUrl: string;
timeout?: number;
pollInterval?: number;
},
): Promise<GetCoverageResultResponse> {
const reqBody: GetCoverageResultRequest = {
coverageId,
};

const timeout = configs?.timeout ?? this.#getCoverageResultTimeout;
const pollInterval =
configs?.pollInterval ?? this.#getCoverageResultPollInterval;

const headers = await this.#createHeaders();
return await new Promise((resolve, reject) => {
let timeoutReached = false;
Expand All @@ -197,14 +210,11 @@ export class ShieldRemoteBackend implements ShieldBackend {
// eslint-disable-next-line no-unmodified-loop-condition
while (!timeoutReached) {
const startTime = Date.now();
const res = await this.#fetch(
`${this.#baseUrl}/v1/transaction/coverage/result`,
{
method: 'POST',
headers,
body: JSON.stringify(reqBody),
},
);
const res = await this.#fetch(configs.coverageResultUrl, {
method: 'POST',
headers,
body: JSON.stringify(reqBody),
});
if (res.status === 200) {
return (await res.json()) as GetCoverageResultResponse;
}
Expand Down
Loading