|
|
@ -1,4 +1,4 @@ |
|
|
|
import React from "react" |
|
|
|
import React, { useState } from "react" |
|
|
|
|
|
|
|
|
|
|
|
import { Formik, ErrorMessage, Field } from "formik" |
|
|
|
import { Formik, ErrorMessage, Field } from "formik" |
|
|
|
import { useNavigate, useLocation } from "react-router-dom" |
|
|
|
import { useNavigate, useLocation } from "react-router-dom" |
|
|
@ -9,15 +9,14 @@ import { SubmitButton } from "../components" |
|
|
|
export const CaptureKeyView: React.FC = () => { |
|
|
|
export const CaptureKeyView: React.FC = () => { |
|
|
|
const location = useLocation() |
|
|
|
const location = useLocation() |
|
|
|
const navigate = useNavigate() |
|
|
|
const navigate = useNavigate() |
|
|
|
|
|
|
|
const [msg, setMsg] = useState("")
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<AppContext.Consumer> |
|
|
|
<AppContext.Consumer> |
|
|
|
{({ apiKey, clientInstance, setAPIKey }) => { |
|
|
|
{({ apiKey, clientInstance, setAPIKey }) => { |
|
|
|
if (!apiKey && clientInstance && clientInstance.call) { |
|
|
|
if (!apiKey) setMsg('Please add API key to continue. It should be 34 characters long') |
|
|
|
clientInstance.call('sidePanel' as any, 'currentFocus').then((current) => { |
|
|
|
return ( |
|
|
|
if (current === 'etherscan') clientInstance.call('notification' as any, 'toast', 'Please add API key to continue') |
|
|
|
<div> |
|
|
|
}) |
|
|
|
<Formik |
|
|
|
} |
|
|
|
|
|
|
|
return <Formik |
|
|
|
|
|
|
|
initialValues={{ apiKey }} |
|
|
|
initialValues={{ apiKey }} |
|
|
|
validate={(values) => { |
|
|
|
validate={(values) => { |
|
|
|
const errors = {} as any |
|
|
|
const errors = {} as any |
|
|
@ -32,7 +31,6 @@ export const CaptureKeyView: React.FC = () => { |
|
|
|
const apiKey = values.apiKey |
|
|
|
const apiKey = values.apiKey |
|
|
|
if (apiKey.length === 34) { |
|
|
|
if (apiKey.length === 34) { |
|
|
|
setAPIKey(values.apiKey) |
|
|
|
setAPIKey(values.apiKey) |
|
|
|
clientInstance.call('notification' as any, 'toast', 'API key saved successfully!!!') |
|
|
|
|
|
|
|
navigate((location && location.state ? location.state : '/')) |
|
|
|
navigate((location && location.state ? location.state : '/')) |
|
|
|
} |
|
|
|
} |
|
|
|
}} |
|
|
|
}} |
|
|
@ -59,11 +57,20 @@ export const CaptureKeyView: React.FC = () => { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<SubmitButton text="Save" dataId="save-api-key" disable={ errors && errors.apiKey ? true : false } /> |
|
|
|
<SubmitButton text="Save" dataId="save-api-key" disable={errors && errors.apiKey ? true : false } /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
</form> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</Formik> |
|
|
|
</Formik> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div |
|
|
|
|
|
|
|
data-id="api-key-result" |
|
|
|
|
|
|
|
className="text-primary mt-4 text-center" |
|
|
|
|
|
|
|
style={{fontSize: "0.8em"}} |
|
|
|
|
|
|
|
dangerouslySetInnerHTML={{ __html: msg }} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
) |
|
|
|
}} |
|
|
|
}} |
|
|
|
</AppContext.Consumer> |
|
|
|
</AppContext.Consumer> |
|
|
|
) |
|
|
|
) |
|
|
|