Search for one country address by .1 domain name (#247)

pull/248/head
Artem 2 years ago committed by GitHub
parent 1156c58ed2
commit 29c47a8226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .env
  2. 2
      .env.example
  3. 3
      package.json
  4. 29
      src/components/ui/Search.tsx
  5. 4
      src/config/index.ts
  6. 12
      src/utils/oneCountry.ts

@ -7,3 +7,4 @@ REACT_APP_EXPLORER_V1_API_URL=https://ctrver.t.hmny.io/
REACT_APP_INDEXER_IPFS_GATEWAY=https://ipfs.io/ipfs/
REACT_APP_PROD_ADDRESS=https://ws.explorer-v2-api.hmny.io
REACT_APP_CONTRACT_SHARD=0
REACT_APP_ONE_COUNTRY_CONTRACT_ADDRESS=0xaef596d26be185d1c25c0aadfab6ab054e7c011f

@ -12,3 +12,5 @@ REACT_APP_INDEXER_IPFS_GATEWAY=https://ipfs.io/ipfs/
# backend websocket API url
REACT_APP_PROD_ADDRESS=https://explorer-v2-api.hmny.io/
REACT_APP_CONTRACT_SHARD=0
# 1.country contract address
REACT_APP_ONE_COUNTRY_CONTRACT_ADDRESS=0xaef596d26be185d1c25c0aadfab6ab054e7c011f

@ -11,6 +11,7 @@
"grommet": "2.17.2",
"grommet-icons": "^4.5.0",
"json-bigint": "^1.0.0",
"one-country-sdk": "^0.2.0",
"react": "^17.0.2",
"react-chartjs-2": "^4.0.1",
"react-dom": "^17.0.2",
@ -58,6 +59,7 @@
"@testing-library/user-event": "^12.1.10",
"@types/big.js": "^6.0.2",
"@types/jest": "^26.0.15",
"@types/json-bigint": "^1.0.1",
"@types/node": "^12.0.0",
"@types/react": "17.0.30",
"@types/react-dom": "^17.0.0",
@ -66,7 +68,6 @@
"@types/react-virtualized-auto-sizer": "^1.0.0",
"@types/react-window": "^1.8.3",
"@types/styled-components": "^5.1.9",
"@types/json-bigint": "^1.0.1",
"js-sha3": "^0.8.0",
"node-fetch": "2",
"prettier": "^2.2.1",

@ -17,6 +17,8 @@ import { FixedSizeList as List } from "react-window";
import AutoSizer from "react-virtualized-auto-sizer";
import { Address } from "./Address";
import { config } from "../../config";
import {getAddressByName} from "../../utils/oneCountry";
import {toaster} from "../../App";
let timeoutID: any | null = null;
@ -94,6 +96,29 @@ export const SearchInput = () => {
return;
}
if(config.oneCountryContractAddress && v.endsWith('.1')) {
const [prefix] = v.split('.1')
if(prefix) {
try {
const address = await getAddressByName(prefix)
if(address) {
history.push(`/address/${address}`);
} else {
toaster.show({
message: () => (
<Box direction={"row"} align={"center"} pad={"small"}>
<Text size={"small"}>Address for "{v}" not found</Text>
</Box>
),
time: 5000
})
}
} catch (e) {
console.log('Cannot get one country address', e)
}
}
}
if (v.length !== 66 && v.length !== 42) {
return;
}
@ -185,7 +210,9 @@ export const SearchInput = () => {
}
};
exec();
if(readySubmit) {
exec();
}
}, [readySubmit]);
const Row = (options: { index: number; style: any }) => {

@ -26,9 +26,11 @@ const shardUrls = availableShards
.filter(url => url)
const contractShardId = +(process.env.REACT_APP_CONTRACT_SHARD || '0') as ShardID
const oneCountryContractAddress = process.env.REACT_APP_ONE_COUNTRY_CONTRACT_ADDRESS || ''
export const config = {
availableShards,
shardUrls,
contractShardId
contractShardId,
oneCountryContractAddress
}

@ -0,0 +1,12 @@
import { OneCountry } from 'one-country-sdk'
import Web3 from "web3";
import { config } from '../config'
const { oneCountryContractAddress, shardUrls } = config
const provider = new Web3.providers.HttpProvider(shardUrls[0] || '')
const oneCountry = new OneCountry({ provider, contractAddress: oneCountryContractAddress })
export const getAddressByName = async (name: string) => {
const record = await oneCountry.getRecordByName(name)
return record ? record.renter : ''
}
Loading…
Cancel
Save