Skip to content

Commit

Permalink
update demo wallet; update commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Lykhoyda committed Oct 29, 2024
1 parent 9a57caf commit bc111ad
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 746 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dev": "yarn run just:build-keys && yarn run wasm:build && yarn run snap:start & yarn run demo-wallet:dev",
"build": "yarn workspace @webzjs/demo-wallet run build",
"demo-wallet:dev": "yarn workspace @webzjs/demo-wallet run dev",
"test:e2e": "yarn workspace @webzjs/demo-wallet run test",
"test:e2e": "yarn workspace @webzjs/e2e-tests test",
"snap:start": "yarn workspace @webzjs/zcash-snap run start",
"snap:build": "yarn workspace @webzjs/zcash-snap run build",
"wasm:build": "yarn workspace @webzjs/wasm run build",
Expand Down
1 change: 0 additions & 1 deletion packages/demo-wallet/src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export function App() {
<Container>
<Stack>
<h1>WebZjs Wallet Demo</h1>
<ConnectMetamaskButton />
<Header />
<Tabs
defaultActiveKey="import"
Expand Down
30 changes: 28 additions & 2 deletions packages/demo-wallet/src/App/components/AddAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import { toast, ToastContainer } from 'react-toastify';
import { generate_seed_phrase } from '@webzjs/webz-keys';

import { WalletContext } from '../App';
import { addNewAccountFromUfvk, flushDbToStore } from '../Actions';
import {
addNewAccount,
addNewAccountFromUfvk,
flushDbToStore,
} from '../Actions';
import { NU5_ACTIVATION } from '../Constants';
import { useInvokeSnap } from '../../hooks';
import { useInvokeSnap, useMetaMask } from '../../hooks';
import { ConnectMetamaskButton } from './ConnectMetamaskButton';

export function AddAccount() {
let { state, dispatch } = useContext(WalletContext);
const { installedSnap } = useMetaMask();
const invokeSnap = useInvokeSnap();

let [birthdayHeight, setBirthdayHeight] = useState(0);
Expand All @@ -26,6 +32,18 @@ export function AddAccount() {
}, [state]);

const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
await addNewAccount(state, dispatch, seedPhrase, birthdayHeight);
toast.success('Account imported successfully', {
position: 'top-center',
autoClose: 2000,
});
setBirthdayHeight(0);
setSeedPhrase('');
flushDbToStore(state, dispatch);
};

const handleMetamaskImport = async (e: FormEvent) => {
e.preventDefault();
const viewKey = (await invokeSnap({ method: 'getViewingKey' })) as string;
console.log(viewKey);
Expand Down Expand Up @@ -86,6 +104,14 @@ export function AddAccount() {
<Button variant="primary" type="submit">
Import
</Button>
<ConnectMetamaskButton />
<Button
variant="primary"
onClick={handleMetamaskImport}
disabled={!installedSnap}
>
Import Metamask Account
</Button>
</Form>
<ToastContainer />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ export function ConnectMetamaskButton() {

export const InstallFlaskButton = () => (
<a href="https://metamask.io/flask/" target="_blank">
<button>Install MetaMask Flask</button>
<Button variant="primary">Install MetaMask Flask</Button>
</a>
);

const ConnectButton = (props: ComponentProps<typeof Button>) => {
return (
<button {...props}>
<div>Connect</div>
</button>
<Button {...props}>
<div>Connect Metamask Snap</div>
</Button>
);
};

const ReconnectButton = (props: ComponentProps<typeof Button>) => {
return (
<Button variant={'primary'} {...props}>
<div>Reconnect</div>
<Button variant="primary" {...props}>
<div>Reconnect Snap</div>
</Button>
);
};
2 changes: 1 addition & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "e2e-tests",
"name": "@webzjs/e2e-tests",
"version": "1.0.0",
"description": "",
"source": "src/index.html",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "I8oqZQJw4f+gB4M5fuqENdA6gdGqnub5VtBYaZhdCCk=",
"shasum": "midSiySJ7gsf5hwuXhogBRT8XnUL3yNMyme+BxyVv+s=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Loading

0 comments on commit bc111ad

Please sign in to comment.