Skip to content

Commit

Permalink
make InlinePK show Explorer link, so I can use it elsewhere
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
  • Loading branch information
SvenDowideit committed May 13, 2022
1 parent 672085a commit 5e558d3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 43 deletions.
42 changes: 0 additions & 42 deletions src/renderer/components/AccountView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as sol from '@solana/web3.js';
import * as spltoken from '@solana/spl-token';
import { useInterval, useAppSelector } from '../hooks';

import analytics from '../common/analytics';
import { AccountInfo } from '../data/accounts/accountInfo';
import {
truncateLamportAmount,
Expand All @@ -23,7 +22,6 @@ import {
import {
Net,
NetStatus,
netToURL,
selectValidatorNetworkState,
} from '../data/ValidatorNetwork/validatorNetworkState';
import InlinePK from './InlinePK';
Expand All @@ -34,19 +32,6 @@ import { TokenMetaView } from './TokenView';

const logger = window.electron.log;

const explorerURL = (net: Net, address: string) => {
switch (net) {
case Net.Test:
case Net.Dev:
return `https://explorer.solana.com/address/${address}?cluster=${net}`;
case Net.Localhost:
return `https://explorer.solana.com/address/${address}/ \
?cluster=custom&customUrl=${encodeURIComponent(netToURL(net))}`;
default:
return `https://explorer.solana.com/address/${address}`;
}
};

function tryExpandingTokenState(
net: Net,
tAccount: {
Expand Down Expand Up @@ -177,33 +162,6 @@ function AccountView(props: { pubKey: string | undefined }) {
)}
</td>
</tr>
<tr>
<td>
<small className="text-muted">Explorer</small>
</td>
<td>
<small>
{account ? (
<a
onClick={() =>
analytics('clickExplorerLink', { net })
}
href={explorerURL(
net,
account.accountId.toString()
)}
target="_blank"
className="sol-link"
rel="noreferrer"
>
Link
</a>
) : (
'No onchain account'
)}
</small>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
61 changes: 61 additions & 0 deletions src/renderer/components/InlinePK.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { faExplosion } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';

import { ACCOUNTS_NONE_KEY } from '../data/accounts/accountInfo';
import analytics from '../common/analytics';
import { useAppSelector } from '../hooks';
import {
Net,
netToURL,
selectValidatorNetworkState,
} from '../data/ValidatorNetwork/validatorNetworkState';

import CopyIcon from './CopyIcon';

Expand All @@ -12,12 +23,62 @@ const prettifyPubkey = (pk = '') => {
: '';
};

const explorerURL = (net: Net, address: string) => {
switch (net) {
case Net.Test:
case Net.Dev:
return `https://explorer.solana.com/address/${address}?cluster=${net}`;
case Net.Localhost:
return `https://explorer.solana.com/address/${address}/ \
?cluster=custom&customUrl=${encodeURIComponent(netToURL(net))}`;
default:
return `https://explorer.solana.com/address/${address}`;
}
};

const renderCopyTooltip = (id: string, text: string) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any,func-names
function (ttProps: any) {
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<Tooltip id={id} {...ttProps}>
<div>{text}</div>
</Tooltip>
);
};

function InlinePK(props: { pk: string; className?: string }) {
const { pk, className } = props;
const { net } = useAppSelector(selectValidatorNetworkState);

return (
<span className={className}>
<code>{prettifyPubkey(pk)}</code>
<CopyIcon writeValue={pk} />
<small>
{pk !== '' ? (
<OverlayTrigger
placement="bottom"
delay={{ show: 250, hide: 0 }}
overlay={renderCopyTooltip(pk, 'Solana Explorer')}
>
<a
onClick={() => analytics('clickExplorerLink', { net })}
href={explorerURL(net, pk)}
target="_blank"
className="sol-link"
rel="noreferrer"
>
<FontAwesomeIcon
className="border-success rounded p-1 exe-icon"
icon={faExplosion}
/>
</a>
</OverlayTrigger>
) : (
'No onchain account'
)}
</small>
</span>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/nav/TokenPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function TokenPage() {
const conn = new metaplex.Connection(netToURL(net), 'finalized');
try {
const metadata = new metaplex.programs.metadata.MetadataDataData({
name: 'Worbench token',
name: 'Workbench token',
symbol: 'WORKBENCH',
uri: 'https://github.com/workbenchapp/solana-workbench/',
sellerFeeBasisPoints: 10,
Expand Down

0 comments on commit 5e558d3

Please sign in to comment.