Skip to content

Commit

Permalink
feat/update api calls to read from flat files (#25)
Browse files Browse the repository at this point in the history
* add key to the react components to avoid double rendering when it is not necesary

* disable useRedirect for now, will be re enabled later

* remove csv references

* add missing dep to the deps array

* update api calls to read from new API

* update cosmwasm to specific chains, since we need to distinguish the chains and his ids

* code review comments

* run prettier
  • Loading branch information
sebastianscatularo authored Mar 20, 2024
1 parent ae80e0c commit 6b61eda
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 636 deletions.
9 changes: 6 additions & 3 deletions frontend/claim_sdk/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ export type Ecosystem =
| 'evm'
| 'sui'
| 'aptos'
| 'cosmwasm'
| 'terra'
| 'osmosis'
| 'injective'
export const Ecosystems: Ecosystem[] = [
'discord',
'solana',
'evm',
'sui',
'aptos',
'cosmwasm',
'terra',
'osmosis',
'injective',
]

Expand Down Expand Up @@ -53,7 +55,8 @@ export class ClaimInfo {
}
break
}
case 'cosmwasm': {
case 'osmosis':
case 'terra': {
identityStruct = {
cosmwasm: { address: this.identity },
}
Expand Down
1 change: 1 addition & 0 deletions frontend/claim_sdk/merkleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const LEAF_PREFIX = Buffer.from('00', 'hex')
const NODE_PREFIX = Buffer.from('01', 'hex')
const NULL_PREFIX = Buffer.from('02', 'hex')

// The size of the hash output in bytes
export const HASH_SIZE = 20

export class MerkleTree {
Expand Down
6 changes: 4 additions & 2 deletions frontend/claim_sdk/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ export class TokenDispenserProvider {
},
}
}
case 'cosmwasm': {
case 'osmosis':
case 'terra': {
return {
cosmwasm: {
pubkey: Array.from(signedMessage.publicKey),
Expand Down Expand Up @@ -426,7 +427,8 @@ export class TokenDispenserProvider {
recoveryId: signedMessage.recoveryId!,
})
}
case 'cosmwasm': {
case 'osmosis':
case 'terra': {
return undefined
}
case 'discord':
Expand Down
14 changes: 8 additions & 6 deletions frontend/claim_sdk/testWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export async function loadTestWallets(): Promise<
evm: [],
sui: [],
aptos: [],
cosmwasm: [],
terra: [],
osmosis: [],
injective: [],
}
result['discord'] = [
Expand All @@ -90,11 +91,12 @@ export async function loadTestWallets(): Promise<
result['evm'] = [TestEvmWallet.fromKeyfile(evmPrivateKeyPath)]
result['sui'] = [TestSuiWallet.fromKeyfile(suiPrivateKeyPath)]
result['aptos'] = [TestAptosWallet.fromKeyfile(aptosPrivateKeyPath)]
result['cosmwasm'] = [
await TestCosmWasmWallet.fromKeyFile(cosmosPrivateKeyPath, 'osmo'),
await TestCosmWasmWallet.fromKeyFile(cosmosPrivateKeyPath, 'terra', [
stringToPath("m/44'/330'/0'/0/0"),
]),
// prettier-ignore
result['osmosis'] = [await TestCosmWasmWallet.fromKeyFile(cosmosPrivateKeyPath, 'osmo')]
// prettier-ignore
result['terra'] = [await TestCosmWasmWallet.fromKeyFile(cosmosPrivateKeyPath, 'terra', [
stringToPath("m/44'/330'/0'/0/0"),
]),
]
result['injective'] = [TestEvmWallet.fromKeyfile(cosmosPrivateKeyPath, true)]

Expand Down
5 changes: 4 additions & 1 deletion frontend/integration/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@solana/web3.js'
import { NextApiRequest, NextApiResponse } from 'next'
import {
getAmountAndProofRoute,
getFundTransactionRoute,
handleAmountAndProofResponse,
handleFundTransaction,
Expand Down Expand Up @@ -38,6 +37,10 @@ const WHITELISTED_PROGRAMS: PublicKey[] = [
ComputeBudgetProgram.programId,
]

function getAmountAndProofRoute(..._: any[]): string {
return ''
}

function lowerCapIfEvm(identity: string, ecosystem: string): string {
if (ecosystem === 'evm') {
return identity.toLowerCase()
Expand Down
15 changes: 6 additions & 9 deletions frontend/integration/integrationTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ describe('integration test', () => {

it('submits a cosmwasm claim', async () => {
const { claimInfo, proofOfInclusion } = (await mockFetchAmountAndProof(
'cosmwasm',
testWallets.cosmwasm[0].address()
'terra',
testWallets.terra[0].address()
))!

const signedMessage = await testWallets.cosmwasm[0].signMessage(
const signedMessage = await testWallets.terra[0].signMessage(
tokenDispenserProvider.generateAuthorizationPayload()
)

Expand Down Expand Up @@ -283,7 +283,7 @@ describe('integration test', () => {
const cosmClaimEvent = txnEvents[0].event!
expect(cosmClaimEvent.claimant.equals(wallet.publicKey)).toBeTruthy()
expect(cosmClaimEvent.claimInfo.identity).toEqual({
cosmwasm: { address: testWallets.cosmwasm[0].address() },
cosmwasm: { address: testWallets.terra[0].address() },
})
expect(
new anchor.BN(cosmClaimEvent.claimInfo.amount.toString()).eq(
Expand All @@ -299,15 +299,12 @@ describe('integration test', () => {
}, 40000)

it('submits multiple claims at once', async () => {
const wallets: TestWallet[] = [
testWallets.cosmwasm[1],
testWallets.cosmwasm[2],
]
const wallets: TestWallet[] = [testWallets.terra[1], testWallets.terra[2]]

const claims = await Promise.all(
wallets.map(async (wallet) => {
const { claimInfo, proofOfInclusion } =
(await mockFetchAmountAndProof('cosmwasm', wallet.address()))!
(await mockFetchAmountAndProof('terra', wallet.address()))!
return {
claimInfo,
proofOfInclusion,
Expand Down
4 changes: 3 additions & 1 deletion frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const App: FC<AppProps> = ({ Component, pageProps }: AppProps) => {
setIsVersionChecked(true)
}, [router])

useRedirect(isVersionChecked)
// TODO Review this, we should check if the user
// loads the page, we should redirect to welcome pages again
// useRedirect(isVersionChecked)

return (
<>
Expand Down
Loading

0 comments on commit 6b61eda

Please sign in to comment.