Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/add-backend-it
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1asm committed Mar 26, 2024
2 parents c12c378 + 7de14d5 commit a79c52c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 7 additions & 1 deletion frontend/hooks/useAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import { useWallet as useSolanaWallet } from '@solana/wallet-adapter-react'
import { useAccount } from 'wagmi'
import { useWallet as useAlgorandWallet } from '@components/Ecosystem/AlgorandProvider'

const PREFIX_0X = '0x'

export function useAptosAddress(): string | undefined {
const { account } = useAptosWallet()
return account?.address
if (account && account.address) {
return `${PREFIX_0X}${account.address
.replace(PREFIX_0X, '')
.padStart(64, '0')}`
}
}

export function useCosmosAddress(
Expand Down
13 changes: 7 additions & 6 deletions frontend/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SignedMessage } from '../claim_sdk/ecosystems/signatures'
import { ECOSYSTEM_IDS } from './constants'

const MERKLE_PROOFS = process.env.NEXT_PUBLIC_MERKLE_PROOFS
const BACKEND_API = process.env.NEXT_PUBLIC_BACKEND_API

function parseProof(proof: string) {
// TODO remove it, we should not have empty proofs and will fail if tahat happens
Expand Down Expand Up @@ -43,7 +44,6 @@ const getAmountAndProofRoute = (
}
}

// TODO refactor/remove
export function handleAmountAndProofResponse(
ecosystem: Ecosystem,
identity: string,
Expand Down Expand Up @@ -79,7 +79,10 @@ export async function fetchAmountAndProof(
const response = await fetch(file)
if (response.headers.get('content-type') === 'application/json') {
const data = await response.json()
if (response.status === 200 && data.address === identity) {
if (
response.status === 200 &&
data.address.toLocaleLowerCase() === identity.toLocaleLowerCase()
) {
return {
claimInfo: new ClaimInfo(ecosystem, identity, new BN(data.amount)),
proofOfInclusion: parseProof(data.hashes),
Expand All @@ -90,8 +93,7 @@ export async function fetchAmountAndProof(
}

export function getDiscordSignedMessageRoute(claimant: PublicKey) {
// TODO update it with lambda route
return `/api/grant/v1/discord_signed_message?publicKey=${claimant.toBase58()}`
return `${BACKEND_API}/api/grant/v1/discord_signed_message?publicKey=${claimant.toBase58()}`
}

export function handleDiscordSignedMessageResponse(
Expand Down Expand Up @@ -119,8 +121,7 @@ export async function fetchDiscordSignedMessage(
}

export function getFundTransactionRoute(): string {
// TODO update it with lambda route
return `/api/grant/v1/fund_transaction`
return `${BACKEND_API}/api/grant/v1/fund_transaction`
}

export function handleFundTransaction(
Expand Down
11 changes: 4 additions & 7 deletions frontend/utils/toStringWithDecimals.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import BN from 'bn.js'

const TRAILING_ZEROS = new RegExp(/\.?0+$/)
const PYTH_DECIMALS = 6
const W_DECIMALS = 9

export function toStringWithDecimals(amount: BN) {
const padded = amount.toString().padStart(PYTH_DECIMALS + 1, '0')
const padded = amount.toString().padStart(W_DECIMALS + 1, '0')
return (
padded.slice(0, padded.length - PYTH_DECIMALS) +
('.' + padded.slice(padded.length - PYTH_DECIMALS)).replace(
TRAILING_ZEROS,
''
)
padded.slice(0, padded.length - W_DECIMALS) +
('.' + padded.slice(padded.length - W_DECIMALS)).replace(TRAILING_ZEROS, '')
)
}

0 comments on commit a79c52c

Please sign in to comment.