Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): add explorer link to operator addr #257 #258

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Common/Copy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Copy = observer(({ value }: IProps) => {
>
<CopyButton value={value} timeout={2000}>
{({ copied, copy }) => (
<Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position="right">
<Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position="top">
<ActionIcon color={copied ? 'teal' : 'gray'} onClick={copy}>
{copied ? <IconCheck size={16} /> : <IconCopy size={16} />}
</ActionIcon>
Expand Down
26 changes: 26 additions & 0 deletions src/components/Common/ExternalLink/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Tooltip, Text, CopyButton, ActionIcon } from '@mantine/core';
import { observer, useLocalStore } from 'mobx-react-lite';
import { IconCheck, IconCopy } from '@tabler/icons';
import { Box } from '@chakra-ui/react';
import copy from 'copy-to-clipboard';
import { FiExternalLink } from 'react-icons/fi';

interface IProps {
link: string;
tooltipLabel: string;
}
export const ExternalLink = observer(({ link, tooltipLabel }: IProps) => {
return (
<Box
onClick={async (e) => {
window.open(link);
}}
>
<Tooltip label={tooltipLabel} withArrow position="top">
<Box borderRadius={'4px'} p={1.5} _hover={{ bg: 'rgba(248, 249, 250, 1)' }}>
<FiExternalLink cursor={'pointer'} color="gray" />
</Box>
</Tooltip>
</Box>
);
});
36 changes: 32 additions & 4 deletions src/components/IDE/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React, { useEffect } from 'react';
import { Box, Button, Divider, Flex, Icon, Spinner, Stack, Text, Tooltip } from '@chakra-ui/react';
import { Box, Button, Divider, Flex, HStack, Icon, Spinner, Stack, Text, Tooltip } from '@chakra-ui/react';
import { observer, useLocalObservable } from 'mobx-react-lite';
import { useStore } from '@/store/index';
import { rootStore, useStore } from '@/store/index';
import { ProjectEnvs } from '@/components/JSONFormWidgets/ProjectEnvs';
import { defaultOutlineButtonStyle } from '@/lib/theme';
import { axios } from '@/lib/axios';
import { eventBus } from '@/lib/event';
import { FaFileExport, FaRegQuestionCircle } from 'react-icons/fa';
import { PromiseState } from '@/store/standard/PromiseState';
import { MdEditDocument } from 'react-icons/md';
import { FiExternalLink } from 'react-icons/fi';
import SelectTagWidget from '@/components/JSONFormWidgets/SelectTagWidget';
import { trpc } from '@/lib/trpc';
import toast from 'react-hot-toast';
import { Copy } from '@/components/Common/Copy';
import { ExternalLink } from '@/components/Common/ExternalLink';

const Settings = () => {
const {
Expand Down Expand Up @@ -39,12 +42,25 @@ const Settings = () => {
return '';
}
}
}),
operateBalance: new PromiseState<() => Promise<any>, string>({
defaultValue: null,
function: async () => {
try {
console.log(await rootStore.god.currentNetwork.loadBalanceFromAddress(store.operateAddress.value));
return await (await rootStore.god.currentNetwork.loadBalanceFromAddress(store.operateAddress.value)).format;
} catch (error) {
return '';
}
}
})
}));

useEffect(() => {
project.setMode('edit');
store.operateAddress.call();
store.operateAddress.call().then(() => {
store.operateBalance.call();
});
}, []);

useEffect(() => {
Expand All @@ -59,7 +75,18 @@ const Settings = () => {
{
title: 'Operator Address',
value: store.operateAddress.value,
tips: 'The operator account is randomly generated and assigned to your project. It is used by W3bstream to sign transaction is that your applet sends to the blockchain. Please ensure that you fund this address with the tokens required for gas on the destination chain to which you are se nding your transactions.'
tips: 'The operator account is randomly generated and assigned to your project. It is used by W3bstream to sign transaction is that your applet sends to the blockchain. Please ensure that you fund this address with the tokens required for gas on the destination chain to which you are se nding your transactions.',
extra: (
<>
{store.operateAddress && (
<HStack spacing="4px" ml={2}>
{store.operateBalance.value != null && <Box fontSize="sm">({store.operateBalance.value} IOTX)</Box>}
<ExternalLink tooltipLabel="Jump to explorer" link={`https://iotexscan.io/address/${store.operateAddress.value}?format=0x`} />
<Copy value={store.operateAddress.value} />
</HStack>
)}
</>
)
},
{
title: 'WASM file name',
Expand Down Expand Up @@ -163,6 +190,7 @@ const Settings = () => {
<Text ml="10px" fontSize={'14px'} color="blackAlpha.700">
{item.value}
</Text>

{item.extra}
</Flex>
);
Expand Down
9 changes: 9 additions & 0 deletions src/store/network/EthNetworkState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NetworkState } from './NetworkState';
import { GodStore } from '../god';
import BigNumber from 'bignumber.js';
import { CallParams } from '../lib/ContractState';
import { BigNumberState } from '../standard/BigNumberState';

export class EthNetworkState implements NetworkState {
god: GodStore;
Expand Down Expand Up @@ -35,6 +36,14 @@ export class EthNetworkState implements NetworkState {
this.currentChain.Coin.balance.setValue(new BigNumber(balance.toString()));
}

async loadBalanceFromAddress(address: string): Promise<BigNumberState> {
if (!this.signer) {
return new BigNumberState({ value: new BigNumber(0) });
}
const balance = await this.signer.provider.getBalance(address);
return new BigNumberState({ value: new BigNumber(balance.toString()) });
}

set(args: Partial<EthNetworkState>) {
Object.assign(this, args);
}
Expand Down