Skip to content

Conversation

@chadoh
Copy link
Member

@chadoh chadoh commented May 6, 2025

In #29, the raw calls to localStorage made me uneasy for a couple reasons:

  1. Lots of strings! If the name of one of those keys gets mistyped, bad things will happen. Better to have type-checking on the strings, or to store them in constants, or something.
  2. No types on the storage

A tricky thing here is that we are implementing a starting point for other projects. We want to provide something minimal, yet powerful. I confess that what I've added here might not qualify as "minimal"!

I don't want these new projects to have unnecessary npm dependencies, so I re-implemented (a minimal version of) an existing library.

I think the storage.ts file is slim enough to be understandable, and has nice properties. If you define your keys like this:

const keys = { walletId: 'a', walletAddress: 0 }

Then when you import storage elsewhere, you get this typeahead on getItem:

a tooltip over 'getItem' shows that the first argument can be either 'walletId' or 'walletAddress'

And the return types for keys of different types are all well-typed:

the type returned by 'walletAddress' is a number the type returned by 'walletId' is a string

@chadoh chadoh force-pushed the feat/typed-storage branch from 8a8f8b2 to 3ab1a1a Compare May 6, 2025 19:11
@chadoh chadoh requested review from hugo-heer and pselle May 6, 2025 19:12
@hugo-heer hugo-heer merged commit 4e582d3 into feat/wallet-integration May 7, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants