From d92ee01c60d708844bc7a7aae5e62e972b9c20ee Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:28:42 +0000 Subject: [PATCH] Sandbox run plugin/src/components/DevnetAccountSelector/index.tsx --- .../DevnetAccountSelector/index.tsx | 110 +++++++++++------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/plugin/src/components/DevnetAccountSelector/index.tsx b/plugin/src/components/DevnetAccountSelector/index.tsx index 0063ee3f..7c57b307 100644 --- a/plugin/src/components/DevnetAccountSelector/index.tsx +++ b/plugin/src/components/DevnetAccountSelector/index.tsx @@ -1,8 +1,4 @@ -import { - getRoundedNumber, - getShortenedHash, - weiToEth -} from '../../utils/utils' +import { getRoundedNumber, getShortenedHash, weiToEth } from '../../utils/utils' import { getAccounts } from '../../utils/network' import React, { useEffect, useState } from 'react' import { Account, Provider } from 'starknet' @@ -10,7 +6,13 @@ import { MdCopyAll, MdRefresh } from 'react-icons/md' import './devnetAccountSelector.css' import copy from 'copy-to-clipboard' import { useAtom, useAtomValue } from 'jotai' -import { availableDevnetAccountsAtom, devnetAtom, envAtom, isDevnetAliveAtom, selectedDevnetAccountAtom } from '../../atoms/environment' +import { + availableDevnetAccountsAtom, + devnetAtom, + envAtom, + isDevnetAliveAtom, + selectedDevnetAccountAtom +} from '../../atoms/environment' import useAccount from '../../hooks/useAccount' import useProvider from '../../hooks/useProvider' import useRemixClient from '../../hooks/useRemixClient' @@ -24,8 +26,12 @@ const DevnetAccountSelector: React.FC = () => { const env = useAtomValue(envAtom) const devnet = useAtomValue(devnetAtom) const [isDevnetAlive, setIsDevnetAlive] = useAtom(isDevnetAliveAtom) - const [selectedDevnetAccount, setSelectedDevnetAccount] = useAtom(selectedDevnetAccountAtom) - const [availableDevnetAccounts, setAvailableDevnetAccounts] = useAtom(availableDevnetAccountsAtom) + const [selectedDevnetAccount, setSelectedDevnetAccount] = useAtom( + selectedDevnetAccountAtom + ) + const [availableDevnetAccounts, setAvailableDevnetAccounts] = useAtom( + availableDevnetAccountsAtom + ) const checkDevnetUrl = async (): Promise => { try { @@ -37,7 +43,7 @@ const DevnetAccountSelector: React.FC = () => { } }) const status = await response.json() - + if (!status.version || response.status !== 200) { setIsDevnetAlive(false) } else { @@ -51,7 +57,7 @@ const DevnetAccountSelector: React.FC = () => { // devnet live status useEffect(() => { const interval = setInterval(() => { - checkDevnetUrl().catch(e => { + checkDevnetUrl().catch((e) => { console.error(e) }) }, 3000) @@ -103,7 +109,7 @@ const DevnetAccountSelector: React.FC = () => { if (!isDevnetAlive) { return } - refreshDevnetAccounts().catch(e => { + refreshDevnetAccounts().catch((e) => { console.error(e) }) }, 1) @@ -139,7 +145,7 @@ const DevnetAccountSelector: React.FC = () => { setProvider(newProvider) }, [devnet, selectedDevnetAccount]) - function handleAccountChange (value: number): void { + function handleAccountChange(value: number): void { if (value === -1) { return } @@ -172,44 +178,64 @@ const DevnetAccountSelector: React.FC = () => { const [dropdownControl, setDropdownControl] = useState(false) return ( -
+
- { setDropdownControl(e) }}> - -
- -
+ { + setDropdownControl(e) + }} + > + +
+ + {' '} +
{isDevnetAlive && availableDevnetAccounts.length > 0 ? availableDevnetAccounts.map((account, index) => { - return ( - { handleAccountChange(index) }} key={index}> - {accountIdx === index && } - {`${getShortenedHash( - account.address ?? '', - 6, - 4 - )} (${getRoundedNumber( - weiToEth(account.initial_balance), - 2 - )} ether)`} - - ) - }) + return ( + { + handleAccountChange(index) + }} + key={index} + > + {accountIdx === index && } + {`${getShortenedHash( + account.address ?? '', + 6, + 4 + )} (${getRoundedNumber( + weiToEth(account.initial_balance), + 2 + )} ether)`} + + ) + }) : ([ - { handleAccountChange(-1) }} key={-1}> - No accounts found - + { + handleAccountChange(-1) + }} + key={-1} + > + No accounts found + ] as JSX.Element[])}