From c873e2d4cfad084adf0ce07283a7bfbb2bd8918d Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 25 Aug 2022 12:28:07 +0530 Subject: [PATCH] Etherscan settings component --- .../settings/src/lib/etherscan-settings.tsx | 58 +++++++++++++++++++ .../settings/src/lib/github-settings.tsx | 4 +- .../settings/src/lib/remix-ui-settings.tsx | 15 ++++- .../settings/src/lib/settingsAction.ts | 1 + libs/remix-ui/settings/src/types/index.ts | 17 +++++- 5 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 libs/remix-ui/settings/src/lib/etherscan-settings.tsx diff --git a/libs/remix-ui/settings/src/lib/etherscan-settings.tsx b/libs/remix-ui/settings/src/lib/etherscan-settings.tsx new file mode 100644 index 0000000000..344b6e49f8 --- /dev/null +++ b/libs/remix-ui/settings/src/lib/etherscan-settings.tsx @@ -0,0 +1,58 @@ +import { CopyToClipboard } from '@remix-ui/clipboard' +import React, { useEffect, useState } from 'react' +import { EtherscanSettingsProps } from '../types' +import { etherscanTokenTitle, etherscanAccessTokenText, etherscanAccessTokenText2, etherscanTokenLink } from './constants' + + +export function EtherscanSettings (props: EtherscanSettingsProps) { + const [etherscanToken, setEtherscanToken] = useState("") + + useEffect(() => { + if (props.config) { + const etherscanToken = props.config.get('settings/etherscan-access-token') || '' + setEtherscanToken(etherscanToken) + } + }, [props.config]) + + const handleChangeTokenState = (event) => { + setEtherscanToken(event.target.value) + } + + // api key settings + const saveEtherscanToken = () => { + props.saveToken(etherscanToken) + } + + const removeToken = () => { + setEtherscanToken('') + props.removeToken() + } + + return ( +
+
+
{etherscanTokenTitle}
+

{etherscanAccessTokenText}

+

{etherscanAccessTokenText2}

+

{etherscanTokenLink}

+
+ +
+ handleChangeTokenState(e)} value={ etherscanToken } /> +
+ +
+
+
+
+
+
+ + +
+
+
+
+
+ ) +} \ No newline at end of file diff --git a/libs/remix-ui/settings/src/lib/github-settings.tsx b/libs/remix-ui/settings/src/lib/github-settings.tsx index e7e68e750f..09c50bb34e 100644 --- a/libs/remix-ui/settings/src/lib/github-settings.tsx +++ b/libs/remix-ui/settings/src/lib/github-settings.tsx @@ -35,14 +35,14 @@ export function GithubSettings (props: GithubSettingsProps) { // api key settings const saveGithubToken = () => { - props.saveTokenToast(githubToken, githubUserName, githubEmail) + props.saveToken(githubToken, githubUserName, githubEmail) } const removeToken = () => { setGithubToken('') setGithubUsername('') setGithubEmail('') - props.removeTokenToast() + props.removeToken() } return ( diff --git a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx index 935704c5ad..b78618935a 100644 --- a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx +++ b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx @@ -9,6 +9,7 @@ import { initialState, toastInitialState, toastReducer, settingReducer } from '. import { Toaster } from '@remix-ui/toaster'// eslint-disable-line import { RemixUiThemeModule, ThemeModule} from '@remix-ui/theme-module' import { GithubSettings } from './github-settings' +import { EtherscanSettings } from './etherscan-settings' /* eslint-disable-next-line */ export interface RemixUiSettingsProps { @@ -388,19 +389,27 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { {state.message ? : null} {generalConfig()} { + saveToken={(githubToken: string, githubUserName: string, githubEmail: string) => { saveTokenToast(props.config, dispatchToast, githubToken, "gist-access-token") saveTokenToast(props.config, dispatchToast, githubUserName, "github-user-name") saveTokenToast(props.config, dispatchToast, githubEmail, "github-email") }} - removeTokenToast={() => { + removeToken={() => { removeTokenToast(props.config, dispatchToast, "gist-access-token") removeTokenToast(props.config, dispatchToast, "github-user-name") removeTokenToast(props.config, dispatchToast, "github-email") }} config={props.config} /> - {token('etherscan')} + { + saveTokenToast(props.config, dispatchToast, etherscanToken, "etherscan-access-token") + }} + removeToken={() => { + removeTokenToast(props.config, dispatchToast, "etherscan-access-token") + }} + config={props.config} + /> {swarmSettings()} {ipfsSettings()} diff --git a/libs/remix-ui/settings/src/lib/settingsAction.ts b/libs/remix-ui/settings/src/lib/settingsAction.ts index fc00e10b64..6388280c66 100644 --- a/libs/remix-ui/settings/src/lib/settingsAction.ts +++ b/libs/remix-ui/settings/src/lib/settingsAction.ts @@ -57,6 +57,7 @@ export const useDisplayErrors = (config, checked, dispatch) => { } export const saveTokenToast = (config, dispatch, tokenValue, key) => { + console.log('key in saveToken---->', key) config.set('settings/' + key, tokenValue) dispatch({ type: 'save', payload: { message: 'GitHub credentials updated' } }) } diff --git a/libs/remix-ui/settings/src/types/index.ts b/libs/remix-ui/settings/src/types/index.ts index 5b4af8dfc1..f14027f886 100644 --- a/libs/remix-ui/settings/src/types/index.ts +++ b/libs/remix-ui/settings/src/types/index.ts @@ -1,6 +1,19 @@ export interface GithubSettingsProps { - saveTokenToast: (githubToken: string, githubUserName: string, githubEmail: string) => void, - removeTokenToast: () => void, + saveToken: (githubToken: string, githubUserName: string, githubEmail: string) => void, + removeToken: () => void, + config: { + exists: (key: string) => boolean, + get: (key: string) => string, + set: (key: string, content: string) => void, + clear: () => void, + getUnpersistedProperty: (key: string) => void, + setUnpersistedProperty: (key: string, value: string) => void + } +} + +export interface EtherscanSettingsProps { + saveToken: (etherscanToken: string) => void, + removeToken: () => void, config: { exists: (key: string) => boolean, get: (key: string) => string,