Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim committed Aug 7, 2024
1 parent e910eec commit ee86726
Show file tree
Hide file tree
Showing 29 changed files with 1,205 additions and 196 deletions.
48 changes: 45 additions & 3 deletions packages/site/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { FunctionComponent, ReactNode } from 'react';
import { useContext } from 'react';
import { useContext, useEffect } from 'react';
import styled from 'styled-components';

import { Footer, Header } from './components';
import { Header } from './components';
import { GlobalStyle } from './config/theme';
import { useInvokeSnap, useMetaMaskContext } from './hooks';
import { ToggleThemeContext } from './Root';
import { useStore } from './state';
import { walletSelector } from './state/wallet';
import type { Account, Currency } from './types';

const Wrapper = styled.div`
display: flex;
Expand All @@ -20,14 +24,52 @@ export type AppProps = {

export const App: FunctionComponent<AppProps> = ({ children }) => {
const toggleTheme = useContext(ToggleThemeContext);
const request = useInvokeSnap();
const { provider } = useMetaMaskContext();
const { setAccounts, setBalances, setCurrencies } = useStore(walletSelector);

useEffect(() => {
if (!provider) {
return;
}

// eslint-disable-next-line no-void
void (async () => {
try {
const account = (await request({
method: 'nill_createAccount',
})) as Account;
setAccounts([account]);

const balance = (await request({
method: 'nill_getBalance',
params: {
userAddress: account.account,
},
})) as string;

setBalances({ [account.account]: balance });

const currencies = (await request({
method: 'nill_getCurrencies',
params: {
userAddress: account.account,
},
})) as Currency[];

setCurrencies({ [account.account]: currencies });
} catch (error) {
//
}
})();
}, [provider]);

return (
<>
<GlobalStyle />
<Wrapper>
<Header handleToggleClick={toggleTheme} />
{children}
<Footer />
</Wrapper>
</>
);
Expand Down
16 changes: 16 additions & 0 deletions packages/site/src/components/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ export const ConnectButton = (props: ComponentProps<typeof Button>) => {
);
};

export const FaucetButton = (props: ComponentProps<typeof Button>) => {
return <Button {...props}>Faucet</Button>;
};

export const DeployButton = (props: ComponentProps<typeof Button>) => {
return <Button {...props}>Deploy Account</Button>;
};

export const MintAndCreateButton = (props: ComponentProps<typeof Button>) => {
return <Button {...props}>Create and Mint Currency</Button>;
};

export const SendButton = (props: ComponentProps<typeof Button>) => {
return <Button {...props}>Mint Token</Button>;
};

export const ReconnectButton = (props: ComponentProps<typeof Button>) => {
return (
<Button {...props}>
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Card = ({ content, disabled = false, fullWidth }: CardProps) => {
<CardWrapper fullWidth={fullWidth} disabled={disabled}>
{title && <Title>{title}</Title>}
<Description>{description}</Description>
{button}
{button && button}
</CardWrapper>
);
};
2 changes: 1 addition & 1 deletion packages/site/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const Header = ({
<HeaderWrapper>
<LogoWrapper>
<SnapLogo color={theme.colors.icon?.default} size={36} />
<Title>template-snap</Title>
<Title>=nil;-snap</Title>
</LogoWrapper>
<RightContainer>
<Toggle
Expand Down
5 changes: 3 additions & 2 deletions packages/site/src/hooks/useInvokeSnap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ export const useInvokeSnap = (snapId = defaultSnapOrigin) => {
* @param params.params - The method params.
* @returns The Snap response.
*/
const invokeSnap = async ({ method, params }: InvokeSnapParams) =>
request({
const invokeSnap = async ({ method, params }: InvokeSnapParams) => {
return await request({
method: 'wallet_invokeSnap',
params: {
snapId,
request: params ? { method, params } : { method },
},
});
};

return invokeSnap;
};
2 changes: 2 additions & 0 deletions packages/site/src/hooks/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const useRequest = () => {

return data;
} catch (requestError: any) {
console.log(requestError);

setError(requestError);

return null;
Expand Down
Loading

0 comments on commit ee86726

Please sign in to comment.