1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-30 21:52:05 +02:00
blog/src/features/Web3/stores/selectedToken.ts

24 lines
548 B
TypeScript
Raw Normal View History

2023-11-04 01:36:16 +01:00
import { action } from 'nanostores'
import { persistentAtom } from '@nanostores/persistent'
import type { GetToken } from './tokens'
2023-11-01 16:31:29 +01:00
2023-11-04 01:36:16 +01:00
// export const $selectedToken = atom<GetToken | undefined>()
2023-11-01 16:31:29 +01:00
2023-11-04 01:36:16 +01:00
export const $selectedToken = persistentAtom<GetToken | undefined>(
'@kremalicious/selectedToken',
undefined,
{
encode: JSON.stringify,
decode: JSON.parse
}
)
2023-11-03 23:43:06 +01:00
2023-11-04 01:36:16 +01:00
export const $setSelectedToken = action(
$selectedToken,
'setSelectedToken',
(store, token: GetToken | undefined) => {
store.set(token)
return store.get()
}
)