Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug domain not shown on signature #6464

Merged
merged 9 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/components/UI/AccountInfoCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class AccountInfoCard extends PureComponent {
ticker: PropTypes.string,
transaction: PropTypes.object,
activeTabUrl: PropTypes.string,
origin: PropTypes.string,
};

state = {
Expand Down Expand Up @@ -156,6 +157,7 @@ class AccountInfoCard extends PureComponent {
fromAddress: rawFromAddress,
transaction,
activeTabUrl,
origin,
} = this.props;

const fromAddress = safeToChecksumAddress(rawFromAddress);
Expand All @@ -176,7 +178,7 @@ class AccountInfoCard extends PureComponent {
)?.toUpperCase();
return operation === 'signing' && transaction !== undefined ? (
<ApproveTransactionHeader
origin={transaction.origin}
origin={transaction.origin || origin}
url={activeTabUrl}
from={rawFromAddress}
/>
Expand Down
9 changes: 9 additions & 0 deletions app/components/UI/AccountInfoCard/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@ describe('AccountInfoCard', () => {
);
expect(getByText('Balance')).toBeDefined();
});

it('should show origin header in signing page', async () => {
const { getByText } = renderWithProvider(
<AccountInfoCard fromAddress="0x0" operation="signing" />,
{ state: initialState },
);

expect(getByText('https://metamask.io')).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ exports[`ApproveTransactionHeader should return origin to be null when not prese
}
}
>
0
&lt; 0.00001 ETH
</Text>
</View>
</View>
Expand Down
6 changes: 5 additions & 1 deletion app/components/UI/SignatureRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ class SignatureRequest extends PureComponent {
return (
<View style={styles.actionViewChild}>
<View style={styles.accountInfoCardWrapper}>
<AccountInfoCard operation="signing" fromAddress={fromAddress} />
<AccountInfoCard
operation="signing"
fromAddress={fromAddress}
origin={title}
/>
</View>
<TouchableOpacity
style={styles.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ describe('useAddressBalance', () => {
expect(mockGetERC20BalanceOf).toBeCalledTimes(1);
});

it('should render balance if asset is undefined', () => {
let asset: Asset;
let res = renderHook(() => useAddressBalance(asset, '0x0'), {
wrapper: Wrapper,
});
expect(res.result.current.addressBalance).toStrictEqual('5.36385 ETH');
res = renderHook(() => useAddressBalance({ isETH: true } as Asset, '0x1'), {
wrapper: Wrapper,
});
expect(res.result.current.addressBalance).toStrictEqual('< 0.00001 ETH');
});

it('should render balance from TokenBalancesController.contractBalances if selectedAddress is same as fromAddress', () => {
const res = renderHook(
() =>
Expand Down
27 changes: 17 additions & 10 deletions app/components/hooks/useAddressBalance/useAddressBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,32 @@ const useAddressBalance = (asset: Asset, address?: string) => {
}, []);

useEffect(() => {
if (!address || !asset) {
const setBalance = () => {
const parsedTicker = getTicker(ticker);
const checksumAddress = safeToChecksumAddress(address);
if (!checksumAddress) {
return;
}
const fromAccBalance = `${renderFromWei(
accounts[checksumAddress]?.balance,
)} ${parsedTicker}`;
setAddressBalance(fromAccBalance);
};

// on signature request, asset is undefined
if (!address) {
return;
}
let fromAccBalance;

if (
!asset ||
asset.isETH ||
asset.tokenId ||
asset.standard === ERC721 ||
asset.standard === ERC1155
) {
const parsedTicker = getTicker(ticker);
const checksumAddress = safeToChecksumAddress(address);
if (!checksumAddress) {
return;
}
fromAccBalance = `${renderFromWei(
accounts[checksumAddress]?.balance,
)} ${parsedTicker}`;
setAddressBalance(fromAccBalance);
setBalance();
} else if (asset?.decimals !== undefined) {
segun marked this conversation as resolved.
Show resolved Hide resolved
const { address: rawAddress, symbol = 'ERC20', decimals } = asset;
const contractAddress = safeToChecksumAddress(rawAddress);
Expand Down