wallet-core/packages/anastasis-webui/src/utils/index.tsx

282 lines
7.0 KiB
TypeScript
Raw Normal View History

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,
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",
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",
},
{
type: "sms",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
{
type: "email",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
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,
"https://kudos.demo.anastasis.lu/": {
2022-06-06 04:10:51 +02:00
status: "ok",
http_status: 200,
annual_fee: "COL:0",
business_name: "Anastasis Kudo",
currency: "COL",
liability_limit: "COL:10",
methods: [
{
type: "question",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
{
type: "email",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
],
2022-06-06 04:10:51 +02:00
provider_salt: "WBMDD76BR1E90YQ5AHBMKPH7GW",
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,
"https://anastasis.demo.taler.net/": {
2022-06-06 04:10:51 +02:00
status: "ok",
http_status: 200,
annual_fee: "COL:0",
business_name: "Anastasis Demo",
currency: "COL",
liability_limit: "COL:10",
methods: [
{
type: "question",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
{
type: "sms",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
{
type: "totp",
2021-11-10 14:20:52 +01:00
usage_fee: "COL:0",
},
],
2022-06-06 04:10:51 +02:00
provider_salt: "WBMDD76BR1E90YQ5AHBMKPH7GW",
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-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,
recoverySelectCountry: {
...base,
2021-11-10 14:20:52 +01:00
recovery_state: RecoveryStates.CountrySelecting,
2021-10-22 06:31:46 +02:00
} as ReducerState,
recoverySelectContinent: {
...base,
2021-10-22 06:31:46 +02:00
recovery_state: RecoveryStates.ContinentSelecting,
} as ReducerState,
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,
recoveryFinished: {
...base,
2021-10-22 06:31:46 +02:00
recovery_state: RecoveryStates.RecoveryFinished,
} as ReducerState,
challengeSelecting: {
...base,
2021-10-22 06:31:46 +02:00
recovery_state: RecoveryStates.ChallengeSelecting,
} as ReducerState,
challengeSolving: {
...base,
reducer_type: "recovery",
2021-10-22 06:31:46 +02:00
recovery_state: RecoveryStates.ChallengeSolving,
} as ReducerStateRecovery,
challengePaying: {
...base,
recovery_state: RecoveryStates.ChallengePaying,
} as ReducerState,
recoveryAttributeEditing: {
...base,
2021-11-10 14:20:52 +01:00
recovery_state: RecoveryStates.UserAttributesCollecting,
} as ReducerState,
backupSelectCountry: {
...base,
2021-11-10 14:20:52 +01:00
backup_state: BackupStates.CountrySelecting,
} as ReducerState,
backupSelectContinent: {
...base,
backup_state: BackupStates.ContinentSelecting,
} as ReducerState,
secretEdition: {
...base,
2021-10-22 06:31:46 +02:00
backup_state: BackupStates.SecretEditing,
} as ReducerState,
policyReview: {
...base,
2021-10-22 06:31:46 +02:00
backup_state: BackupStates.PoliciesReviewing,
} as ReducerState,
policyPay: {
...base,
2021-10-22 06:31:46 +02:00
backup_state: BackupStates.PoliciesPaying,
} as ReducerState,
backupFinished: {
...base,
2021-10-22 06:31:46 +02:00
backup_state: BackupStates.BackupFinished,
} as ReducerState,
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,
backupAttributeEditing: {
...base,
2021-11-10 14:20:52 +01:00
backup_state: BackupStates.UserAttributesCollecting,
2021-10-22 06:31:46 +02:00
} as ReducerState,
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
};