diff --git a/packages/site/src/pages/index.tsx b/packages/site/src/pages/index.tsx index ce7db80..20b5f1b 100644 --- a/packages/site/src/pages/index.tsx +++ b/packages/site/src/pages/index.tsx @@ -34,7 +34,6 @@ import { Card, LoginAccountButton, CreateAccountButton } from '../components'; import SendIcon from '@mui/icons-material/Send'; import { SHA256 } from 'crypto-js'; - const Container = styled.div` display: flex; flex-direction: column; @@ -51,7 +50,6 @@ const Container = styled.div` } `; - const darkTheme = createTheme({ palette: { mode: 'dark' } }); const lightTheme = createTheme({ palette: { mode: 'light' } }); const Heading = styled.h1` @@ -85,19 +83,19 @@ const CardContainer = styled.div` margin-top: 1.5rem; `; const CreateButton = styled(Button)` -font-size: 1.5rem; -border-radius: 8px; -width: 200px; -height: 40px; -margin-top: 50px; -align-self: center; -display: flex; -justify-content: center; -align-items: center; -position: absolute; -top: 10px; -left: 50%; -transform: translateX(-50%); + font-size: 1.5rem; + border-radius: 8px; + width: 200px; + height: 40px; + margin-top: 50px; + align-self: center; + display: flex; + justify-content: center; + align-items: center; + position: absolute; + top: 10px; + left: 50%; + transform: translateX(-50%); `; const Notice = styled.div` background-color: ${({ theme }) => theme.colors.background?.alternative}; @@ -160,15 +158,14 @@ const AccountInfoBox = styled.div` padding: 15px; margin-bottom: 20px; color: black; - font-size: 1.2rem; - width: auto; - height: 10px; - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + font-size: 1.2rem; + width: auto; + height: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); background-color: rgba(25, 118, 210, 0.1); display: flex; align-items: center; justify-content: center; - `; const AccountModalContent = styled(DialogContent)` font-size: 90rem; @@ -278,13 +275,12 @@ const Index = () => { openCreateAccountModal(); setIsAccountLogin(true); setIsAccountCreating(false); - } + }; const handleAccount = () => { - if(isAccountCreating){ - handleSendGetAccount() - } - else{ - handleLoginAccount() + if (isAccountCreating) { + handleSendGetAccount(); + } else { + handleLoginAccount(); } setIsCreatingAccount(false); setInputPassword(''); @@ -297,13 +293,12 @@ const Index = () => { }; const handleSendGetAccount = async () => { try { - const accountinfo: any = await sendGetAccount(); + const accountinfo: any = await sendGetAccount(password); const { accountInfo } = accountinfo; - const {address, bal} = accountInfo; + const { address, bal } = accountInfo; setAddress(address); setBalance(bal); const hashedPassword = SHA256(inputPassword).toString(); - await sendSetData(pvtKey, address, hashedPassword); setShowCreateAccountCard(false); setIsAccount(true); } catch (error) { @@ -316,7 +311,7 @@ const Index = () => { try { const hashedPassword = SHA256(inputPassword).toString(); const accountinfo: any = await sendGetData(hashedPassword); - const {address} = accountinfo; + const { address } = accountinfo; const bal = await sendGetBalance(); setAddress(address); setBalance(bal); @@ -326,7 +321,7 @@ const Index = () => { console.error(error); dispatch({ type: MetamaskActions.SetError, payload: error }); } - } + }; const handleCoinTransfer = async () => { closeSendModal(); @@ -364,7 +359,6 @@ const Index = () => { } }; - return ( @@ -376,48 +370,48 @@ const Index = () => { An error happened: {state.error.message} )} - {showCreateAccountCard && !isAccount && ( - - ), - }} - disabled={!state.installedSnap} - fullWidth={ - isMetaMaskReady && - Boolean(state.installedSnap) && - !shouldDisplayReconnectButton(state.installedSnap) - } - /> - )} - {showCreateAccountCard && !isAccount && ( - - ), - }} - disabled={!state.installedSnap} - fullWidth={ - isMetaMaskReady && - Boolean(state.installedSnap) && - !shouldDisplayReconnectButton(state.installedSnap) - } - /> - )} + {showCreateAccountCard && !isAccount && ( + + ), + }} + disabled={!state.installedSnap} + fullWidth={ + isMetaMaskReady && + Boolean(state.installedSnap) && + !shouldDisplayReconnectButton(state.installedSnap) + } + /> + )} + {showCreateAccountCard && !isAccount && ( + + ), + }} + disabled={!state.installedSnap} + fullWidth={ + isMetaMaskReady && + Boolean(state.installedSnap) && + !shouldDisplayReconnectButton(state.installedSnap) + } + /> + )} Send Funds @@ -440,7 +434,7 @@ const Index = () => { - @@ -464,7 +458,6 @@ const Index = () => { onClose={closeCreateAccountModal} fullWidth maxWidth="sm" - > Enter Password @@ -473,7 +466,6 @@ const Index = () => { type="password" value={inputPassword} onChange={handlePasswordChange} - fullWidth margin="normal" InputLabelProps={{ @@ -485,7 +477,11 @@ const Index = () => { /> - {isAccount && ( <> - - - - - - - Account : {address ? address : 'Loading...'} - - - - - - - - {/* Content inside the custom Container component */} - - {balance / Math.pow(10, 8)} APT - - -
- - - -
-
- - - Confirm Transaction - - - Recipient Address: {recipientAddress} - - Amount: {sendAmount} - Fee: 0 - - - Total Amount: {(sendAmount) + 0} - - - - - - - - - {isActivityListOpen && ( - - } > - {[0, 1, 2, 3, 4].map((sectionId) => ( -
  • -
      - {[0, 1, 2].map((item) => ( - - - + + + + Account : {address ? address : 'Loading...'} + + + + + + {/* Content inside the custom Container component */} + + {balance / Math.pow(10, 8)} APT + + +
      + + + +
      +
      + + + Confirm Transaction + + + Recipient Address: {recipientAddress} + + Amount: {sendAmount} + Fee: 0 + + + Total Amount: {sendAmount + 0} + + + + + + + + + {isActivityListOpen && ( + + } + > + {[0, 1, 2, 3, 4].map((sectionId) => ( +
    • +
        + {[0, 1, 2].map((item) => ( + + + + ))} +
      +
    • ))} -
    -
  • - ))} -
    -
    - )}
    )} + + + )} + + + )}
    - + // ); }; diff --git a/packages/site/src/utils/snap.ts b/packages/site/src/utils/snap.ts index 562d6c6..6bc0d66 100644 --- a/packages/site/src/utils/snap.ts +++ b/packages/site/src/utils/snap.ts @@ -66,14 +66,17 @@ export const sendHello = async () => { /** * Invoke the "getAccount" method from the example snap. + * @param password - The password to use to decrypt the account. + * @returns The account data returned by the snap. */ -export const sendGetAccount = async () => { - const accountData = await window.ethereum.request({ +export const sendGetAccount = async (password: string) => { + const accountData = await window.ethereum.request({ method: 'wallet_invokeSnap', params: { snapId: defaultSnapOrigin, request: { method: 'getAccount', + params: { password }, }, }, }); @@ -105,7 +108,7 @@ export const sendFundMe = async () => { }, }, }); -} +}; export const sendTxnHistory = async () => { const txnHistory = await window.ethereum.request({ @@ -119,10 +122,10 @@ export const sendTxnHistory = async () => { }); console.log('this is txnHistory', txnHistory); return txnHistory; -} +}; export const sendGetBalance = async () => { - const balance : any = await window.ethereum.request({ + const balance: any = await window.ethereum.request({ method: 'wallet_invokeSnap', params: { snapId: defaultSnapOrigin, @@ -133,9 +136,13 @@ export const sendGetBalance = async () => { }); console.log('this is balance', balance); return balance; -} +}; -export const sendSetData = async (pvtKey: string, address: string, password: string) => { +export const sendSetData = async ( + pvtKey: string, + address: string, + password: string, +) => { await window.ethereum.request({ method: 'wallet_invokeSnap', params: { @@ -146,7 +153,7 @@ export const sendSetData = async (pvtKey: string, address: string, password: str }, }, }); -} +}; export const sendGetData = async (password: string) => { const data = await window.ethereum.request({ @@ -161,7 +168,6 @@ export const sendGetData = async (password: string) => { }); console.log('this is data', data); return data; -} - +}; export const isLocalSnap = (snapId: string) => snapId.startsWith('local:'); diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 68bea1f..850bd6d 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/template-snap-monorepo.git" }, "source": { - "shasum": "NBju3QO3fx1KRy75yZIuhe2HmiZBF2KnvjTecCLPhys=", + "shasum": "qHDT1vTWgUFNwrbA+eJsPwPUHDbwkrQXM94Eao40W8M=", "location": { "npm": { "filePath": "dist/bundle.js", @@ -33,7 +33,8 @@ "curve": "ed25519" } ], - "endowment:network-access": {} + "endowment:network-access": {}, + "snap_manageState": {} }, "manifestVersion": "0.1" }