diff options
Diffstat (limited to 'extension/src/entries/store/allowedOrigins.ts')
-rw-r--r-- | extension/src/entries/store/allowedOrigins.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/extension/src/entries/store/allowedOrigins.ts b/extension/src/entries/store/allowedOrigins.ts new file mode 100644 index 0000000..7fc5e15 --- /dev/null +++ b/extension/src/entries/store/allowedOrigins.ts @@ -0,0 +1,43 @@ + +import 'pinia' +import { } from 'lodash' +import { PiniaPluginContext } from 'pinia' +import { computed, ref } from 'vue'; +import { onWatchableChange } from '../../features/types'; +import { type AllowedOriginStatus } from '../../features/nip07allow-api'; + +declare module 'pinia' { + export interface PiniaCustomProperties { + isTabAllowed: boolean; + currentOrigin: string | undefined; + allowedOrigins: Array<string>; + isOriginProtectionOn: boolean; + allowOrigin(origin?:string): Promise<void>; + dissallowOrigin(origin?:string): Promise<void>; + disableOriginProtection(): Promise<void>; + setOriginProtection(value: boolean): Promise<void>; + } +} + +export const originPlugin = ({ store }: PiniaPluginContext) => { + + const { plugins } = store + const status = ref<AllowedOriginStatus>() + + onWatchableChange(plugins.allowedOrigins, async () => { + //Update the status + status.value = await plugins.allowedOrigins.getStatus() + }, { immediate: true }) + + return { + allowedOrigins: computed(() => status.value?.allowedOrigins || []), + isTabAllowed: computed(() => status.value?.isAllowed == true), + currentOrigin: computed(() => status.value?.currentOrigin), + isOriginProtectionOn: computed(() => status.value?.enabled == true), + //Push to the allow list, will trigger a change if needed + allowOrigin: plugins.allowedOrigins.addOrigin, + //Remove from allow list, will trigger a change if needed + dissallowOrigin: plugins.allowedOrigins.removeOrigin, + setOriginProtection: plugins.allowedOrigins.enable + } +} |