Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rastajpa committed Apr 14, 2023
1 parent 08fc635 commit bba756a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/list/ContactRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const RowContainer = styled.View`
align-items: center;
`;

export type DomainType = 'ens' | 'unstoppable';
export type DomainType = 'ENSDomain' | 'UnstoppableDomain';

export interface ContactRowProps {
address: string;
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/tabs/contacts/components/ContactIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CoinBadge: React.FC<BadgeProps> = ({
return (
<CoinBadgeContainer>
{domainType ? (
domainType === 'ens' ? (
domainType === 'ENSDomain' ? (
<ENSDomainIcon size={size} />
) : (
<UnstoppableDomainIcon size={size} />
Expand Down
55 changes: 32 additions & 23 deletions src/navigation/tabs/contacts/screens/ContactsAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
SearchInput,
Column,
} from '../../../../components/styled/Containers';
import {ValidateCoinAddress} from '../../../../store/wallet/utils/validations';
import {
ValidateCoinAddress,
ValidateURI,
} from '../../../../store/wallet/utils/validations';
import {GetCoinAndNetwork} from '../../../../store/wallet/effects/address/address';
import {
ContactRowProps,
Expand Down Expand Up @@ -396,7 +399,8 @@ const ContactsAdd = ({
}
}
} else {
processDomain({domain: address});
const data = ValidateURI(address);
processDomain({data});
}
} else {
resetValues();
Expand All @@ -405,30 +409,35 @@ const ContactsAdd = ({

const processDomain = useMemo(
() =>
debounce(async ({domain}: {domain: string}) => {
debounce(async ({data}: {data: any}) => {
try {
if (!domain) {
if (!data.data) {
return;
}
const addressByENS = await dispatch(getAddressByENSDomain({domain}));
const addressByUnstoppableDomain = await dispatch(
getAddressByUnstoppableDomain({domain}),
);

if (addressByENS) {
setValidDomain(true);
processAddressOrDomain({
address: addressByENS,
domain,
domainType: 'ens',
});
} else if (addressByUnstoppableDomain) {
setValidDomain(true);
processAddressOrDomain({
address: addressByUnstoppableDomain,
domain,
domainType: 'unstoppable',
});
if (data.type === 'UnstoppableDomain') {
const addressByUnstoppableDomain = await dispatch(
getAddressByUnstoppableDomain({domain: data.data}),
);
if (addressByUnstoppableDomain) {
setValidDomain(true);
processAddressOrDomain({
address: addressByUnstoppableDomain,
domain: data.data,
domainType: data.type,
});
}
} else if (data.type === 'ENSDomain') {
const addressByENS = await dispatch(
getAddressByENSDomain({domain: data.data}),
);
if (addressByENS) {
setValidDomain(true);
processAddressOrDomain({
address: addressByENS,
domain: data.data,
domainType: data.type,
});
}
} else {
resetValues();
}
Expand Down
14 changes: 14 additions & 0 deletions src/store/moralis/moralis.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const UnstoppableDomains = [
'.crypto',
'.nft',
'.x',
'.wallet',
'.polygon',
'.dao',
'.888',
'.zil',
'.blockchain',
'.bitcoin',
];

export const ENSDomains = ['.eth'];
25 changes: 25 additions & 0 deletions src/store/wallet/utils/validations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {BwcProvider} from '../../../lib/bwc';
import {ENSDomains, UnstoppableDomains} from '../../moralis/moralis.constants';
import {ExtractBitPayUriAddress} from './decode-uri';

const BWC = BwcProvider.getInstance();
Expand Down Expand Up @@ -199,6 +200,14 @@ export const CheckIfLegacyBCH = (address: string): boolean => {
);
};

export const IsValidUnstoppableDomain = (domain: string): boolean => {
return UnstoppableDomains.some(item => domain.endsWith(item));
};

export const IsValidENSDomain = (domain: string): boolean => {
return ENSDomains.some(item => domain.endsWith(item));
};

export const ValidateURI = (data: string): any => {
if (!data) {
return;
Expand Down Expand Up @@ -348,6 +357,22 @@ export const ValidateURI = (data: string): any => {
};
}

if (IsValidUnstoppableDomain(data)) {
return {
data,
type: 'UnstoppableDomain',
title: 'Unstoppable Domain',
};
}

if (IsValidENSDomain(data)) {
return {
data,
type: 'ENSDomain',
title: 'ENS Domain',
};
}

return;
};

Expand Down

0 comments on commit bba756a

Please sign in to comment.