summaryrefslogtreecommitdiff
path: root/packages/anastasis-webui/src/utils/index.tsx
blob: d1d8614696bd7d2b14a90ddc51daf5e9c5e94330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint-disable @typescript-eslint/camelcase */
import { BackupStates, RecoveryStates, ReducerState } from 'anastasis-core';
import { FunctionalComponent, h, VNode } from 'preact';
import { AnastasisProvider } from '../context/anastasis';

export function createExample<Props>(Component: FunctionalComponent<Props>, currentReducerState?: ReducerState, props?: Partial<Props>): { (args: Props): VNode } {
  const r = (args: Props): VNode => {
    return <AnastasisProvider value={{
      currentReducerState,
      currentError: undefined,
      back: () => { null },
      dismissError: () => { null },
      reset: () => { null },
      runTransaction: () => { null },
      startBackup: () => { null },
      startRecover: () => { null },
      transition: () => { null },
    }}>
      <Component {...args} />
    </AnastasisProvider>
  }
  r.args = props
  return r
}

const base = {
  continents: [
    {
      name: "Europe"
    },
    {
      name: "India"
    },
    {
      name: "Asia"
    },
    {
      name: "North America"
    },
    {
      name: "Testcontinent"
    }
  ],
  countries: [
    {
      code: "xx",
      name: "Testland",
      continent: "Testcontinent",
      continent_i18n: {
        de_DE: "Testkontinent"
      },
      name_i18n: {
        de_DE: "Testlandt",
        de_CH: "Testlandi",
        fr_FR: "Testpais",
        en_UK: "Testland"
      },
      currency: "TESTKUDOS",
      call_code: "+00"
    },
    {
      code: "xy",
      name: "Demoland",
      continent: "Testcontinent",
      continent_i18n: {
        de_DE: "Testkontinent"
      },
      name_i18n: {
        de_DE: "Demolandt",
        de_CH: "Demolandi",
        fr_FR: "Demopais",
        en_UK: "Demoland"
      },
      currency: "KUDOS",
      call_code: "+01"
    }
  ],
  authentication_providers: {
    "http://localhost:8086/": {
      http_status: 200,
      annual_fee: "COL:0",
      business_name: "ana",
      currency: "COL",
      liability_limit: "COL:10",
      methods: [
        {
          type: "question",
          usage_fee: "COL:0"
        }
      ],
      salt: "WBMDD76BR1E90YQ5AHBMKPH7GW",
      storage_limit_in_megabytes: 16,
      truth_upload_fee: "COL:0"
    },
    "http://localhost:8087/": {
      code: 8414,
      hint: "request to provider failed"
    },
    "http://localhost:8088/": {
      code: 8414,
      hint: "request to provider failed"
    },
    "http://localhost:8089/": {
      code: 8414,
      hint: "request to provider failed"
    }
  },
  // expiration: {
  //   d_ms: 1792525051855 // check t_ms
  // },
} as Partial<ReducerState>

export const reducerStatesExample = {
  initial: undefined,
  recoverySelectCountry: {...base,
    recovery_state: RecoveryStates.CountrySelecting
  } as ReducerState,
  backupSelectCountry: {...base,
    backup_state: BackupStates.CountrySelecting
  } as ReducerState,
  recoverySelectContinent: {...base,
    recovery_state: RecoveryStates.ContinentSelecting,
  } as ReducerState,
  backupSelectContinent: {...base,
    backup_state: BackupStates.ContinentSelecting,
  } as ReducerState,
  secretSelection: {...base,
    recovery_state: RecoveryStates.SecretSelecting,
  } as ReducerState,
  recoveryFinished: {...base,
    recovery_state: RecoveryStates.RecoveryFinished,
  } as ReducerState,
  challengeSelecting: {...base,
    recovery_state: RecoveryStates.ChallengeSelecting,
  } as ReducerState,
  challengeSolving: {...base,
    recovery_state: RecoveryStates.ChallengeSolving,
  } as ReducerState,
  secretEdition: {...base,
    backup_state: BackupStates.SecretEditing,
  } as ReducerState,
  policyReview: {...base,
    backup_state: BackupStates.PoliciesReviewing,
  } as ReducerState,
  policyPay: {...base,
    backup_state: BackupStates.PoliciesPaying,
  } as ReducerState,
  backupFinished: {...base,
    backup_state: BackupStates.BackupFinished,
  } as ReducerState,
  authEditing: {...base,
    backup_state: BackupStates.AuthenticationsEditing
  } as ReducerState,
  attributeEditing: {...base,
    backup_state: BackupStates.UserAttributesCollecting
  } as ReducerState,
  truthsPaying: {...base,
    backup_state: BackupStates.TruthsPaying
  } as ReducerState,

}