Skip to content

Commit

Permalink
Remove ended crowdloan
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Oct 25, 2023
1 parent 73427c2 commit cf710f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/extension-base/src/koni/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ export default class KoniState {
this.onAccountAdd();
this.onAccountRemove();

// TODO: consider moving this to a separate service
await this.dbService.stores.crowdloan.removeEndedCrowdloans();

await this.startSubscription();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ import BaseStoreWithAddressAndChain from '@subwallet/extension-base/services/sto
import { ICrowdloanItem } from '../databases';

export default class CrowdloanStore extends BaseStoreWithAddressAndChain<ICrowdloanItem> {
async removeEndedCrowdloans () {
const now = new Date();
const removeList: string[] = [];

await this.table.each((obj, cursor) => {
try {
if (!obj.endTime || new Date(obj.endTime) < now) {
removeList.push(cursor.primaryKey as string);
}
} catch (e) {
console.error(e);
}
});

await this.table.bulkDelete(removeList);
}

getCrowdloan (address: string) {
return this.table.where('address').equals(address).toArray();
}
Expand Down

1 comment on commit cf710f1

@saltict
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.