|
1 | | -import { Address, Bytes, Hex } from 'ox' |
2 | | -import * as Db from '../dbs' |
3 | | -import { Config, Payload } from '@0xsequence/wallet-primitives' |
4 | 1 | import { Envelope } from '@0xsequence/wallet-core' |
| 2 | +import { Config } from '@0xsequence/wallet-primitives' |
| 3 | +import { Hex } from 'ox' |
5 | 4 | import { v7 as uuidv7 } from 'uuid' |
| 5 | +import * as Db from '../dbs' |
6 | 6 | import { Shared } from './manager' |
7 | | -import { Handler } from './handlers' |
8 | 7 | import { BaseSignatureRequest, SignatureRequest, SignerBase, SignerSigned, SignerUnavailable } from './types' |
9 | 8 |
|
10 | 9 | export class Signatures { |
@@ -142,7 +141,21 @@ export class Signatures { |
142 | 141 | } |
143 | 142 |
|
144 | 143 | async complete(requestId: string) { |
145 | | - await this.shared.databases.signatures.del(requestId) |
| 144 | + const request = await this.shared.databases.signatures.get(requestId) |
| 145 | + if (request?.envelope.payload.type === 'config-update') { |
| 146 | + // Clear pending config updates for the same wallet with a checkpoint equal or lower than the completed update |
| 147 | + const pendingRequests = await this.shared.databases.signatures.list() |
| 148 | + const pendingConfigUpdatesToClear = pendingRequests.filter( |
| 149 | + (sig) => |
| 150 | + sig.wallet === request.wallet && |
| 151 | + sig.envelope.payload.type === 'config-update' && |
| 152 | + sig.envelope.configuration.checkpoint <= request.envelope.configuration.checkpoint, |
| 153 | + ) |
| 154 | + // This also deletes the requested id |
| 155 | + await Promise.all(pendingConfigUpdatesToClear.map((sig) => this.shared.modules.signatures.delete(sig.id))) |
| 156 | + } else { |
| 157 | + await this.shared.databases.signatures.del(requestId) |
| 158 | + } |
146 | 159 | } |
147 | 160 |
|
148 | 161 | async request<A extends Db.Action>( |
|
0 commit comments