Skip to content

Commit

Permalink
Merge pull request #296 from Outblock/232-feature-decode-evm-transact…
Browse files Browse the repository at this point in the history
…ion-call-data-for-user-readability

232 feature decode evm transaction call data for user readability
  • Loading branch information
zzggo authored Dec 18, 2024
2 parents d5f4164 + ba4b9fd commit 44904bd
Show file tree
Hide file tree
Showing 12 changed files with 782 additions and 915 deletions.
25 changes: 5 additions & 20 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,17 +1075,6 @@ export class WalletController extends BaseController {
return result;
}

private async getFixedTokenPrice(symbol: string): Promise<any> {
if (symbol === 'usdc') {
return await openapiService.getUSDCPrice();
} else if (symbol === 'fusd') {
return Promise.resolve({
price: { last: '1.0', change: { percentage: '0.0' } },
});
}
return null;
}

private async calculateTokenPrice(token: string, price: string | null): Promise<any> {
if (price) {
return { price: { last: price, change: { percentage: '0.0' } } };
Expand All @@ -1109,9 +1098,6 @@ export class WalletController extends BaseController {
return this.getFlowTokenPrice(flowPrice);
}

const fixedTokenPrice = await this.getFixedTokenPrice(token);
if (fixedTokenPrice) return fixedTokenPrice;

return this.calculateTokenPrice(token, price);
}

Expand All @@ -1124,9 +1110,6 @@ export class WalletController extends BaseController {
return this.getFlowTokenPrice(flowPrice);
}

const fixedTokenPrice = await this.getFixedTokenPrice(token);
if (fixedTokenPrice) return fixedTokenPrice;

return this.calculateTokenPrice(token, price);
}

Expand Down Expand Up @@ -1963,10 +1946,8 @@ export class WalletController extends BaseController {
return await userWalletService.sendTransaction(script, [fcl.arg(formattedAmount, t.UFix64)]);
};

