wallet-core/packages/anastasis-webui/src/pages/home/ReviewPoliciesScreen.tsx

57 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-10-19 15:56:52 +02:00
/* eslint-disable @typescript-eslint/camelcase */
import { h, VNode } from "preact";
2021-10-22 06:31:46 +02:00
import { useAnastasisContext } from "../../context/anastasis";
import { AnastasisClientFrame } from "./index";
export function ReviewPoliciesScreen(): VNode {
const reducer = useAnastasisContext()
if (!reducer) {
return <div>no reducer in context</div>
}
if (!reducer.currentReducerState || reducer.currentReducerState.backup_state === undefined) {
return <div>invalid state</div>
}
const authMethods = reducer.currentReducerState.authentication_methods ?? [];
const policies = reducer.currentReducerState.policies ?? [];
2021-10-19 15:56:52 +02:00
return (
<AnastasisClientFrame title="Backup: Review Recovery Policies">
2021-10-22 06:31:46 +02:00
{policies.map((p, policy_index) => {
const methods = p.methods
.map(x => authMethods[x.authentication_method] && ({ ...authMethods[x.authentication_method], provider: x.provider }))
.filter(x => !!x)
const policyName = methods.map(x => x.type).join(" + ");
2021-10-19 15:56:52 +02:00
return (
2021-10-22 06:31:46 +02:00
<div key={policy_index} class="policy">
2021-10-19 15:56:52 +02:00
<h3>
2021-10-22 06:31:46 +02:00
Policy #{policy_index + 1}: {policyName}
2021-10-19 15:56:52 +02:00
</h3>
Required Authentications:
2021-10-22 06:31:46 +02:00
{!methods.length && <p>
No auth method found
</p>}
2021-10-19 15:56:52 +02:00
<ul>
2021-10-22 06:31:46 +02:00
{methods.map((m, i) => {
2021-10-19 15:56:52 +02:00
return (
<li key={i}>
2021-10-22 06:31:46 +02:00
{m.type} ({m.instructions}) at provider {m.provider}
2021-10-19 15:56:52 +02:00
</li>
);
})}
</ul>
<div>
<button
2021-10-22 06:31:46 +02:00
onClick={() => reducer.transition("delete_policy", { policy_index })}
2021-10-19 15:56:52 +02:00
>
Delete Policy
</button>
</div>
</div>
);
})}
</AnastasisClientFrame>
);
}