2022-06-06 16:25:37 +02:00
|
|
|
/*
|
2022-06-06 16:45:01 +02:00
|
|
|
This file is part of GNU Anastasis
|
|
|
|
(C) 2021-2022 Anastasis SARL
|
2022-06-06 16:25:37 +02:00
|
|
|
|
2022-06-06 16:45:01 +02:00
|
|
|
GNU Anastasis is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU Affero General Public License as published by the Free Software
|
2022-06-06 16:25:37 +02:00
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
2022-06-06 16:45:01 +02:00
|
|
|
GNU Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
|
2022-06-06 16:25:37 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
2022-06-06 16:45:01 +02:00
|
|
|
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
2022-06-06 16:25:37 +02:00
|
|
|
|
2022-06-06 16:45:01 +02:00
|
|
|
You should have received a copy of the GNU Affero General Public License along with
|
|
|
|
GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2022-06-06 16:25:37 +02:00
|
|
|
*/
|
2022-01-24 18:39:27 +01:00
|
|
|
import {
|
2022-06-06 04:10:51 +02:00
|
|
|
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";
|
2022-06-06 05:04:53 +02:00
|
|
|
import { AnastasisProvider } from "../context/anastasis.js";
|
|
|
|
|
|
|
|
const noop = async (): Promise<void> => {
|
|
|
|
return;
|
|
|
|
};
|
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-06-06 05:04:53 +02:00
|
|
|
discoverMore: noop,
|
|
|
|
discoverStart: noop,
|
2022-04-13 19:32:12 +02:00
|
|
|
discoveryState: {
|
|
|
|
state: "none",
|
|
|
|
},
|
2021-11-10 14:20:52 +01:00
|
|
|
currentError: undefined,
|
2022-06-06 05:04:53 +02:00
|
|
|
back: noop,
|
|
|
|
dismissError: noop,
|
|
|
|
reset: noop,
|
|
|
|
runTransaction: noop,
|
|
|
|
startBackup: noop,
|
|
|
|
startRecover: noop,
|
|
|
|
transition: noop,
|
2022-02-10 20:15:44 +01:00
|
|
|
exportState: () => {
|
|
|
|
return "{}";
|
|
|
|
},
|
2022-06-06 05:04:53 +02:00
|
|
|
importState: noop,
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "recovery",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "recovery",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "recovery",
|
2021-10-22 06:31:46 +02:00
|
|
|
recovery_state: RecoveryStates.RecoveryFinished,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
challengeSelecting: {
|
|
|
|
...base,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "recovery",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "recovery",
|
2021-10-26 17:08:03 +02:00
|
|
|
recovery_state: RecoveryStates.ChallengePaying,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
recoveryAttributeEditing: {
|
|
|
|
...base,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "recovery",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
2021-10-26 17:08:03 +02:00
|
|
|
backup_state: BackupStates.ContinentSelecting,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
secretEdition: {
|
|
|
|
...base,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.SecretEditing,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
policyReview: {
|
|
|
|
...base,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.PoliciesReviewing,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
policyPay: {
|
|
|
|
...base,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
2021-10-22 06:31:46 +02:00
|
|
|
backup_state: BackupStates.PoliciesPaying,
|
|
|
|
} as ReducerState,
|
2021-11-03 21:30:11 +01:00
|
|
|
backupFinished: {
|
|
|
|
...base,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
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,
|
2022-06-08 20:18:41 +02:00
|
|
|
reducer_type: "backup",
|
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
|
|
|
};
|