2021-10-22 06:31:46 +02:00
|
|
|
/* eslint-disable @typescript-eslint/camelcase */
|
2022-01-24 18:39:27 +01:00
|
|
|
import {
|
2022-06-06 04:10:51 +02:00
|
|
|
AuthenticationProviderStatus,
|
|
|
|
AuthenticationProviderStatusError,
|
|
|
|
AuthenticationProviderStatusOk,
|
2022-01-24 18:39:27 +01:00
|
|
|
BackupStates,
|
|
|
|
RecoveryStates,
|
|
|
|
ReducerState,
|
2022-04-14 21:00:03 +02:00
|
|
|
ReducerStateRecovery,
|
2022-01-24 18:39:27 +01:00
|
|
|
} from "@gnu-taler/anastasis-core";
|
2021-11-10 14:20:52 +01:00
|
|
|
import { FunctionalComponent, h, VNode } from "preact";
|
|
|
|
import { AnastasisProvider } from "../context/anastasis";
|
2021-10-22 06:31:46 +02:00
|
|
|
|
2021-11-10 14:20:52 +01:00
|
|
|
export function createExample<Props>(
|
|
|
|
Component: FunctionalComponent<Props>,
|
|
|
|
currentReducerState?: ReducerState,
|
|
|
|
props?: Partial<Props>,
|
|
|
|
): { (args: Props): VNode } {
|
2021-10-22 06:31:46 +02:00
|
|
|
const r = (args: Props): VNode => {
|
2021-11-10 14:20:52 +01:00
|
|
|
return (
|
|
|
|
<AnastasisProvider
|
|
|
|
value={{
|
|
|
|
currentReducerState,
|
2022-04-13 19:32:12 +02:00
|
|
|
discoverMore: async () => {},
|
|
|
|
discoverStart: async () => {},
|
|
|
|
discoveryState: {
|
|
|
|
state: "none",
|
|
|
|
},
|
2021-11-10 14:20:52 +01:00
|
|
|
currentError: undefined,
|
|
|
|
back: async () => {
|
|
|
|
null;
|
|
|
|
},
|
|
|
|
dismissError: async () => {
|
|
|
|
null;
|
|
|
|
},
|
|
|
|
reset: () => {
|
|
|
|
null;
|
|
|
|
},
|
|
|
|
runTransaction: async () => {
|
|
|
|
null;
|
|
|
|
},
|
|
|
|
startBackup: () => {
|
|
|
|
null;
|
|
|
|
},
|
|
|
|
startRecover: () => {
|
|
|
|
null;
|
|
|
|
},
|
|
|
|
transition: async () => {
|
|
|
|
null;
|
|
|
|
},
|
2022-02-10 20:15:44 +01:00
|
|
|
exportState: () => {
|
|
|
|
return "{}";
|
|
|
|
},
|
|
|
|
importState(s: string) {
|
|
|
|
/* do nothing */
|
|
|
|
},
|
2021-11-10 14:20:52 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Component {...args} />
|
|
|
|
</AnastasisProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
r.args = props;
|
|
|
|
return r;
|
2021-10-22 06:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const base = {
|
|
|
|
continents: [
|
|
|
|
{
|
2021-11-10 14:20:52 +01:00
|
|
|
name: "Europe",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-10 14:20:52 +01:00
|
|
|
name: "India",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-10 14:20:52 +01:00
|
|
|
name: "Asia",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-10 14:20:52 +01:00
|
|
|
name: "North America",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-10 14:20:52 +01:00
|
|
|
name: "Testcontinent",
|
|
|
|
},
|
2021-10-22 06:31:46 +02:00
|
|
|
],
|
|
|
|
countries: [
|
|
|
|
{
|
|
|
|
code: "xx",
|
|
|
|
name: "Testland",
|
|
|
|
continent: "Testcontinent",
|
|
|
|
continent_i18n: {
|
2021-11-10 14:20:52 +01:00
|
|
|
de_DE: "Testkontinent",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
name_i18n: {
|
|
|
|
de_DE: "Testlandt",
|
|
|
|
de_CH: "Testlandi",
|
|
|
|
fr_FR: "Testpais",
|
2021-11-10 14:20:52 +01:00
|
|
|
en_UK: "Testland",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
currency: "TESTKUDOS",
|
2021-11-10 14:20:52 +01:00
|
|
|
call_code: "+00",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: "xy",
|
|
|
|
name: "Demoland",
|
|
|
|
continent: "Testcontinent",
|
|
|
|
continent_i18n: {
|
2021-11-10 14:20:52 +01:00
|
|
|
de_DE: "Testkontinent",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
name_i18n: {
|
|
|
|
de_DE: "Demolandt",
|
|
|
|
de_CH: "Demolandi",
|
|
|
|
fr_FR: "Demopais",
|
2021-11-10 14:20:52 +01:00
|
|
|
en_UK: "Demoland",
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
|
|
|
currency: "KUDOS",
|
2021-11-10 14:20:52 +01:00
|
|
|
call_code: "+01",
|
|
|
|
},
|
2021-10-22 06:31:46 +02:00
|
|
|
],
|
|
|
|
authentication_providers: {
|
|
|
|
"http://localhost:8086/": {
|
2022-06-06 04:10:51 +02:00
|
|
|
status: "ok",
|
2021-10-22 06:31:46 +02:00
|
|
|
http_status: 200,
|
|
|
|
annual_fee: "COL:0",
|
2021-11-11 17:22:14 +01:00
|
|
|
business_name: "Anastasis Local",
|
2021-10-22 06:31:46 +02:00
|
|
|
currency: "COL",
|
|
|
|
liability_limit: "COL:10",
|
|
|
|
methods: [
|
|
|
|
{
|
|
|
|
type: "question",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
|
|
|
},
|
|
|
|
{
|
2021-11-01 20:10:49 +01:00
|
|
|
type: "sms",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
|
|
|
},
|
|
|
|
{
|
2021-11-01 20:10:49 +01:00
|
|
|
type: "email",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
2021-11-01 20:10:49 +01:00
|
|
|
},
|
2021-10-22 06:31:46 +02:00
|
|
|
],
|
2022-06-06 04:10:51 +02:00
|
|
|
provider_salt: "WBMDD76BR1E90YQ5AHBMKPH7GW",
|
2021-10-22 06:31:46 +02:00
|
|
|
storage_limit_in_megabytes: 16,
|
2021-11-10 14:20:52 +01:00
|
|
|
truth_upload_fee: "COL:0",
|
2022-06-06 04:10:51 +02:00
|
|
|
} as AuthenticationProviderStatusOk,
|
2021-11-03 21:30:11 +01:00
|
|
|
"https://kudos.demo.anastasis.lu/": {
|
2022-06-06 04:10:51 +02:00
|
|
|
status: "ok",
|
2021-11-03 21:30:11 +01:00
|
|
|
http_status: 200,
|
|
|
|
annual_fee: "COL:0",
|
2021-11-11 17:22:14 +01:00
|
|
|
business_name: "Anastasis Kudo",
|
2021-11-03 21:30:11 +01:00
|
|
|
currency: "COL",
|
|
|
|
liability_limit: "COL:10",
|
|
|
|
methods: [
|
|
|
|
{
|
|
|
|
type: "question",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 21:30:11 +01:00
|
|
|
type: "email",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
2021-11-03 21:30:11 +01:00
|
|
|
},
|
|
|
|
],
|
2022-06-06 04:10:51 +02:00
|
|
|
provider_salt: "WBMDD76BR1E90YQ5AHBMKPH7GW",
|
2021-11-03 21:30:11 +01:00
|
|
|
storage_limit_in_megabytes: 16,
|
2021-11-10 14:20:52 +01:00
|
|
|
truth_upload_fee: "COL:0",
|
2022-06-06 04:10:51 +02:00
|
|
|
} as AuthenticationProviderStatusOk,
|
2021-11-03 21:30:11 +01:00
|
|
|
"https://anastasis.demo.taler.net/": {
|
2022-06-06 04:10:51 +02:00
|
|
|
status: "ok",
|
2021-11-03 21:30:11 +01:00
|
|
|
http_status: 200,
|
|
|
|
annual_fee: "COL:0",
|
2021-11-11 17:22:14 +01:00
|
|
|
business_name: "Anastasis Demo",
|
2021-11-03 21:30:11 +01:00
|
|
|
currency: "COL",
|
|
|
|
liability_limit: "COL:10",
|
|
|
|
methods: [
|
|
|
|
{
|
|
|
|
type: "question",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 21:30:11 +01:00
|
|
|
type: "sms",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
|
|
|
},
|
|
|
|
{
|
2021-11-03 21:30:11 +01:00
|
|
|
type: "totp",
|
2021-11-10 14:20:52 +01:00
|
|
|
usage_fee: "COL:0",
|
2021-11-03 21:30:11 +01:00
|
|
|
},
|
|
|
|
],
|
2022-06-06 04:10:51 +02:00
|
|
|
provider_salt: "WBMDD76BR1E90YQ5AHBMKPH7GW",
|
2021-11-03 21:30:11 +01:00
|
|
|
storage_limit_in_megabytes: 16,
|
2021-11-10 14:20:52 +01:00
|
|
|
truth_upload_fee: "COL:0",
|
2022-06-06 04:10:51 +02:00
|
|
|
} as AuthenticationProviderStatusOk,
|
2021-11-03 21:30:11 +01:00
|
|
|
|
2021-10-22 06:31:46 +02:00
|
|
|
"http://localhost:8087/": {
|
|
|
|
code: 8414,
|
2021-11-10 14:20:52 +01:00
|
|
|
hint: "request to provider failed",
|
2022-06-06 04:10:51 +02:00
|
|
|
} as AuthenticationProviderStatusError,
|
2021-10-22 06:31:46 +02:00
|
|
|
"http://localhost:8088/": {
|
|
|
|
code: 8414,
|
2021-11-10 14:20:52 +01:00
|
|
|
hint: "request to provider failed",
|
2022-06-06 04:10:51 +02:00
|
|
|
} as AuthenticationProviderStatusError,
|
2021-10-22 06:31:46 +02:00
|
|
|
"http://localhost:8089/": {
|
|
|
|
code: 8414,
|
2021-11-10 14:20:52 +01:00
|
|
|
hint: "request to provider failed",
|
2022-06-06 04:10:51 +02:00
|
|
|
} as AuthenticationProviderStatusError,
|
2021-10-22 06:31:46 +02:00
|
|
|
},
|
2021-11-10 14:20:52 +01:00
|
|
|
} as Partial<ReducerState>;
|
2021-10-22 06:31:46 +02:00
|
|
|
|
|
|
|
export const reducerStatesExample = {
|
|
|
|
initial: undefined,
|
2021-11-03 21:30:11 +01:00
|
|
|
recoverySelectCountry: {
|
|
|
|
...base,
|
2021-11-10 14:20:52 +01:00
|
|
|
recovery_state: RecoveryStates.CountrySelecting,
|
2021-10-22 06:31:46 +02:00
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
recoverySelectContinent: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
recovery_state: RecoveryStates.ContinentSelecting,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
secretSelection: {
|
|
|
|
...base,
|
2022-06-06 04:10:51 +02:00
|
|
|
reducer_type: "recovery",
|
2021-10-22 06:31:46 +02:00
|
|
|
recovery_state: RecoveryStates.SecretSelecting,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
recoveryFinished: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
recovery_state: RecoveryStates.RecoveryFinished,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
challengeSelecting: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
recovery_state: RecoveryStates.ChallengeSelecting,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
challengeSolving: {
|
|
|
|
...base,
|
2022-04-15 18:07:03 +02:00
|
|
|
reducer_type: "recovery",
|
2021-10-22 06:31:46 +02:00
|
|
|
recovery_state: RecoveryStates.ChallengeSolving,
|
2022-04-14 21:00:03 +02:00
|
|
|
} as ReducerStateRecovery,
|
2021-11-03 21:30:11 +01:00
|
|
|
challengePaying: {
|
|
|
|
...base,
|
2021-10-26 17:08:03 +02:00
|
|
|
recovery_state: RecoveryStates.ChallengePaying,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
recoveryAttributeEditing: {
|
|
|
|
...base,
|
2021-11-10 14:20:52 +01:00
|
|
|
recovery_state: RecoveryStates.UserAttributesCollecting,
|
2021-10-26 17:08:03 +02:00
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
backupSelectCountry: {
|
|
|
|
...base,
|
2021-11-10 14:20:52 +01:00
|
|
|
backup_state: BackupStates.CountrySelecting,
|
2021-10-26 17:08:03 +02:00
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
backupSelectContinent: {
|
|
|
|
...base,
|
2021-10-26 17:08:03 +02:00
|
|
|
backup_state: BackupStates.ContinentSelecting,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
secretEdition: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.SecretEditing,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
policyReview: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.PoliciesReviewing,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
policyPay: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.PoliciesPaying,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
backupFinished: {
|
|
|
|
...base,
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.BackupFinished,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
authEditing: {
|
|
|
|
...base,
|
2021-11-10 14:20:52 +01:00
|
|
|
backup_state: BackupStates.AuthenticationsEditing,
|
2022-06-06 04:10:51 +02:00
|
|
|
reducer_type: "backup",
|
2021-10-22 06:31:46 +02:00
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
backupAttributeEditing: {
|
|
|
|
...base,
|
2021-11-10 14:20:52 +01:00
|
|
|
backup_state: BackupStates.UserAttributesCollecting,
|
2021-10-22 06:31:46 +02:00
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
truthsPaying: {
|
|
|
|
...base,
|
2021-11-10 14:20:52 +01:00
|
|
|
backup_state: BackupStates.TruthsPaying,
|
2021-10-22 06:31:46 +02:00
|
|
|
} as ReducerState,
|
2021-11-10 14:20:52 +01:00
|
|
|
};
|