Skip to content

Commit

Permalink
move init permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
karczuRF committed Nov 20, 2024
1 parent 65f0341 commit 6a924e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
18 changes: 1 addition & 17 deletions src/store/provider/provider.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ import {
import { AccountsGetBalancesResponse } from "@tari-project/wallet_jrpc_client"
import { BalanceUpdate } from "../simulation/simulation.types"
import { ErrorSource } from "../error/error.types"
import {
TariPermission,
TariPermissionAccountInfo,
TariPermissionKeyList,
TariPermissions,
TariPermissionSubstatesRead,
TariPermissionTransactionSend,
} from "@tari-project/tarijs/dist/providers/wallet_daemon"

let handleMessage: typeof window.postMessage

Expand Down Expand Up @@ -147,15 +139,7 @@ export const initializeAction = () => ({
}
window.addEventListener("message", handleMessage, false)

// set default permissions
let permissions: TariPermission[] = [
new TariPermissionKeyList(),
new TariPermissionAccountInfo(),
new TariPermissionTransactionSend(),
new TariPermissionSubstatesRead(),
]

listenerApi.dispatch(providerActions.initializeSuccess({ provider, permissions }))
listenerApi.dispatch(providerActions.initializeSuccess({ provider }))
} catch (error) {
listenerApi.dispatch(providerActions.initializeFailure({ errorMsg: error as string }))
}
Expand Down
15 changes: 13 additions & 2 deletions src/store/provider/provider.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ import {
UpdatePermissionsRequestPayload,
UpdatePermissionsSuccessPayload,
} from "./provider.types"
import {
TariPermissionAccountInfo,
TariPermissionKeyList,
TariPermissionSubstatesRead,
TariPermissionTransactionSend,
} from "@tari-project/tarijs/dist/providers/tari_universe"

const initialState: ProviderStoreState = {
isInitialized: false,
provider: null,
permissions: [],
// TODO default permissions for built-in provider
permissions: [
new TariPermissionKeyList(),
new TariPermissionAccountInfo(),
new TariPermissionTransactionSend(),
new TariPermissionSubstatesRead(),
],
}

const providerSlice = createSlice({
Expand All @@ -24,7 +36,6 @@ const providerSlice = createSlice({
initializeRequest: (_, _action: PayloadAction<InitProviderRequestPayload>) => {},
initializeSuccess: (state, action: PayloadAction<InitProviderSuccessPayload>) => {
state.provider = action.payload.provider
state.permissions = action.payload.permissions
state.isInitialized = true
},
initializeFailure: (_, _action: PayloadAction<InitProviderFailurePayload>) => {},
Expand Down
1 change: 0 additions & 1 deletion src/store/provider/provider.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type InitProviderFailurePayload = {
}
export type InitProviderSuccessPayload = {
provider: TariUniverseProvider
permissions: TariPermission[]
}

export type UpdatePermissionsRequestPayload = {
Expand Down

0 comments on commit 6a924e8

Please sign in to comment.