Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Lowercasing searched address to find it on chunk file (#2260)
Browse files Browse the repository at this point in the history
* Lowercasing searched address to find it on chunk file

* Updated claims branch to latest

* Removed lowercasing from claim addresses as it's no longer needed

* New Gnosis Chain contract address

* Update contract in GC

Co-authored-by: Leandro <[email protected]>
Co-authored-by: Anxo Rodriguez <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2022
1 parent ca3b4bd commit bb7b1a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/custom/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const GP_VAULT_RELAYER: Partial<Record<number, string>> = {

export const V_COW_CONTRACT_ADDRESS: Partial<Record<number, string>> = {
[ChainId.MAINNET]: '0x6d04B3ad33594978D0D4B01CdB7c3bA4a90a7DFe',
[ChainId.XDAI]: '0x18598a23E830eFBA0061A4d27E511cB5AE6AC43E',
[ChainId.XDAI]: '0xA3A674a40709A837A5E742C2866eda7d3b35a7c0',
[ChainId.RINKEBY]: '0xD7Dd9397Fb942565959c77f8e112ec5aa7D8C92c',
}

Expand Down
16 changes: 10 additions & 6 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
import { EnhancedUserClaimData } from 'pages/Claim/types'
import { supportedChainId } from 'utils/supportedChainId'

const CLAIMS_REPO_BRANCH = 'test-deployment-all-networks'
const CLAIMS_REPO_BRANCH = '2022-01-22-test-deployment-all-networks'
export const CLAIMS_REPO = `https://raw.githubusercontent.com/gnosis/cow-merkle-drop/${CLAIMS_REPO_BRANCH}/`

// Base amount = 1 VCOW
Expand Down Expand Up @@ -714,21 +714,25 @@ const FETCH_CLAIM_PROMISES: { [key: string]: Promise<UserClaims> } = {}
* Returns the claim for the given address, or null if not valid
*/
function fetchClaims(account: string, chainId: number): Promise<UserClaims> {
// Validate it's a, well, valid address
const formatted = isAddress(account)
if (!formatted) return Promise.reject(new Error('Invalid address'))

const claimKey = getClaimKey(formatted, chainId)
// To be sure, let's lowercase the hashed address and work with it instead
const lowerCasedAddress = formatted.toLowerCase()

const claimKey = getClaimKey(lowerCasedAddress, chainId)

return (
FETCH_CLAIM_PROMISES[claimKey] ??
(FETCH_CLAIM_PROMISES[claimKey] = fetchClaimsMapping(chainId)
.then((mapping) => {
const sorted = Object.keys(mapping).sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
const sorted = Object.keys(mapping).sort((a, b) => (a < b ? -1 : 1))

for (const startingAddress of sorted) {
const lastAddress = mapping[startingAddress]
if (startingAddress.toLowerCase() <= formatted.toLowerCase()) {
if (formatted.toLowerCase() <= lastAddress.toLowerCase()) {
if (startingAddress <= lowerCasedAddress) {
if (lowerCasedAddress <= lastAddress) {
return startingAddress
}
} else {
Expand All @@ -739,7 +743,7 @@ function fetchClaims(account: string, chainId: number): Promise<UserClaims> {
})
.then((address) => fetchClaimsFile(address, chainId))
.then((result) => {
if (result[formatted]) return transformRepoClaimsToUserClaims(result[formatted]) // mod
if (result[lowerCasedAddress]) return transformRepoClaimsToUserClaims(result[lowerCasedAddress]) // mod
throw new Error(`Claim for ${claimKey} was not found in claim file!`)
})
.catch((error) => {
Expand Down

0 comments on commit bb7b1a1

Please sign in to comment.