-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3627b3f
commit 5c0b864
Showing
9 changed files
with
115 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ REACT_APP_SENTRY_DSN=https://[email protected] | |
REACT_APP_PORTIS_ID=469a25c8-1101-4c57-823d-c47cb328f788 | ||
|
||
REACT_APP_WHITELIST=true | ||
REACT_APP_WHITELIST_TOKEN=0x857a62c9c0b6f1211e04275a1f0c5f26fce2021f | ||
|
||
REACT_APP_YBUG_ID=3f1jrxvzrhkn1b975t8b | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { currentChainId, backendUrl, ethGenesisAddress } from './classifiers'; | ||
import { contractReader } from './sovryn/contract-reader'; | ||
|
||
const sovLimit = 100; | ||
|
||
class Whitelist { | ||
public async test(address: string) { | ||
try { | ||
return await this.getApi(address); | ||
} catch (e) { | ||
return await this.getContracts(address); | ||
} | ||
} | ||
|
||
// Check if user is whitelisted using backend server | ||
public async getApi(address: string) { | ||
const controller = new AbortController(); | ||
// abort request if it's not resolved in 30 seconds and start checking in smart-contract from frontend side. | ||
const timeoutId = setTimeout(() => controller.abort(), 30e3); | ||
return fetch(`${backendUrl[currentChainId]}/whitelist/${address}`, { | ||
method: 'GET', | ||
headers: { | ||
accept: 'application/json', | ||
}, | ||
signal: controller.signal, | ||
}) | ||
.then(response => { | ||
clearTimeout(timeoutId); | ||
return response.json(); | ||
}) | ||
.then(({ whitelisted }) => whitelisted); | ||
} | ||
|
||
// Check if user is whitelisted using smart-contracts | ||
public async getContracts(address: string) { | ||
address = address.toLowerCase(); | ||
|
||
const sov = await contractReader | ||
.call('SOV_token', 'balanceOf', [address]) | ||
.then(e => Number(e) / 1e18); | ||
if (sov >= sovLimit) return true; | ||
|
||
const csov1 = await contractReader | ||
.call('CSOV_token', 'balanceOf', [address]) | ||
.then(e => Number(e) / 1e18); | ||
if (csov1 >= sovLimit) return true; | ||
|
||
const csov2 = await contractReader | ||
.call('CSOV2_token', 'balanceOf', [address]) | ||
.then(e => Number(e) / 1e18); | ||
if (csov2 >= sovLimit) return true; | ||
|
||
const staked = await contractReader | ||
.call('staking', 'balanceOf', [address]) | ||
.then(e => Number(e) / 1e18); | ||
if (staked >= sovLimit) return true; | ||
|
||
const vesting1 = await contractReader.call( | ||
'vestingRegistry', | ||
'getVesting', | ||
[address], | ||
); | ||
if (vesting1 !== ethGenesisAddress) { | ||
const staked = await contractReader | ||
.call('staking', 'balanceOf', [vesting1]) | ||
.then(e => Number(e) / 1e18); | ||
if (staked >= sovLimit) return true; | ||
} | ||
|
||
const vesting2 = await contractReader.call( | ||
'vestingRegistry', | ||
'getTeamVesting', | ||
[address], | ||
); | ||
if (vesting2 !== ethGenesisAddress) { | ||
const staked = await contractReader | ||
.call('staking', 'balanceOf', [vesting2]) | ||
.then(e => Number(e) / 1e18); | ||
if (staked >= sovLimit) return true; | ||
} | ||
|
||
// todo enable it after new vesting registry is available | ||
// const vesting3 = await contractReader.call( | ||
// 'vestingRegistry2', | ||
// 'getTeamVesting', | ||
// [address], | ||
// ); | ||
// if (vesting3 !== ethGenesisAddress) { | ||
// const staked = await contractReader | ||
// .call('staking', 'balanceOf', [vesting3]) | ||
// .then(e => Number(e) / 1e18); | ||
// if (staked >= sovLimit) return true; | ||
// } | ||
|
||
return false; | ||
} | ||
} | ||
|
||
export const whitelist = new Whitelist(); |
5c0b864
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: