Skip to content

Commit

Permalink
fixed txnHistory bug
Browse files Browse the repository at this point in the history
Signed-off-by: aritroCoder <[email protected]>
  • Loading branch information
aritroCoder committed Dec 11, 2023
1 parent 0c67f45 commit d813a49
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 74 deletions.
137 changes: 75 additions & 62 deletions packages/site/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ import {
LoginAccountButton,
CreateAccountButton,
SnapLogo,
CopyToClipboardButton
CopyToClipboardButton,
} from '../components';
import SendIcon from '@mui/icons-material/Send';
import { SHA256 } from 'crypto-js';
import {Network} from '../components';
import { Network } from '../components';

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -418,7 +418,7 @@ const Index = () => {
const handleCoinTransfer = async () => {
closeSendModal();
try {
await sendCoin(recipientAddress, sendAmount , selectedNetwork);
await sendCoin(recipientAddress, sendAmount, selectedNetwork);
const updatedBalance = await sendGetBalance(selectedNetwork);
setBalance(updatedBalance);
} catch (error) {
Expand Down Expand Up @@ -447,10 +447,6 @@ const Index = () => {
const getTxn = await sendTxnHistory(selectedNetwork);
setTxnHistory(getTxn.txnHistory);
toggleOpen();
if (!txncCronJobActive) {
transactionCronJob();
setTxnCronJobActive(true);
}
} catch (error) {
console.error(error);
dispatch({ type: MetamaskActions.SetError, payload: error });
Expand All @@ -470,13 +466,12 @@ const Index = () => {
setAnchorEl(null);
};

const handleNetworkSelect = async (network) => {
const handleNetworkSelect = async (network: string) => {
setSelectedNetwork(network);
handleDropdownClose();
if(network === 'mainnet'){
if (network === 'mainnet') {
setIsMainnet(true);
}
else{
} else {
setIsMainnet(false);
const updatedBalance = await sendGetBalance(network);
setBalance(updatedBalance);
Expand Down Expand Up @@ -634,7 +629,7 @@ const Index = () => {
justifyContent: 'flex-start',
alignItems: 'center',
position: 'relative',
width:'50%',
width: '50%',
}}
>
{' '}
Expand All @@ -645,10 +640,10 @@ const Index = () => {
alignItems: 'center',
justifyContent: 'space-between',
padding: '10px 0px',
background:'#F2F2F2',
background: '#F2F2F2',
boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.25)',
borderRadius: '15px 15px 0px 0px',
width:'100%',
width: '100%',
}}
>
<div
Expand Down Expand Up @@ -751,15 +746,21 @@ const Index = () => {
</AccountModalContent>
</AccountInfoBox>
<Typography
variant="h3"
gutterBottom
style={{ textAlign: 'center' }}
>
{isMainet? 0 : balance / Math.pow(10, 8)} APT
</Typography>
variant="h3"
gutterBottom
style={{ textAlign: 'center' }}
>
{isMainet ? 0 : balance / Math.pow(10, 8)} APT
</Typography>

<HorizontalButtonContainer>
<div style={{ display: 'flex', justifyContent:'space-evenly', width:'100%',}}>
<div
style={{
display: 'flex',
justifyContent: 'space-evenly',
width: '100%',
}}
>
<Button
variant="contained"
onClick={openSendModal}
Expand All @@ -780,30 +781,32 @@ const Index = () => {
<SendIcon style={{ marginRight: '5px' }} />
SEND
</Button>
{!isMainet && <Button
variant="contained"
onClick={handleFundMeWithFaucet}
style={{
width: '105px',
height: '32px',
borderRadius: '10px',
font: 'Roboto',
fontSize: '12px',
fontWeight: '400',
lineHeight: '18px',
letterSpacing: '0em',
textAlign: 'left',
background: '#2F81FC',
color: 'white',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '0',
}}
>
<Faucet style={{ fill: 'white', marginRight: '5px' }} />
FAUCET
</Button>}
{!isMainet && (
<Button
variant="contained"
onClick={handleFundMeWithFaucet}
style={{
width: '105px',
height: '32px',
borderRadius: '10px',
font: 'Roboto',
fontSize: '12px',
fontWeight: '400',
lineHeight: '18px',
letterSpacing: '0em',
textAlign: 'left',
background: '#2F81FC',
color: 'white',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
padding: '0',
}}
>
<Faucet style={{ fill: 'white', marginRight: '5px' }} />
FAUCET
</Button>
)}
<Button
variant="contained"
onClick={handleGetAllTransactions}
Expand Down Expand Up @@ -831,15 +834,25 @@ const Index = () => {
</Button>
</div>
{!open && (
<p style={{color: '#7F7F7F', fontSize: '1.4rem', fontFamily: 'Roboto', fontWeight: '400', wordWrap: 'break-word'}}>Click on transaction history to view all transactions.</p>
<p
style={{
color: '#7F7F7F',
fontSize: '1.4rem',
fontFamily: 'Roboto',
fontWeight: '400',
wordWrap: 'break-word',
}}
>
Click on transaction history to view all transactions.
</p>
)}
{open && txnHistory.length > 0 && (
<div
style={{
overflowX: 'auto',
overflowY: 'scroll',
maxHeight: '480px',
width:'100%',
width: '100%',
}}
>
<TableContainer component={Paper}>
Expand Down Expand Up @@ -881,21 +894,21 @@ const Index = () => {
{milliToDate(txn.timestamp)}
</TableCell>
<TableCell>
<OpenInNewIcon
style={{
width: '20px',
height: '20px',
color: '#434343',
marginRight: '10px',
cursor: 'pointer',
}}
onClick={() => {
window.open(
`https://explorer.aptoslabs.com/txn/${txn.hash}?network=${selectedNetwork}`,
'_blank',
);
}}
/>
<OpenInNewIcon
style={{
width: '20px',
height: '20px',
color: '#434343',
marginRight: '10px',
cursor: 'pointer',
}}
onClick={() => {
window.open(
`https://explorer.aptoslabs.com/txn/${txn.hash}?network=${selectedNetwork}`,
'_blank',
);
}}
/>
</TableCell>
</TableRow>
))}
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/utils/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const sendGetBalance = async (network:string) => {
},
},
});
console.log('this is balance', balance);
console.log('this is balance', balance, " network: ", network);
return balance.balance;
};

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": "9g3sncuyfoE35ArTf2gpVpSI5ZarCRXNfOfcBBES7PE=",
"shasum": "8fmWtK9q5KxO5e323+7aa7DHOH6iVSuvI8zpafDP5qo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
29 changes: 19 additions & 10 deletions packages/snap/src/utils/aptos/GetBal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ import getAccount from './GetAccount';
const HOST = 'http://localhost:5500';

export async function getBal(network: string) {
const account = await getAccount();
const networkType = network.toUpperCase();
const balance = await fetch(`${HOST}/getBalance`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ address: account.accountAddress.toString(), network: networkType }),
}).then((res) => res.json());
const account = await getAccount();
const networkType = network.toUpperCase();
const balance = await fetch(`${HOST}/getBalance`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
address: account.accountAddress.toString(),
network: networkType,
}),
}).then((res) => res.json());
if (balance) {
console.log({ balance });
if ('amount' in balance[0]) {
const bal = balance[0].amount;
console.log('this is bal', bal);
return bal;
}
}
}
return 0;
}
2 changes: 2 additions & 0 deletions server/src/CheckBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default async function checkBalance(request:Request) {
const aptos = new Aptos(aptosConfig);
const accountCoinsData: GetAccountCoinsDataResponse = await aptos.getAccountCoinsData({accountAddress: request.address});
console.log('this is accountCoinsData', accountCoinsData);
console.log({requestBody})
console.log('network: ', networkType)

return accountCoinsData;

Expand Down

0 comments on commit d813a49

Please sign in to comment.