Skip to content
Merged
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
35 changes: 28 additions & 7 deletions packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1355,14 +1355,17 @@ class ServiceAccount extends ServiceBase {
return parts[1]; // userAddress
}

private async shouldDeleteCredential(
addressRecord: IDBAddress | null,
private async shouldDeleteCredential({
addressRecord,
deletedInfo,
}: {
addressRecord: IDBAddress | null;
deletedInfo: {
walletId?: string;
indexedAccountId?: string;
accountId?: string;
},
): Promise<boolean> {
};
}): Promise<boolean> {
if (!addressRecord) {
return false;
}
Expand All @@ -1389,12 +1392,26 @@ class ServiceAccount extends ServiceBase {
}

@backgroundMethod()
async cleanupOrphanedHyperLiquidAgentCredentials(deletedInfo: {
async cleanupOrphanedHyperLiquidAgentCredentials({
walletId,
indexedAccountId,
accountId,
}: {
walletId?: string;
indexedAccountId?: string;
accountId?: string;
}): Promise<void> {
try {
await timerUtils.wait(1000);
if (indexedAccountId || accountId) {
// eslint-disable-next-line no-param-reassign
walletId = undefined;
}
const deletedInfo = {
walletId,
indexedAccountId,
accountId,
};
// Get all HyperLiquid agent credentials
const allCredentials = await localDb.getAllHyperLiquidAgentCredentials();

Expand All @@ -1414,7 +1431,12 @@ class ServiceAccount extends ServiceBase {
});

// Check if this credential should be deleted
if (await this.shouldDeleteCredential(addressRecord, deletedInfo)) {
if (
await this.shouldDeleteCredential({
addressRecord,
deletedInfo,
})
) {
credentialsToDelete.push(credential);
}
} catch (error) {
Expand Down Expand Up @@ -3159,7 +3181,6 @@ class ServiceAccount extends ServiceBase {

// Cleanup orphaned HyperLiquid agent credentials
void this.cleanupOrphanedHyperLiquidAgentCredentials({
walletId,
accountId: account?.id,
indexedAccountId: indexedAccount?.id,
});
Expand Down
Loading