Skip to content

Commit

Permalink
add a LocalStorage wallet for electron dev-use
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Dowideit <[email protected]>
  • Loading branch information
SvenDowideit committed Apr 11, 2022
1 parent effaa7e commit be5a618
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ export const GlobalContainer: FC = () => {
new LedgerWalletAdapter(),
// new SolletWalletAdapter({ network }),
// new SolletExtensionWalletAdapter({ network }),
new LocalStorageWalletAdapter(),
new LocalStorageWalletAdapter({ endpoint }),
],
[]
[endpoint]
);

return (
Expand Down
65 changes: 51 additions & 14 deletions src/renderer/components/AccountView.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useState } from 'react';
import { useEffect, useState, useCallback } from 'react';
import { faTerminal } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import Container from 'react-bootstrap/Container';
import ButtonGroup from 'react-bootstrap/ButtonGroup';
import ButtonToolbar from 'react-bootstrap/ButtonToolbar';
import * as sol from '@solana/web3.js';
import { useInterval, useAppSelector } from '../hooks';

import analytics from '../common/analytics';
Expand Down Expand Up @@ -37,28 +38,64 @@ const explorerURL = (net: Net, address: string) => {
}
};

function AccountView(props: { pubKey: string | undefined }) {
function AccountView(props: { pubKey: string }) {
const { pubKey } = props;
const { net } = useAppSelector(selectValidatorNetworkState);

const [account, setSelectedAccountInfo] = useState<AccountInfo | undefined>(
undefined
);
if (!pubKey) {
pubKey = '12341234123412341234';
}

useInterval(() => {
const [account, setSelectedAccountInfo] = useState<AccountInfo>({
net,
pubKey,
accountId: new sol.PublicKey(pubKey),
accountInfo: sol.AccountInfo < Buffer > {},
solDelta: 0,
count: 0,
maxDelta: 0,
programID: '',
});

const updateAccount = useCallback(() => {
let ok = false;
if (pubKey) {
getAccount(net, pubKey)
.then((a) => setSelectedAccountInfo(a))
.then((res) => {
// eslint-disable-next-line promise/always-return
if (res) {
setSelectedAccountInfo(res);
ok = true;
}
})
/* eslint-disable no-console */
.catch(console.log);
} else {
setSelectedAccountInfo(undefined);
}
}, 666);
if (!ok) {
const offChainAccount: AccountInfo = {
net,
pubKey,
accountId: new sol.PublicKey(pubKey),
accountInfo: sol.AccountInfo < Buffer > {},
solDelta: 0,
count: 0,
maxDelta: 0,
programID: '',
};
setSelectedAccountInfo(offChainAccount);
}
}, [net, pubKey]);

if (!account) {
return <>No account selected</>;
}
useEffect(() => {
updateAccount();
}, [net, pubKey, updateAccount]);

useInterval(() => {
updateAccount();
}, 666);
// if (!account) {
// return <>No account selected</>;
// }
const humanName = getHumanName(account);
return (
<Container>
Expand Down Expand Up @@ -89,7 +126,7 @@ function AccountView(props: { pubKey: string | undefined }) {
</td>
<td>
<small>
<InlinePK pk={account.accountId.toString()} />
<InlinePK pk={account?.accountId?.toString()} />
</small>
</td>
</tr>
Expand Down
18 changes: 16 additions & 2 deletions src/renderer/components/ProgramChange.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState, useCallback } from 'react';
import * as sol from '@solana/web3.js';

import { faStar } from '@fortawesome/free-solid-svg-icons';
import * as faRegular from '@fortawesome/free-regular-svg-icons';
Expand All @@ -24,18 +25,31 @@ export function ProgramChange(props: {
const [change, setChangeInfo] = useState<AccountInfo | undefined>(undefined);

const updateAccount = useCallback(() => {
let ok = false;
if (pubKey) {
getAccount(net, pubKey)
.then((res) => {
// eslint-disable-next-line promise/always-return
if (res) {
setChangeInfo(res);
ok = true;
}
})
/* eslint-disable no-console */
.catch(console.log);
} else {
setChangeInfo(undefined);
}
if (!ok) {
const offChainAccount: AccountInfo = {
net,
pubKey,
accountId: new sol.PublicKey(pubKey),
accountInfo: sol.AccountInfo < Buffer > {},
solDelta: 0,
count: 0,
maxDelta: 0,
programID: '',
};
setChangeInfo(offChainAccount);
}
}, [net, pubKey]);

Expand Down
9 changes: 8 additions & 1 deletion src/renderer/components/TransferSolButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ function TransferSolPopover(props: { pubKey: string | undefined }) {
{
pending: 'Transfer submitted',
success: 'Transfer succeeded 👌',
error: 'Transfer failed 🤯',
// error: 'Transfer failed 🤯',
error: {
render({ data }) {
console.log('eror', data);
// When the promise reject, data will contains the error
return 'error';
},
},
}
);
}}
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/data/accounts/getAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const renderData = (account: AccountInfo | undefined) => {
// TODO: this should look up a persistent key: string map
export const getHumanName = (key: AccountInfo | sol.PublicKey) => {
/* eslint-disable no-console */
console.log(key);
// console.log(key);

return '';
};
Loading

0 comments on commit be5a618

Please sign in to comment.