@rainbow-me/rainbow-common
Advanced tools
Comparing version 0.8.0 to 0.8.1
{ | ||
"name": "@rainbow-me/rainbow-common", | ||
"description": "Common library for web and mobile", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"author": "Jin Chung <jin@rainbow.me>", | ||
@@ -6,0 +6,0 @@ "license": "GPL-3.0", |
@@ -8,4 +8,4 @@ import '@babel/polyfill'; | ||
const address = '0x1492004547FF0eFd778CC2c14E794B26B4701105'; | ||
let result = await apiGetTransactionData(address, 1); | ||
let result = await apiGetTransactionData(address, 'mainnet', 1); | ||
expect(result.data.total).toBe(1); | ||
}); |
import '@babel/polyfill'; | ||
import { isValidAddress } from '../validators' | ||
import { isENSAddressFormat, isValidAddress } from '../validators' | ||
test('isENSAddressFormat', async () => { | ||
const address = 'hello.eth'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeTruthy(); | ||
}); | ||
test('isENSAddressFormat2', async () => { | ||
const address = 'a.b'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeTruthy(); | ||
}); | ||
test('isENSAddressFormat3', async () => { | ||
const address = 'a.'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeFalsy(); | ||
}); | ||
test('isENSAddressFormat4', async () => { | ||
const address = '123.456'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeTruthy(); | ||
}); | ||
test('isENSAddressFormat5', async () => { | ||
const address = '123.456.678'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeTruthy(); | ||
}); | ||
test('isENSAddressFormat6', async () => { | ||
const address = '12-.%56.*78'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeTruthy(); | ||
}); | ||
test('isENSAddressFormat7', async () => { | ||
const address = '.'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeFalsy(); | ||
}); | ||
test('isENSAddressFormat8', async () => { | ||
const address = '.b'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeFalsy(); | ||
}); | ||
test('isENSAddressFormat9', async () => { | ||
const address = 'abc'; | ||
const result = await isENSAddressFormat(address); | ||
expect(result).toBeFalsy(); | ||
}); | ||
test('isValidAddress', async () => { | ||
const result = await isValidAddress('0x1492004547FF0eFd778CC2c14E794B26B4701105'); | ||
expect(result).toBe(true); | ||
expect(result).toBeTruthy(); | ||
}); | ||
@@ -11,3 +65,3 @@ | ||
const result = await isValidAddress('0x1492004547fF0efd778CC2c14E794B26B4701105'); | ||
expect(result).toBe(false); | ||
expect(result).toBeFalsy(); | ||
}); | ||
@@ -17,3 +71,3 @@ | ||
const result = await isValidAddress('0x1492004547FF0EFD778CC2C14E794B26B4701105'); | ||
expect(result).toBe(true); | ||
expect(result).toBeTruthy(); | ||
}); | ||
@@ -23,3 +77,3 @@ | ||
const result = await isValidAddress('0x1492004547ff0efd778cc2c14e794b26b4701105'); | ||
expect(result).toBe(true); | ||
expect(result).toBeTruthy(); | ||
}); | ||
@@ -29,3 +83,3 @@ | ||
const result = await isValidAddress('0x0000000000000000000000000000000000000000'); | ||
expect(result).toBe(true); | ||
expect(result).toBeTruthy(); | ||
}); | ||
@@ -35,3 +89,3 @@ | ||
const result = await isValidAddress('jinrummie.eth'); | ||
expect(result).toBe(true); | ||
expect(result).toBeTruthy(); | ||
}); | ||
@@ -41,3 +95,3 @@ | ||
const result = await isValidAddress('vitalik.eth'); | ||
expect(result).toBe(false); | ||
expect(result).toBeFalsy(); | ||
}); | ||
@@ -47,3 +101,3 @@ | ||
const result = await isValidAddress('123.eth'); | ||
expect(result).toBe(false); | ||
expect(result).toBeFalsy(); | ||
}); | ||
@@ -53,3 +107,3 @@ | ||
const result = await isValidAddress('hello'); | ||
expect(result).toBe(false); | ||
expect(result).toBeFalsy(); | ||
}); | ||
@@ -59,3 +113,3 @@ | ||
const result = await isValidAddress('0x1234'); | ||
expect(result).toBe(false); | ||
expect(result).toBeFalsy(); | ||
}); | ||
@@ -65,3 +119,3 @@ | ||
const result = await isValidAddress('818472'); | ||
expect(result).toBe(false); | ||
expect(result).toBeFalsy(); | ||
}); |
@@ -1,3 +0,6 @@ | ||
import { endsWith, startsWith } from 'lodash'; | ||
import { toChecksumAddress, web3Provider } from '../handlers/web3_ethers'; | ||
import { | ||
isHexString, | ||
toChecksumAddress, | ||
web3Provider, | ||
} from '../handlers/web3_ethers'; | ||
@@ -14,2 +17,6 @@ /** | ||
export const isENSAddressFormat = (address) => { | ||
return address.match(/.+\..+/g); | ||
}; | ||
/** | ||
@@ -21,3 +28,3 @@ * @desc validate ethereum address | ||
export const isValidAddress = async (address) => { | ||
if (endsWith(address, '.eth')) { | ||
if (isENSAddressFormat(address)) { | ||
try { | ||
@@ -30,3 +37,3 @@ const resolvedAddress = await web3Provider.resolveName(address); | ||
} | ||
if (!startsWith(address, '0x')) return false; | ||
if (!isHexString(address)) return false; | ||
if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) return false; | ||
@@ -33,0 +40,0 @@ if (/^(0x)?[0-9a-f]{40}$/.test(address) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1253689
10637