@prosopo/procaptcha-react 0.1.0 → 0.1.1
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/README.md +36 -0
- package/dist/components/CaptchaComponent.d.ts +7 -0
- package/dist/components/CaptchaComponent.d.ts.map +1 -0
- package/dist/components/CaptchaComponent.js +58 -0
- package/dist/components/CaptchaComponent.js.map +1 -0
- package/dist/components/CaptchaManager.d.ts +5 -0
- package/dist/components/CaptchaManager.d.ts.map +1 -0
- package/dist/components/CaptchaManager.js +34 -0
- package/dist/components/CaptchaManager.js.map +1 -0
- package/dist/components/CaptchaWidget.d.ts +9 -0
- package/dist/components/CaptchaWidget.d.ts.map +1 -0
- package/dist/components/CaptchaWidget.js +28 -0
- package/dist/components/CaptchaWidget.js.map +1 -0
- package/dist/components/ExtensionAccountSelect.d.ts +9 -0
- package/dist/components/ExtensionAccountSelect.d.ts.map +1 -0
- package/dist/components/ExtensionAccountSelect.js +8 -0
- package/dist/components/ExtensionAccountSelect.js.map +1 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +20 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.d.ts +2 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +88 -0
- package/dist/styles.js.map +1 -0
- package/package.json +2 -2
- package/src/components/CaptchaManager.ts +2 -1
package/README.md
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# React Prosopo Procaptcha Component Library
|
|
2
|
+
|
|
3
|
+
React components for integrating the Prosopo [procaptcha](https://github.com/prosopo-io/procaptcha) into a React app.
|
|
4
|
+
|
|
5
|
+
Prosopo is a distributed human verification service that can be used to stop bots from interacting with smart contracts. Sign up to be a network [alpha tester](https://5b06hrhtlmh.typeform.com/to/vNpyOUfg).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You can install this library with:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @prosopo/procaptcha-react --save
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Basic Usage
|
|
16
|
+
|
|
17
|
+
See the [client example](https://github.com/prosopo-io/client-example) for a minimal example of these components being used in a frontend app.
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
<Box className={"App"}>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<CaptchaContextManager.Provider value={manager}>
|
|
24
|
+
{showCaptchas &&
|
|
25
|
+
<CaptchaComponent {...{ clientInterface }} />}
|
|
26
|
+
</CaptchaContextManager.Provider>
|
|
27
|
+
|
|
28
|
+
{!showCaptchas &&
|
|
29
|
+
<Button onClick={showCaptchaClick} className={"iAmHumanButton"}>
|
|
30
|
+
<Typography className={"iAmHumanButtonLabel"}>
|
|
31
|
+
I am human
|
|
32
|
+
</Typography>
|
|
33
|
+
</Button>}
|
|
34
|
+
|
|
35
|
+
</Box>
|
|
36
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ProsopoCaptchaClient } from "@prosopo/procaptcha";
|
|
3
|
+
export declare function CaptchaComponent({ clientInterface }: {
|
|
4
|
+
clientInterface: ProsopoCaptchaClient;
|
|
5
|
+
}): JSX.Element;
|
|
6
|
+
export default CaptchaComponent;
|
|
7
|
+
//# sourceMappingURL=CaptchaComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptchaComponent.d.ts","sourceRoot":"","sources":["../../src/components/CaptchaComponent.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAEH,oBAAoB,EAGvB,MAAM,qBAAqB,CAAC;AAQ7B,wBAAgB,gBAAgB,CAAC,EAAE,eAAe,EAAE,EAAE;IAAE,eAAe,EAAE,oBAAoB,CAAA;CAAE,eA+E9F;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
3
|
+
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
4
|
+
//
|
|
5
|
+
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// procaptcha-react is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
import { useEffect, useContext, useReducer } from "react";
|
|
18
|
+
import { Box, Button, Typography } from "@mui/material";
|
|
19
|
+
import { ProsopoCaptchaStateClient, captchaStateReducer } from "@prosopo/procaptcha";
|
|
20
|
+
import { CaptchaContextManager } from "./CaptchaManager";
|
|
21
|
+
import { CaptchaWidget } from "./CaptchaWidget";
|
|
22
|
+
import { useStyles } from "../styles";
|
|
23
|
+
export function CaptchaComponent({ clientInterface }) {
|
|
24
|
+
const classes = useStyles();
|
|
25
|
+
const manager = useContext(CaptchaContextManager);
|
|
26
|
+
const [state, update] = useReducer(captchaStateReducer, { captchaIndex: 0, captchaSolution: [] });
|
|
27
|
+
const { account, contractAddress } = manager.state;
|
|
28
|
+
const { captchaChallenge, captchaIndex, captchaSolution } = state;
|
|
29
|
+
const totalCaptchas = captchaChallenge?.captchas.length ?? 0;
|
|
30
|
+
const stateClientInterface = new ProsopoCaptchaStateClient(clientInterface, { state, update });
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
clientInterface.onLoad();
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const extension = clientInterface.getExtension();
|
|
36
|
+
if (contractAddress && extension) {
|
|
37
|
+
extension.setDefaultAccount();
|
|
38
|
+
const defaultAccount = extension.getAccount();
|
|
39
|
+
if (defaultAccount) {
|
|
40
|
+
clientInterface.onAccountChange(defaultAccount);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, [contractAddress]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (account && !captchaChallenge) {
|
|
46
|
+
stateClientInterface.onLoadCaptcha()
|
|
47
|
+
.catch(error => {
|
|
48
|
+
clientInterface.status.update({ error });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}, [account]);
|
|
52
|
+
// TODO text strings
|
|
53
|
+
// https://www.npmjs.com/package/i18next
|
|
54
|
+
return (_jsx(Box, { className: classes.root, children: account && captchaChallenge &&
|
|
55
|
+
_jsxs(Box, { className: classes.captchasContainer, children: [_jsx(Box, { className: classes.captchasHeader, children: _jsxs(Typography, { className: classes.captchasHeaderLabel, children: ["Select all images with ", captchaChallenge.captchas[captchaIndex].captcha.target] }) }), _jsxs(Box, { className: classes.captchasBody, children: [_jsx(CaptchaWidget, { challenge: captchaChallenge.captchas[captchaIndex], solution: captchaSolution[captchaIndex] || [], onChange: stateClientInterface.onChange.bind(stateClientInterface) }), _jsx(Box, { className: classes.dotsContainer, children: captchaChallenge?.captchas.map((_, index) => _jsx(Box, { className: captchaIndex === index ? classes.dot : classes.dotActive }, index)) })] }), _jsxs(Box, { className: classes.captchasFooter, children: [_jsx(Button, { onClick: () => stateClientInterface.onCancel(), variant: "text", children: "Cancel" }), _jsx(Button, { onClick: () => stateClientInterface.onSubmit(), variant: "contained", children: captchaIndex + 1 < totalCaptchas ? "Next" : "Submit" })] })] }) }));
|
|
56
|
+
}
|
|
57
|
+
export default CaptchaComponent;
|
|
58
|
+
//# sourceMappingURL=CaptchaComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptchaComponent.js","sourceRoot":"","sources":["../../src/components/CaptchaComponent.tsx"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,0FAA0F;AAC1F,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAGH,yBAAyB,EACzB,mBAAmB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,UAAU,gBAAgB,CAAC,EAAE,eAAe,EAA6C;IAE3F,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;IAE5B,MAAM,OAAO,GAA2B,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAC1E,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,mBAAmB,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;IAElG,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IACnD,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IAClE,MAAM,aAAa,GAAG,gBAAgB,EAAE,QAAQ,CA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MAAM,IACrE,GACX,EAEN,MAAC,GAAG,IAAC,SAAS,EAAE,OAAO,CAAC,YAAY,aAEhC,KAAC,aAAa,IAAC,SAAS,EAAE,gBAAgB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,YAAY,CAAC,IAAI,EAAE,EAC5G,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,GAAI,EAE1E,KAAC,GAAG,IAAC,SAAS,EAAE,OAAO,CAAC,aAAa,YAChC,gBAAgB,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CACzC,KAAC,GAAG,IAAa,SAAS,EAAE,YAAY,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,IAA1E,KAAK,CAAyE,CAAC,GAC3F,IAEJ,EAEN,MAAC,GAAG,IAAC,SAAS,EAAE,OAAO,CAAC,cAAc,aAClC,KAAC,MAAM,IAAC,OAAO,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAC,MAAM,uBAE7D,EACT,KAAC,MAAM,IAAC,OAAO,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAC,WAAW,YACtE,YAAY,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,GAChD,IACP,IAEJ,GAER,CACT,CAAC;AACN,CAAC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ICaptchaContextState, ICaptchaContextReducer, ProsopoCaptchaClient, CaptchaEventCallbacks } from "@prosopo/procaptcha";
|
|
3
|
+
export declare function useCaptcha(defaultContext: ICaptchaContextState, callbacks?: CaptchaEventCallbacks): ProsopoCaptchaClient;
|
|
4
|
+
export declare const CaptchaContextManager: import("react").Context<ICaptchaContextReducer>;
|
|
5
|
+
//# sourceMappingURL=CaptchaManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptchaManager.d.ts","sourceRoot":"","sources":["../../src/components/CaptchaManager.ts"],"names":[],"mappings":";AAiBA,OAAO,EACH,oBAAoB,EAGpB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACxB,MAAM,qBAAqB,CAAC;AAG7B,wBAAgB,UAAU,CAAC,cAAc,EAAE,oBAAoB,EAAE,SAAS,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAIxH;AAED,eAAO,MAAM,qBAAqB,iDAUN,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { createContext, useReducer } from "react";
|
|
17
|
+
import { captchaContextReducer, captchaStatusReducer, ProsopoCaptchaClient, } from "@prosopo/procaptcha";
|
|
18
|
+
export function useCaptcha(defaultContext, callbacks) {
|
|
19
|
+
const [context, updateContext] = useReducer(captchaContextReducer, defaultContext);
|
|
20
|
+
const [status, updateStatus] = useReducer(captchaStatusReducer, {});
|
|
21
|
+
return new ProsopoCaptchaClient({ state: context, update: updateContext }, { state: status, update: updateStatus }, callbacks);
|
|
22
|
+
}
|
|
23
|
+
export const CaptchaContextManager = createContext({
|
|
24
|
+
state: {
|
|
25
|
+
config: {
|
|
26
|
+
"providerApi.baseURL": "",
|
|
27
|
+
"providerApi.prefix": "",
|
|
28
|
+
"dappAccount": "",
|
|
29
|
+
"dappUrl": "",
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
update: () => { },
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=CaptchaManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptchaManager.js","sourceRoot":"","sources":["../../src/components/CaptchaManager.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,0FAA0F;AAC1F,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAE5E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAEH,qBAAqB,EACrB,oBAAoB,EAEpB,oBAAoB,GAEvB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,UAAU,UAAU,CAAC,cAAoC,EAAE,SAAiC;IAC9F,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,UAAU,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;IACnF,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,UAAU,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;IACpE,OAAO,IAAI,oBAAoB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,SAAS,CAAC,CAAC;AACnI,CAAC;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAC/C,KAAK,EAAE;QACH,MAAM,EAAE;YACJ,qBAAqB,EAAE,EAAE;YACzB,oBAAoB,EAAE,EAAE;YACxB,aAAa,EAAE,EAAE;YACjB,SAAS,EAAE,EAAE;SAChB;KACJ;IACD,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;CACO,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CaptchaResponseCaptcha } from "@prosopo/procaptcha";
|
|
3
|
+
export declare function CaptchaWidget({ challenge, solution, onChange }: {
|
|
4
|
+
challenge: CaptchaResponseCaptcha;
|
|
5
|
+
solution: number[];
|
|
6
|
+
onChange: (index: number) => void;
|
|
7
|
+
}): JSX.Element;
|
|
8
|
+
export default CaptchaWidget;
|
|
9
|
+
//# sourceMappingURL=CaptchaWidget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptchaWidget.d.ts","sourceRoot":"","sources":["../../src/components/CaptchaWidget.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAK7D,wBAAgB,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAC3D;IAAC,SAAS,EAAE,sBAAsB,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAC,eAkB3F;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// Copyright (C) 2021-2022 Prosopo (UK) Ltd.
|
|
3
|
+
// This file is part of procaptcha-react <https://github.com/prosopo-io/procaptcha-react>.
|
|
4
|
+
//
|
|
5
|
+
// procaptcha-react is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// procaptcha-react is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU General Public License
|
|
16
|
+
// along with procaptcha-react. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
import { Avatar } from "@mui/material";
|
|
18
|
+
import { useStyles } from "../styles";
|
|
19
|
+
export function CaptchaWidget({ challenge, solution, onChange }) {
|
|
20
|
+
// TODO challenge.items
|
|
21
|
+
//const items = Array.from(Array(9).keys());
|
|
22
|
+
console.log("CHALLENGE", challenge);
|
|
23
|
+
const items = challenge.captcha.items;
|
|
24
|
+
const classes = useStyles();
|
|
25
|
+
return (_jsx(_Fragment, { children: items.map((item, index) => _jsx(Avatar, { src: item.path, variant: "square", className: classes.captchaItem + " " + (solution.includes(index) ? " selected" : ""), onClick: () => onChange(index) }, index)) }));
|
|
26
|
+
}
|
|
27
|
+
export default CaptchaWidget;
|
|
28
|
+
//# sourceMappingURL=CaptchaWidget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CaptchaWidget.js","sourceRoot":"","sources":["../../src/components/CaptchaWidget.tsx"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,0FAA0F;AAC1F,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,UAAU,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EACiC;IAC1F,uBAAuB;IACvB,4CAA4C;IAC5C,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC;IACtC,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;IAE5B,OAAO,CACL,4BACG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAC,MAAM,IAEjC,GAAG,EAAE,IAAI,CAAC,IAAI,EACd,OAAO,EAAC,QAAQ,EAChB,SAAS,EAAE,OAAO,CAAC,WAAW,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EACpF,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAJzB,KAAK,CAIwB,CACnC,GACA,CACJ,CAAC;AACJ,CAAC;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TExtensionAccount } from "@prosopo/procaptcha";
|
|
3
|
+
export declare const ExtensionAccountSelect: ({ value, options, onChange }: {
|
|
4
|
+
value?: import("@polkadot/extension-inject/types").InjectedAccountWithMeta | undefined;
|
|
5
|
+
options: TExtensionAccount[];
|
|
6
|
+
onChange: (value: TExtensionAccount | null) => void;
|
|
7
|
+
}) => JSX.Element;
|
|
8
|
+
export default ExtensionAccountSelect;
|
|
9
|
+
//# sourceMappingURL=ExtensionAccountSelect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionAccountSelect.d.ts","sourceRoot":"","sources":["../../src/components/ExtensionAccountSelect.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,eAAO,MAAM,sBAAsB;;aACU,iBAAiB,EAAE;sBAAoB,iBAAiB,GAAG,IAAI,KAAK,IAAI;iBAcpH,CAAA;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Autocomplete, TextField } from "@mui/material";
|
|
3
|
+
export const ExtensionAccountSelect = ({ value, options, onChange }) => {
|
|
4
|
+
return (_jsx(Autocomplete, { disablePortal: true, id: "select-accounts" // TODO
|
|
5
|
+
, options: options, value: value, isOptionEqualToValue: (option, value) => option.address === value.address, onChange: (event, value) => onChange(value), sx: { width: 550 }, getOptionLabel: (option) => `${option.meta.name}\n${option.address}`, renderInput: (props) => _jsx(TextField, { ...props, label: "Select account" }) }));
|
|
6
|
+
};
|
|
7
|
+
export default ExtensionAccountSelect;
|
|
8
|
+
//# sourceMappingURL=ExtensionAccountSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionAccountSelect.js","sourceRoot":"","sources":["../../src/components/ExtensionAccountSelect.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAIxD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EACsD,EAAE,EAAE;IACtH,OAAO,CACH,KAAC,YAAY,IACT,aAAa,QACb,EAAE,EAAC,iBAAiB,CAAC,OAAO;UAC5B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,EACZ,oBAAoB,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,EACzE,QAAQ,EAAE,CAAC,KAAqC,EAAE,KAA+B,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EACrG,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,EAClB,cAAc,EAAE,CAAC,MAAW,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,EAAE,EACzE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,SAAS,OAAK,KAAK,EAAE,KAAK,EAAC,gBAAgB,GAAG,GACzE,CACL,CAAC;AACN,CAAC,CAAA;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAeA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,0FAA0F;AAC1F,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,0FAA0F;AAC1F,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"root" | "dot" | "captchasContainer" | "captchasHeader" | "captchasBody" | "captchasFooter" | "captchaItem" | "captchasHeaderLabel" | "dotsContainer" | "dotActive">;
|
|
2
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,SAAS,0NA8DpB,CAAC"}
|
package/dist/styles.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
const dot = {
|
|
18
|
+
width: 7,
|
|
19
|
+
height: 7,
|
|
20
|
+
borderRadius: 3.5,
|
|
21
|
+
marginRight: 5,
|
|
22
|
+
border: "1px solid #CFCFCF",
|
|
23
|
+
backgroundColor: "#FFFFFF",
|
|
24
|
+
};
|
|
25
|
+
export const useStyles = makeStyles({
|
|
26
|
+
root: {
|
|
27
|
+
display: "flex",
|
|
28
|
+
alignItems: "center",
|
|
29
|
+
justifyContent: "center",
|
|
30
|
+
width: "100%",
|
|
31
|
+
height: "100%"
|
|
32
|
+
},
|
|
33
|
+
captchasContainer: {
|
|
34
|
+
display: "flex",
|
|
35
|
+
flexDirection: "column",
|
|
36
|
+
background: "#FFFFFF",
|
|
37
|
+
border: "1px solid #CFCFCF",
|
|
38
|
+
boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)"
|
|
39
|
+
},
|
|
40
|
+
captchasHeader: {
|
|
41
|
+
display: "flex",
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
backgroundColor: "#bdbdbd",
|
|
44
|
+
height: 80,
|
|
45
|
+
paddingLeft: 20
|
|
46
|
+
},
|
|
47
|
+
captchasBody: {
|
|
48
|
+
display: "flex",
|
|
49
|
+
width: 460,
|
|
50
|
+
flexWrap: "wrap",
|
|
51
|
+
height: "max-content",
|
|
52
|
+
paddingTop: 10,
|
|
53
|
+
paddingLeft: 10,
|
|
54
|
+
borderBottom: "1px solid #CFCFCF"
|
|
55
|
+
},
|
|
56
|
+
captchasFooter: {
|
|
57
|
+
display: "flex",
|
|
58
|
+
alignItems: "center",
|
|
59
|
+
justifyContent: "space-between",
|
|
60
|
+
height: 80,
|
|
61
|
+
paddingLeft: 20,
|
|
62
|
+
paddingRight: 20
|
|
63
|
+
},
|
|
64
|
+
captchaItem: {
|
|
65
|
+
width: "140px !important",
|
|
66
|
+
borderRadius: 2,
|
|
67
|
+
height: "140px !important",
|
|
68
|
+
marginRight: 10,
|
|
69
|
+
marginBottom: 10
|
|
70
|
+
},
|
|
71
|
+
captchasHeaderLabel: {
|
|
72
|
+
color: "#ffffff"
|
|
73
|
+
},
|
|
74
|
+
dotsContainer: {
|
|
75
|
+
display: "flex",
|
|
76
|
+
alignItems: "center",
|
|
77
|
+
justifyContent: "center",
|
|
78
|
+
width: "100%",
|
|
79
|
+
paddingBottom: 15,
|
|
80
|
+
paddingTop: 10
|
|
81
|
+
},
|
|
82
|
+
dot,
|
|
83
|
+
dotActive: {
|
|
84
|
+
...dot,
|
|
85
|
+
backgroundColor: "#CFCFCF"
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,0FAA0F;AAC1F,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,sEAAsE;AACtE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,GAAG,GAAG;IACV,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,YAAY,EAAE,GAAG;IACjB,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,mBAAmB;IAC3B,eAAe,EAAE,SAAS;CAC3B,CAAA;AAED,M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GAAG;QACN,eAAe,EAAE,SAAS;KAC3B;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@mui/material": "^5.8.3",
|
|
13
13
|
"@mui/styles": "^5.8.3",
|
|
14
|
-
"@prosopo/procaptcha": "0.1.
|
|
14
|
+
"@prosopo/procaptcha": "0.1.2",
|
|
15
15
|
"react": "^17.0.0",
|
|
16
16
|
"react-dom": "^17.0.0"
|
|
17
17
|
},
|