@prosopo/procaptcha-react 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CaptchaManager.d.ts.map +1 -1
- package/dist/components/CaptchaManager.js +1 -0
- package/dist/components/CaptchaManager.js.map +1 -1
- package/dist/components/CaptchaWidget.js +1 -1
- package/dist/components/CaptchaWidget.js.map +1 -1
- package/dist/components/ExtensionAccountSelect.d.ts +0 -1
- package/dist/components/ExtensionAccountSelect.d.ts.map +1 -1
- package/dist/styles.d.ts +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +3 -0
- package/dist/styles.js.map +1 -1
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/CaptchaComponent.tsx +0 -112
- package/src/components/CaptchaManager.ts +0 -44
- package/src/components/CaptchaWidget.tsx +0 -43
- package/src/components/ExtensionAccountSelect.tsx +0 -38
- package/src/components/index.ts +0 -19
- package/src/index.ts +0 -17
- package/src/styles.ts +0 -89
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
import { useEffect, useContext, useReducer } from "react";
|
|
17
|
-
import { Box, Button, Typography } from "@mui/material";
|
|
18
|
-
import {
|
|
19
|
-
ICaptchaContextReducer,
|
|
20
|
-
ProsopoCaptchaClient,
|
|
21
|
-
ProsopoCaptchaStateClient,
|
|
22
|
-
captchaStateReducer
|
|
23
|
-
} from "@prosopo/procaptcha";
|
|
24
|
-
|
|
25
|
-
import { CaptchaContextManager } from "./CaptchaManager";
|
|
26
|
-
import { CaptchaWidget } from "./CaptchaWidget";
|
|
27
|
-
|
|
28
|
-
import { useStyles } from "../styles";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export function CaptchaComponent({ clientInterface }: { clientInterface: ProsopoCaptchaClient }) {
|
|
32
|
-
|
|
33
|
-
const classes = useStyles();
|
|
34
|
-
|
|
35
|
-
const manager: ICaptchaContextReducer = useContext(CaptchaContextManager);
|
|
36
|
-
const [state, update] = useReducer(captchaStateReducer, { captchaIndex: 0, captchaSolution: [] });
|
|
37
|
-
|
|
38
|
-
const { account, contractAddress } = manager.state;
|
|
39
|
-
const { captchaChallenge, captchaIndex, captchaSolution } = state;
|
|
40
|
-
const totalCaptchas = captchaChallenge?.captchas.length ?? 0;
|
|
41
|
-
|
|
42
|
-
const stateClientInterface = new ProsopoCaptchaStateClient(clientInterface, { state, update });
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
|
|
46
|
-
clientInterface.onLoad();
|
|
47
|
-
|
|
48
|
-
}, []);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const extension = clientInterface.getExtension();
|
|
52
|
-
if (contractAddress && extension) {
|
|
53
|
-
extension.setDefaultAccount();
|
|
54
|
-
const defaultAccount = extension.getAccount();
|
|
55
|
-
if (defaultAccount) {
|
|
56
|
-
clientInterface.onAccountChange(defaultAccount);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}, [contractAddress]);
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (account && !captchaChallenge) {
|
|
63
|
-
stateClientInterface.onLoadCaptcha()
|
|
64
|
-
.catch(error => {
|
|
65
|
-
clientInterface.status.update({ error });
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}, [account]);
|
|
69
|
-
|
|
70
|
-
// TODO text strings
|
|
71
|
-
// https://www.npmjs.com/package/i18next
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Box className={classes.root}>
|
|
75
|
-
|
|
76
|
-
{account && captchaChallenge &&
|
|
77
|
-
<Box className={classes.captchasContainer}>
|
|
78
|
-
|
|
79
|
-
<Box className={classes.captchasHeader}>
|
|
80
|
-
<Typography className={classes.captchasHeaderLabel}>
|
|
81
|
-
Select all images with {captchaChallenge.captchas[captchaIndex].captcha.target}
|
|
82
|
-
</Typography>
|
|
83
|
-
</Box>
|
|
84
|
-
|
|
85
|
-
<Box className={classes.captchasBody}>
|
|
86
|
-
|
|
87
|
-
<CaptchaWidget challenge={captchaChallenge.captchas[captchaIndex]} solution={captchaSolution[captchaIndex] || []}
|
|
88
|
-
onChange={stateClientInterface.onChange.bind(stateClientInterface)} />
|
|
89
|
-
|
|
90
|
-
<Box className={classes.dotsContainer}>
|
|
91
|
-
{captchaChallenge?.captchas.map((_, index) =>
|
|
92
|
-
<Box key={index} className={captchaIndex === index ? classes.dot : classes.dotActive} />)}
|
|
93
|
-
</Box>
|
|
94
|
-
|
|
95
|
-
</Box>
|
|
96
|
-
|
|
97
|
-
<Box className={classes.captchasFooter}>
|
|
98
|
-
<Button onClick={() => stateClientInterface.onCancel()} variant="text">
|
|
99
|
-
Cancel
|
|
100
|
-
</Button>
|
|
101
|
-
<Button onClick={() => stateClientInterface.onSubmit()} variant="contained">
|
|
102
|
-
{captchaIndex + 1 < totalCaptchas ? "Next" : "Submit"}
|
|
103
|
-
</Button>
|
|
104
|
-
</Box>
|
|
105
|
-
|
|
106
|
-
</Box>
|
|
107
|
-
}
|
|
108
|
-
</Box>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export default CaptchaComponent;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
|
|
17
|
-
import { createContext, useReducer } from "react";
|
|
18
|
-
import {
|
|
19
|
-
ICaptchaContextState,
|
|
20
|
-
captchaContextReducer,
|
|
21
|
-
captchaStatusReducer,
|
|
22
|
-
ICaptchaContextReducer,
|
|
23
|
-
ProsopoCaptchaClient,
|
|
24
|
-
CaptchaEventCallbacks,
|
|
25
|
-
} from "@prosopo/procaptcha";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export function useCaptcha(defaultContext: ICaptchaContextState, callbacks?: CaptchaEventCallbacks): ProsopoCaptchaClient {
|
|
29
|
-
const [context, updateContext] = useReducer(captchaContextReducer, defaultContext);
|
|
30
|
-
const [status, updateStatus] = useReducer(captchaStatusReducer, {});
|
|
31
|
-
return new ProsopoCaptchaClient({ state: context, update: updateContext }, { state: status, update: updateStatus }, callbacks);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const CaptchaContextManager = createContext({
|
|
35
|
-
state: {
|
|
36
|
-
config: {
|
|
37
|
-
"providerApi.baseURL": "",
|
|
38
|
-
"providerApi.prefix": "",
|
|
39
|
-
"dappAccount": "",
|
|
40
|
-
"dappUrl": "",
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
update: () => {},
|
|
44
|
-
} as ICaptchaContextReducer);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
import { Avatar } from "@mui/material";
|
|
17
|
-
import { CaptchaResponseCaptcha } from "@prosopo/procaptcha";
|
|
18
|
-
|
|
19
|
-
import { useStyles } from "../styles";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export function CaptchaWidget({ challenge, solution, onChange }:
|
|
23
|
-
{challenge: CaptchaResponseCaptcha, solution: number[], onChange: (index: number) => void}) {
|
|
24
|
-
// TODO challenge.items
|
|
25
|
-
//const items = Array.from(Array(9).keys());
|
|
26
|
-
console.log("CHALLENGE", challenge);
|
|
27
|
-
const items = challenge.captcha.items;
|
|
28
|
-
const classes = useStyles();
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<>
|
|
32
|
-
{items.map((item, index) => <Avatar
|
|
33
|
-
key={index}
|
|
34
|
-
src={item.path} // TODO challenge.items[].path...
|
|
35
|
-
variant="square"
|
|
36
|
-
className={classes.captchaItem + " " + (solution.includes(index) ? " selected" : "")}
|
|
37
|
-
onClick={() => onChange(index)} />
|
|
38
|
-
)}
|
|
39
|
-
</>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default CaptchaWidget;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
import { SyntheticEvent } from "react";
|
|
17
|
-
import { Autocomplete, TextField } from "@mui/material";
|
|
18
|
-
import { TExtensionAccount } from "@prosopo/procaptcha";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export const ExtensionAccountSelect = ({value, options, onChange}:
|
|
22
|
-
{value?: TExtensionAccount, options: TExtensionAccount[], onChange: (value: TExtensionAccount | null) => void}) => {
|
|
23
|
-
return (
|
|
24
|
-
<Autocomplete
|
|
25
|
-
disablePortal
|
|
26
|
-
id="select-accounts" // TODO
|
|
27
|
-
options={options}
|
|
28
|
-
value={value}
|
|
29
|
-
isOptionEqualToValue={(option, value) => option.address === value.address}
|
|
30
|
-
onChange={(event: SyntheticEvent<Element, Event>, value: TExtensionAccount | null) => onChange(value)}
|
|
31
|
-
sx={{ width: 550 }} // TODO prop
|
|
32
|
-
getOptionLabel={(option: any) => `${option.meta.name}\n${option.address}`}
|
|
33
|
-
renderInput={(props) => <TextField {...props} label="Select account" />} // TODO label
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default ExtensionAccountSelect;
|
package/src/components/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
export * from './CaptchaManager';
|
|
17
|
-
export * from './CaptchaWidget';
|
|
18
|
-
export * from './CaptchaComponent';
|
|
19
|
-
export * from './ExtensionAccountSelect';
|
package/src/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
export * from './components';
|
|
17
|
-
export * from './styles';
|
package/src/styles.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
2
|
-
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
3
|
-
//
|
|
4
|
-
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
5
|
-
// it under the terms of the GNU General Public License as published by
|
|
6
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
// (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// procaptcha-react is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
// GNU General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU General Public License
|
|
15
|
-
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
import { makeStyles } from "@mui/styles";
|
|
17
|
-
|
|
18
|
-
const dot = {
|
|
19
|
-
width: 7,
|
|
20
|
-
height: 7,
|
|
21
|
-
borderRadius: 3.5,
|
|
22
|
-
marginRight: 5,
|
|
23
|
-
border: "1px solid #CFCFCF",
|
|
24
|
-
backgroundColor: "#FFFFFF",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const useStyles = makeStyles({
|
|
28
|
-
root: {
|
|
29
|
-
display: "flex",
|
|
30
|
-
alignItems: "center",
|
|
31
|
-
justifyContent: "center",
|
|
32
|
-
width: "100%",
|
|
33
|
-
height: "100%"
|
|
34
|
-
},
|
|
35
|
-
captchasContainer: {
|
|
36
|
-
display: "flex",
|
|
37
|
-
flexDirection: "column",
|
|
38
|
-
background: "#FFFFFF",
|
|
39
|
-
border: "1px solid #CFCFCF",
|
|
40
|
-
boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)"
|
|
41
|
-
},
|
|
42
|
-
captchasHeader: {
|
|
43
|
-
display: "flex",
|
|
44
|
-
alignItems: "center",
|
|
45
|
-
backgroundColor: "#bdbdbd",
|
|
46
|
-
height: 80,
|
|
47
|
-
paddingLeft: 20
|
|
48
|
-
},
|
|
49
|
-
captchasBody: {
|
|
50
|
-
display: "flex",
|
|
51
|
-
width: 460,
|
|
52
|
-
flexWrap: "wrap",
|
|
53
|
-
height: "max-content",
|
|
54
|
-
paddingTop: 10,
|
|
55
|
-
paddingLeft: 10,
|
|
56
|
-
borderBottom: "1px solid #CFCFCF"
|
|
57
|
-
},
|
|
58
|
-
captchasFooter: {
|
|
59
|
-
display: "flex",
|
|
60
|
-
alignItems: "center",
|
|
61
|
-
justifyContent: "space-between",
|
|
62
|
-
height: 80,
|
|
63
|
-
paddingLeft: 20,
|
|
64
|
-
paddingRight: 20
|
|
65
|
-
},
|
|
66
|
-
captchaItem: {
|
|
67
|
-
width: "140px !important",
|
|
68
|
-
borderRadius: 2,
|
|
69
|
-
height: "140px !important",
|
|
70
|
-
marginRight: 10,
|
|
71
|
-
marginBottom: 10
|
|
72
|
-
},
|
|
73
|
-
captchasHeaderLabel: {
|
|
74
|
-
color: "#ffffff"
|
|
75
|
-
},
|
|
76
|
-
dotsContainer: {
|
|
77
|
-
display: "flex",
|
|
78
|
-
alignItems: "center",
|
|
79
|
-
justifyContent: "center",
|
|
80
|
-
width: "100%",
|
|
81
|
-
paddingBottom: 15,
|
|
82
|
-
paddingTop: 10
|
|
83
|
-
},
|
|
84
|
-
dot,
|
|
85
|
-
dotActive: {
|
|
86
|
-
...dot,
|
|
87
|
-
backgroundColor: "#CFCFCF"
|
|
88
|
-
},
|
|
89
|
-
});
|