Skip to content

Commit d39e2e2

Browse files
committed
Add scoped store to plugin contexts
1 parent 96b0de2 commit d39e2e2

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/hooks/useRampPlugins.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react'
33

44
import { pluginFactories } from '../plugins/ramps/allRampPlugins'
55
import type { RampPlugin } from '../plugins/ramps/rampPluginTypes'
6+
import { createStore } from '../plugins/ramps/utils/createStore'
67

78
interface UseRampPluginsOptions {
89
account: EdgeAccount
@@ -25,9 +26,13 @@ export function useRampPlugins({ account }: UseRampPluginsOptions) {
2526

2627
for (const [pluginId, factory] of Object.entries(pluginFactories)) {
2728
try {
29+
// Create store with pluginId as storeId
30+
const store = createStore(pluginId, account.dataStore)
31+
2832
// Create a minimal config for the plugin
2933
const config = {
3034
initOptions: {},
35+
store,
3136
account,
3237
navigation: null as any, // Navigation will be provided by components that need it
3338
onLogEvent: () => {},

src/plugins/ramps/rampPluginTypes.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
FiatPluginRegionCode,
99
FiatPluginUtils
1010
} from '../gui/fiatPluginTypes'
11+
import type { RampPluginStore } from './utils/createStore'
1112

1213
// Token support type (kept for internal plugin use if needed)
1314
export interface ProviderToken {
@@ -91,10 +92,7 @@ export interface RampInfo {
9192

9293
export interface RampPluginConfig {
9394
initOptions?: unknown
94-
store?: {
95-
getItem: (key: string) => Promise<string>
96-
setItem: (key: string, value: string) => Promise<void>
97-
}
95+
store: RampPluginStore
9896
makeUuid?: () => Promise<string>
9997

10098
// Dependencies for plugin operations
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { EdgeDataStore } from 'edge-core-js'
2+
3+
export interface RampPluginStore {
4+
readonly deleteItem: (itemId: string) => Promise<void>
5+
readonly listItemIds: () => Promise<string[]>
6+
readonly getItem: (itemId: string) => Promise<string>
7+
readonly setItem: (itemId: string, value: string) => Promise<void>
8+
}
9+
10+
export const createStore = (
11+
storeId: string,
12+
store: EdgeDataStore
13+
): RampPluginStore => {
14+
return {
15+
deleteItem: async (itemId: string) => {
16+
await store.deleteItem(storeId, itemId)
17+
},
18+
listItemIds: async () => await store.listItemIds(storeId),
19+
getItem: async (itemId: string) => await store.getItem(storeId, itemId),
20+
setItem: async (itemId: string, value: string) => {
21+
await store.setItem(storeId, itemId, value)
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)