coaLink = async (amount = '1.0'): Promise<string> => {
coaLink = async (): Promise<string> => {
await this.getNetwork();
// TODO: This doesn't seem to be used anywhere
const formattedAmount = parseFloat(amount).toFixed(8);

const script = await getScripts('evm', 'coaLink');

Expand Down Expand Up @@ -4114,6 +4095,10 @@ export class WalletController extends BaseController {
trackTime = async (eventName: keyof TrackingEvents) => {
mixpanelTrack.time(eventName);
};

decodeEvmCall = async (callData: string, address = '') => {
return await openapiService.decodeEvmCall(callData, address);
};
}

export default new WalletController();
9 changes: 9 additions & 0 deletions src/background/service/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,15 @@ class OpenApiService {
return data;
};

decodeEvmCall = async (data: string, address = '') => {
const bodyData = {
to: address, // address -- optional
data: data, // calldata -- required
};
const res = await this.sendRequest('POST', `/api/evm/decodeData`, {}, bodyData, WEB_NEXT_URL);
return res;
};

EvmNFTcollectionList = async (
address: string,
collectionIdentifier: string,
Expand Down
10 changes: 10 additions & 0 deletions src/ui/FRWAssets/svg/transactionFeeIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
212 changes: 212 additions & 0 deletions src/ui/FRWComponent/Approval/SignHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import { Box, CardMedia, Typography } from '@mui/material';
import Avatar from '@mui/material/Avatar';
import { makeStyles } from '@mui/styles';
import React, { useState, useEffect } from 'react';
import { useHistory } from 'react-router-dom';

import IconCheck from 'ui/assets/check.svg';
import { LLPrimaryButton } from 'ui/FRWComponent';

const useStyles = makeStyles({
IconCheck: {
display: 'inline',
backgroundColor: '#00E075',
borderRadius: '20px',
width: '24px',
height: '24px',
padding: '3px',
color: '#000',
},
});

export const SignHeader = ({ linkingDone, image, accountTitle, userInfo }) => {
const history = useHistory();
const classes = useStyles();
const [count, setCount] = useState(0);
const colorArray = [
'rgba(94,94,94,0.3)',
'rgba(94,94,94,0.4)',
'rgba(94,94,94,0.5)',
'rgba(94,94,94,0.6)',
'rgba(94,94,94,0.7)',
'rgba(94,94,94,0.8)',
'rgba(94,94,94,0.9)',
];

const startCount = () => {
let count = 0;
setInterval(() => {
count++;
if (count === 15) {
count = 0;
}
setCount(count);
}, 500);
};

const startUsing = () => {
setTimeout(() => {
history.replace('/');
});
};

useEffect(() => {
startCount();
}, []);

return (
<div className="page">
<Box sx={{ paddingX: '18px' }}>
<Box
sx={{
marginTop: '18px',
padding: '65px 30px',
display: 'flex',
flexDirection: 'column',
borderRadius: '12px',
height: '100%',
width: '100%',
background: 'linear-gradient(0deg, #32484C, #11271D)',
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: '1fr 1.5 1fr 1fr',
gridAutoFlow: 'column',
justifyContent: 'center',
alignItems: 'stretch',
py: '16px',
gap: '36px',
marginBottom: '45px',
}}
>
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<img
style={{
height: '60px',
width: '60px',
borderRadius: '30px',
backgroundColor: 'text.secondary',
objectFit: 'cover',
}}
src={image}
/>
<Typography
sx={{
fontSize: '14px',
color: '#f2f2f2',
marginTop: '10px',
width: '100%',
textAlign: 'center',
}}
>
{accountTitle}
</Typography>
</Box>
<Box
sx={{
marginLeft: '-15px',
marginRight: '-15px',
marginTop: '0px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
{colorArray.map((color, index) => (
<Box sx={{ mx: '5px' }} key={index}>
{count === index ? (
<Box
sx={{
width: '10px',
height: '10px',
borderRadius: '10px',
backgroundColor: '#41CC5D',
}}
/>
) : (
<Box
key={index}
sx={{
height: '5px',
width: '5px',
borderRadius: '5px',
backgroundColor: color,
}}
/>
)}
</Box>
))}
</Box>
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
{userInfo && (
<img
style={{
height: '60px',
width: '60px',
borderRadius: '30px',
backgroundColor: 'text.secondary',
objectFit: 'cover',
}}
src={userInfo.avatar}
/>
)}
<Typography
sx={{
fontSize: '14px',
color: '#f2f2f2',
marginTop: '10px',
width: '100%',
textAlign: 'center',
}}
>
{userInfo?.nickname}
</Typography>
</Box>
</Box>
{/* <Typography variant="body1" color="text.secondary">{chrome.i18n.getMessage('Lo')}</Typography> */}
{linkingDone ? (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
marginBottom: '100px',
}}
>
<img className={classes.IconCheck} src={IconCheck} />
<Typography
sx={{
fontSize: '16px',
marginTop: '7px',
color: '#E6E6E6',
fontWeight: 'bold',
width: '100%',
textAlign: 'center',
}}
>
{chrome.i18n.getMessage('Linked_Successful')}
</Typography>
</Box>
) : (
<Typography
sx={{
fontSize: '16px',
color: '#E6E6E6',
fontWeight: 'bold',
width: '100%',
textAlign: 'center',
}}
>
{chrome.i18n.getMessage('Linking_Child_Account')}...
</Typography>
)}
{linkingDone && (
<LLPrimaryButton onClick={startUsing} label="Start use" fullWidth type="submit" />
)}
</Box>
</Box>
</div>
);
};
1 change: 1 addition & 0 deletions src/ui/FRWComponent/Approval/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './SignHeader';
29 changes: 29 additions & 0 deletions src/ui/FRWComponent/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { styled, Button, Tooltip } from '@mui/material';
import React from 'react';

import IconCopy from '../../components/iconfont/IconCopy';

const CopyIconWrapper = styled('div')(() => ({
cursor: 'pointer',
}));

interface CopyButtonProps {
textToCopy: string;
}

export const CopyButton = ({ textToCopy }: CopyButtonProps) => {
return (
<CopyIconWrapper>
<Tooltip title={chrome.i18n.getMessage('Copy__Address')} arrow>
<Button
onClick={() => {
navigator.clipboard.writeText(textToCopy);
}}
sx={{ maxWidth: '30px', minWidth: '30px' }}
>
<IconCopy fill="icon.navi" width="16px" />
</Button>
</Tooltip>
</CopyIconWrapper>
);
};
1 change: 1 addition & 0 deletions src/ui/FRWComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './FWDropDownProfile';
export * from './FWMoveDropdown';
export * from './LLContactEth';
export * from './FRWTargetProfile';
export * from './CopyButton';
Loading

0 comments on commit 44904bd

Please sign in to comment.