Skip to content

Commit

Permalink
Fix bug domain not shown on signature (#6464)
Browse files Browse the repository at this point in the history
* Make sure origin is shown on SignatureRequest

Signed-off-by: Olusegun Akintayo <[email protected]>

* if asset is undefined, show balance of selected account.

Signed-off-by: Olusegun Akintayo <[email protected]>

* update snapshot

Signed-off-by: Olusegun Akintayo <[email protected]>

* lint fix

Signed-off-by: Olusegun Akintayo <[email protected]>

* Test get balance if address is null

Signed-off-by: Olusegun Akintayo <[email protected]>

* test show origin header

Signed-off-by: Olusegun Akintayo <[email protected]>

* Lint fixes

Signed-off-by: Olusegun Akintayo <[email protected]>

* Podfile fix

Signed-off-by: Olusegun Akintayo <[email protected]>

* Fix PR comment: Combine the ifs

Signed-off-by: Olusegun Akintayo <[email protected]>

---------

Signed-off-by: Olusegun Akintayo <[email protected]>
  • Loading branch information
segun authored Jun 7, 2023
1 parent a3853ef commit 6f92be9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
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
12 changes: 12 additions & 0 deletions app/components/hooks/useAddressBalance/useAddressBalance.test.tsx
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) {
const { address: rawAddress, symbol = 'ERC20', decimals } = asset;
const contractAddress = safeToChecksumAddress(rawAddress);
Expand Down

0 comments on commit 6f92be9

Please sign in to comment.