Skip to content

Commit

Permalink
Merge branch 'develop' into MMPD-1296
Browse files Browse the repository at this point in the history
  • Loading branch information
julesat22 authored Sep 12, 2024
2 parents 8b9e3c6 + c7f4f43 commit 28c4fa9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ui/components/app/currency-input/currency-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default function CurrencyInput({
isSkeleton,
isMatchingUpstream,
}) {
const assetDecimals = Number(asset?.decimals) || NATIVE_CURRENCY_DECIMALS;
const assetDecimals = isNaN(Number(asset?.decimals))
? NATIVE_CURRENCY_DECIMALS
: Number(asset?.decimals);

const preferredCurrency = useSelector(getNativeCurrency);
const secondaryCurrency = useSelector(getCurrentCurrency);
Expand Down
5 changes: 3 additions & 2 deletions ui/components/app/modals/qr-scanner/qr-scanner.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Spinner from '../../../ui/spinner';

import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../../shared/constants/app';
import { SECOND } from '../../../../../shared/constants/time';
import { parseScanContent } from './scan-util';

const READY_STATE = {
ACCESSING_CAMERA: 'ACCESSING_CAMERA',
Expand All @@ -30,8 +31,8 @@ const parseContent = (content) => {
// Ethereum address links - fox ex. ethereum:0x.....1111
if (content.split('ethereum:').length > 1) {
type = 'address';
values = { address: content.split('ethereum:')[1] };

// uses regex capture groups to match and extract address while ignoring everything else
values = { address: parseScanContent(content) };
// Regular ethereum addresses - fox ex. 0x.....1111
} else if (content.substring(0, 2).toLowerCase() === '0x') {
type = 'address';
Expand Down
24 changes: 24 additions & 0 deletions ui/components/app/modals/qr-scanner/qr-scanner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { parseScanContent } from './scan-util';

describe('Extract Address from string', () => {
it('should correctly extract the address from the string', () => {
const result = parseScanContent(
'ethereum:0xCf464B40cb2419944138F24514C9aE4D1889ccC1',
);
expect(result).toStrictEqual('0xCf464B40cb2419944138F24514C9aE4D1889ccC1');
});

it('should correctly extract the address from the string when there is a 0x appended', () => {
const result = parseScanContent(
'ethereum:0xCf464B40cb2419944138F24514C9aE4D1889ccC1@0x1',
);
expect(result).toStrictEqual('0xCf464B40cb2419944138F24514C9aE4D1889ccC1');
});

it('should return null if there is no address to extract that matches the pattern', () => {
const result = parseScanContent(
'ethereum:0xCf464B40cb2419944138F24514C9aE4D1',
);
expect(result).toStrictEqual(null);
});
});
7 changes: 7 additions & 0 deletions ui/components/app/modals/qr-scanner/scan-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function parseScanContent(content: string): string | null {
const matches = content.match(/^[a-zA-Z]+:(0x[0-9a-fA-F]{40})(?:@.*)?/u);
if (!matches) {
return null;
}
return matches[1];
}

0 comments on commit 28c4fa9

Please sign in to comment.