Skip to content

Commit

Permalink
Merge pull request #54 from valory-xyz/mohan/prohibeted-addresses-cou…
Browse files Browse the repository at this point in the history
…ntries-1

feat: update functions for prohibited addresses & countries
  • Loading branch information
mohandast52 authored Oct 24, 2023
2 parents ccc29ea + 83ced5c commit 9ba6538
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 39 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,7 @@

## 0.4.16
- Functions to prohibit user from prohibited countries & addresses

## 0.4.17
- Update the functions to prohibit user from prohibited countries & addresses
- Export the JSON files for prohibited countries & addresses
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The following table shows which versions of `autonolas-frontend-library` are cur

| Version | Supported |
| --------- | ------------------ |
| `0.4.16` | :white_check_mark: |
| `0.4.17` | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autonolas/frontend-library",
"version": "0.4.16",
"version": "0.4.17",
"description": "Codebase to common style, components, settings, etc.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/components/product/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// list of tiny reusable components

import React from 'react';

export const CannotConnectAddressOfacError = () => (
<>
Cannot connect – address is on&nbsp;
<a
rel="noreferrer"
href="https://www.treasury.gov/ofac/downloads/sdnlist.pdf"
target="_blank"
>
OFAC SDN list
</a>
</>
);
1 change: 1 addition & 0 deletions src/components/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './Footer';
export * from './ServiceStatusInfo';
export * from './Loader';
export * from './GlobalStyles';
export * from './components';
42 changes: 5 additions & 37 deletions src/functions/prohibitedCountriesAndAddresses/index.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
import React from 'react';
import { toLower } from 'lodash';
import prohibitedAddresses from './prohibited-addresses.json';
import prohibitedCountries from './prohibited-countries.json';
import { notifyError } from '../functions';

/**
* Check if the address is prohibited
*/
export const isAddressProhibited = (address: string | null) => {
if (!address) return false;

const addresses = prohibitedAddresses.map((e) => toLower(e));
return addresses.includes(toLower(address));
};

/**
* Check if the country is prohibited
*/
export const isCountryProhibited = (country: string | null) => {
if (!country) return false;

const prohibitedCountriesCode = Object.values(prohibitedCountries);
return prohibitedCountriesCode.includes(country);
};

export const notifyProhibitedAddressError = () => {
return notifyError(
<>
Cannot connect – address is on&nbsp;
<a
rel="noreferrer"
href="https://www.treasury.gov/ofac/downloads/sdnlist.pdf"
target="_blank"
>
OFAC SDN list
</a>
</>,
);
};
export {
isAddressProhibited,
isCountryProhibited,
} from './prohibitedCountriesAndAddresses';
export { prohibitedAddresses, prohibitedCountries };
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { toLower } from 'lodash';
import prohibitedAddresses from './prohibited-addresses.json';
import prohibitedCountries from './prohibited-countries.json';

/**
* Check if the address is prohibited
*/
export const isAddressProhibited = (address: string | null) => {
if (!address) return false;

const addresses = prohibitedAddresses.map((e) => toLower(e));
return addresses.includes(toLower(address));
};

/**
* Check if the country is prohibited
*/
export const isCountryProhibited = (country: string | null) => {
if (!country) return false;

const prohibitedCountriesCode = Object.values(prohibitedCountries);
return prohibitedCountriesCode.includes(country);
};

0 comments on commit 9ba6538

Please sign in to comment.