Skip to content
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
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/_locales/en_GB/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 23 additions & 11 deletions ui/pages/confirmations/components/send/amount/amount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ describe('Amount', () => {
} as unknown as SendContext.SendContextType);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -86,7 +87,8 @@ describe('Amount', () => {
} as unknown as SendContext.SendContextType);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -110,7 +112,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -121,6 +124,7 @@ describe('Amount', () => {
expect(getByText('$ 20.00')).toBeInTheDocument();
fireEvent.click(getByTestId('toggle-fiat-mode'));
expect(getByRole('textbox')).toHaveValue('20');
expect(getByText('USD')).toBeInTheDocument();
fireEvent.change(getByRole('textbox'), { target: { value: 100 } });
expect(getByText('0 NEU')).toBeInTheDocument();
});
Expand All @@ -136,7 +140,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand Down Expand Up @@ -172,7 +177,8 @@ describe('Amount', () => {
} as unknown as SendContext.SendContextType);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -191,7 +197,8 @@ describe('Amount', () => {
} as unknown as SendContext.SendContextType);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand Down Expand Up @@ -252,7 +259,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -272,7 +280,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: false,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -292,7 +301,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: false,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -315,7 +325,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand All @@ -336,7 +347,8 @@ describe('Amount', () => {
} as unknown as ReturnType<typeof BalanceFunctions.useBalance>);
jest.spyOn(CurrencyConversions, 'useCurrencyConversions').mockReturnValue({
conversionSupportedForAsset: true,
fiatCurrencySymbol: 'USD',
fiatCurrencySymbol: '$',
fiatCurrencyName: 'usd',
getFiatValue: () => '20',
getFiatDisplayValue: () => '$ 20.00',
getNativeValue: () => '20',
Expand Down
5 changes: 4 additions & 1 deletion ui/pages/confirmations/components/send/amount/amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Amount = ({
const [fiatMode, setFiatMode] = useState(false);
const {
conversionSupportedForAsset,
fiatCurrencyName,
getFiatValue,
getFiatDisplayValue,
getNativeValue,
Expand Down Expand Up @@ -154,7 +155,9 @@ export const Amount = ({
value={amount}
endAccessory={
<Box display={Display.Flex}>
<Text>{asset?.symbol}</Text>
<Text>
{fiatMode ? fiatCurrencyName?.toUpperCase() : asset?.symbol}
</Text>
{conversionSupportedForAsset && (
<ButtonIcon
ariaLabel="toggle fiat mode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const useCurrencyConversions = () => {
asset?.standard !== ERC1155 &&
asset?.standard !== ERC721,
fiatCurrencySymbol: getCurrencySymbol(currentCurrency),
fiatCurrencyName: currentCurrency,
getFiatValue,
getFiatDisplayValue,
getNativeValue,
Expand Down
26 changes: 26 additions & 0 deletions ui/pages/confirmations/hooks/send/useMaxAmount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ describe('useMaxAmount', () => {
expect(result.getMaxAmount()).toEqual('999.999570668411440000');
});

it('not throw error if gas fee estimates is not available', () => {
jest.spyOn(SendContext, 'useSendContext').mockReturnValue({
asset: EVM_NATIVE_ASSET,
chainId: '0x5',
from: MOCK_ADDRESS_1,
} as unknown as SendContext.SendContextType);
useBalanceMock.mockReturnValue({
balance: '10.00',
decimals: 18,
rawBalanceNumeric: new Numeric('1000000000000000000000', 10),
});
const result = renderHook({
...mockState,
metamask: {
...mockState.metamask,
gasFeeEstimatesByChainId: {
'0x5': {
gasFeeEstimates: {},
},
},
},
});

expect(result.getMaxAmount()).toEqual('1000');
});

it('return 0 if balance of native asset is less than gas needed', () => {
jest.spyOn(SendContext, 'useSendContext').mockReturnValue({
asset: EVM_NATIVE_ASSET,
Expand Down
5 changes: 2 additions & 3 deletions ui/pages/confirmations/hooks/send/useMaxAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export const getEstimatedTotalGas = (
if (!gasFeeEstimates) {
return new Numeric('0', 10);
}
const {
medium: { suggestedMaxFeePerGas },
} = gasFeeEstimates;
const { medium: { suggestedMaxFeePerGas } = { suggestedMaxFeePerGas: 0 } } =
gasFeeEstimates;
const totalGas = new Numeric(
suggestedMaxFeePerGas * NATIVE_TRANSFER_GAS_LIMIT,
10,
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/confirmations/hooks/send/useNameValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useNameValidation = () => {

if (resolutions.length === 0) {
return {
error: 'ensUnknownError',
error: 'nameResolutionFailedError',
};
}

Expand All @@ -33,7 +33,7 @@ export const useNameValidation = () => {
}

return {
error: 'ensUnknownError',
error: 'nameResolutionFailedError',
};
},
[fetchResolutions],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('useRecipientValidation', () => {
jest.spyOn(NameValidation, 'useNameValidation').mockReturnValue({
validateName: () =>
Promise.resolve({
error: 'ensUnknownError',
error: 'nameResolutionFailedError',
}),
});

Expand Down Expand Up @@ -244,7 +244,7 @@ describe('useRecipientValidation', () => {
jest.spyOn(NameValidation, 'useNameValidation').mockReturnValue({
validateName: () =>
Promise.resolve({
error: 'ensUnknownError',
error: 'nameResolutionFailedError',
}),
});

Expand Down
41 changes: 41 additions & 0 deletions ui/pages/confirmations/hooks/send/useRecipients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,49 @@ describe('useRecipients', () => {
const { result } = renderHookWithProvider(() => useRecipients(), mockState);

expect(result.current).toEqual([
...mockAccountRecipients,
...mockContactRecipients,
]);
});

it('it returns unique recipients', () => {
const mockAccountRecipients: Recipient[] = [
{
address: '0x5678901234',
walletName: 'Wallet 1',
accountGroupName: 'Account 1',
},
{
address: '0xfedcba5678',
walletName: 'Wallet 2',
accountGroupName: 'Account 2',
},
];

const mockContactRecipients: Recipient[] = [
{ address: '0x1234567890', contactName: 'Contact 1' },
{ address: '0xabcdef1234', contactName: 'Contact 2' },
{
address: '0x1234567890',
walletName: 'Wallet 11',
accountGroupName: 'Account 11',
},
{
address: '0x5678901234',
walletName: 'Wallet 12',
accountGroupName: 'Account 12',
},
];

mockUseContactRecipients.mockReturnValue(mockContactRecipients);
mockUseAccountRecipients.mockReturnValue(mockAccountRecipients);

const { result } = renderHookWithProvider(() => useRecipients(), mockState);

expect(result.current).toEqual([
...mockAccountRecipients,
mockContactRecipients[0],
mockContactRecipients[1],
]);
});

Expand Down
16 changes: 14 additions & 2 deletions ui/pages/confirmations/hooks/send/useRecipients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ export type Recipient = {
};

export const useRecipients = (): Recipient[] => {
const contactRecipients = useContactRecipients();
const accountRecipients = useAccountRecipients();
const contactRecipients = useContactRecipients();

const recipients = [...accountRecipients];

contactRecipients.forEach((recipient) => {
if (
!recipients.some(
(r) => r.address.toLowerCase() === recipient.address.toLowerCase(),
)
) {
recipients.push(recipient);
}
});

return [...contactRecipients, ...accountRecipients];
return recipients;
};
Loading