Skip to content

Commit

Permalink
fix: make mediator updateable in the nextjs demo (#262)
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Javier Ribo Labrador <elribonazo@gmail.com>
  • Loading branch information
elribonazo authored Aug 12, 2024
1 parent 8a818ad commit 99df3c0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion demos/next/src/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export enum Message {

export enum Credential {
success = "credentialSuccess"
}
}

export enum Mediator {
update = "updateMediator",
}
6 changes: 5 additions & 1 deletion demos/next/src/pages/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import { Box } from "@/app/Box";
import { useMountedApp } from "@/reducers/store";
import { PageHeader } from "@/components/PageHeader";
import { BackupRestore } from "@/components/BackupRestore";
import { reduxActions } from "@/reducers/app";


export default function App() {
const app = useMountedApp();
const [mediatorDID, setMediatorDID] = useState<string>(app.mediatorDID.toString());

function onChangeMediatorDID(e) {
setMediatorDID(e.target.value);
setMediatorDID(e.target.value)
app.dispatch(reduxActions.updateMediator({
mediator: e.target.value
}))
}

return (
Expand Down
10 changes: 9 additions & 1 deletion demos/next/src/reducers/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import SDK from "@atala/prism-wallet-sdk";
import { v4 as uuidv4 } from "uuid";
import { DBPreload, Message, Credential } from "@/actions/types";
import { DBPreload, Message, Credential, Mediator } from "@/actions/types";
import { acceptCredentialOffer, acceptPresentationRequest, connectDatabase, initAgent, rejectCredentialOffer, sendMessage, startAgent, stopAgent } from "../actions";

const defaultMediatorDID = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly8xOTIuMTY4LjEuNDQ6ODA4MCIsImEiOlsiZGlkY29tbS92MiJdfX0.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6IndzOi8vMTkyLjE2OC4xLjQ0OjgwODAvd3MiLCJhIjpbImRpZGNvbW0vdjIiXX19";
Expand Down Expand Up @@ -111,6 +111,14 @@ const appSlice = createSlice({
name: "app",
initialState: initialState,
reducers: {
[Mediator.update]: (
state,
action: PayloadAction<{
mediator: string
}>
) => {
state.mediatorDID = action.payload.mediator
},
[DBPreload.complete]: (
state,
action: PayloadAction<{
Expand Down
1 change: 1 addition & 0 deletions demos/next/src/reducers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const useMountedApp = () => {
return {
...state,
...dispatchedActions,
dispatch
};
};

Expand Down

0 comments on commit 99df3c0

Please sign in to comment.