Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching out old indexer api #196

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions examples/next/src/app/components/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { isDebugMode, sponsoredContractAddresses } from '../../config'
import { messageToSign } from '@/constants'
import { abi } from '@/constants/nft-abi'

import { ContractVerificationStatus } from '@0xsequence/kit'

export const Connected = () => {
const { address } = useAccount()
const { setOpenWalletModal } = useOpenWalletModal()
Expand Down Expand Up @@ -85,22 +87,23 @@ export const Connected = () => {
const checkTokenBalancesForFeeOptions = async () => {
if (pendingFeeOptionConfirmation) {
const [account] = await walletClient!.getAddresses()
const nativeTokenBalance = await indexerClient.getEtherBalance({ accountAddress: account })

const tokenBalances = await indexerClient.getTokenBalances({
accountAddress: account
const nativeTokenBalance = await indexerClient.getNativeTokenBalance({ accountAddress: account })

const tokenBalances = await indexerClient.getTokenBalancesSummary({
filter: {
accountAddresses: [account],
contractStatus: ContractVerificationStatus.ALL,
contractWhitelist: [],
contractBlacklist: []
}
})

console.log('feeOptions', pendingFeeOptionConfirmation.options)
console.log('nativeTokenBalance', nativeTokenBalance)
console.log('tokenBalances', tokenBalances)

const balances = pendingFeeOptionConfirmation.options.map(option => {
if (option.token.contractAddress === null) {
return {
tokenName: option.token.name,
decimals: option.token.decimals || 0,
balance: nativeTokenBalance.balance.balanceWei
balance: nativeTokenBalance.balance.balance
}
} else {
return {
Expand Down
17 changes: 12 additions & 5 deletions examples/react/src/components/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { messageToSign } from '../constants'
import { abi } from '../constants/nft-abi'
import { delay, getCheckoutSettings, getOrderbookCalldata } from '../utils'

import { ContractVerificationStatus } from '@0xsequence/kit'

// append ?debug to url to enable debug mode
const searchParams = new URLSearchParams(location.search)
const isDebugMode = searchParams.has('debug')
Expand Down Expand Up @@ -132,18 +134,23 @@ export const Connected = () => {
const checkTokenBalancesForFeeOptions = async () => {
if (pendingFeeOptionConfirmation && walletClient) {
const [account] = await walletClient.getAddresses()
const nativeTokenBalance = await indexerClient.getEtherBalance({ accountAddress: account })

const tokenBalances = await indexerClient.getTokenBalances({
accountAddress: account
const nativeTokenBalance = await indexerClient.getNativeTokenBalance({ accountAddress: account })

const tokenBalances = await indexerClient.getTokenBalancesSummary({
filter: {
accountAddresses: [account],
contractStatus: ContractVerificationStatus.ALL,
contractWhitelist: [],
contractBlacklist: []
}
})

const balances = pendingFeeOptionConfirmation.options.map(option => {
if (option.token.contractAddress === null) {
return {
tokenName: option.token.name,
decimals: option.token.decimals || 0,
balance: nativeTokenBalance.balance.balanceWei
balance: nativeTokenBalance.balance.balance
}
} else {
return {
Expand Down
10 changes: 7 additions & 3 deletions packages/checkout/src/views/CheckoutSelection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import {
Skeleton,
TokenImage
} from '@0xsequence/design-system'
import { getNativeTokenInfoByChainId, useBalances, useContractInfo } from '@0xsequence/kit'
import { ContractVerificationStatus, getNativeTokenInfoByChainId, useBalances, useContractInfo } from '@0xsequence/kit'
import { ethers } from 'ethers'
import React from 'react'
import { useAccount, useConfig } from 'wagmi'

import { HEADER_HEIGHT } from '../../constants'
Expand All @@ -40,7 +39,12 @@ export const CheckoutSelection = () => {

const { data: balancesData, isPending: isPendingBalances } = useBalances({
chainIds: [cryptoCheckoutSettings?.chainId || 1],
accountAddress: accountAddress || ''
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
contractStatus: ContractVerificationStatus.ALL,
contractWhitelist: [],
contractBlacklist: []
}
})

const isPending = (isPendingContractInfo || isPendingBalances) && cryptoCheckoutSettings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box, Text, Scroll, Spinner } from '@0xsequence/design-system'
import { useBalances, useContractInfo, useSwapPrices, compareAddress } from '@0xsequence/kit'
import { useBalances, useContractInfo, useSwapPrices, compareAddress, ContractVerificationStatus } from '@0xsequence/kit'
import { findSupportedNetwork } from '@0xsequence/network'
import { useState, useEffect, Fragment, SetStateAction } from 'react'
import { formatUnits, zeroAddress } from 'viem'
import { useEffect, Fragment, SetStateAction } from 'react'
import { formatUnits } from 'viem'
import { useAccount } from 'wagmi'

import { SelectPaymentSettings } from '../../../contexts'
Expand Down Expand Up @@ -35,10 +35,13 @@ export const PayWithCrypto = ({

const { data: currencyBalanceData, isLoading: currencyBalanceIsLoading } = useBalances({
chainIds: [chainId],
contractAddress: currencyAddress,
accountAddress: userAddress || '',
// includeMetadata must be false to work around a bug
includeMetadata: false
filter: {
accountAddresses: userAddress ? [userAddress] : [],
contractStatus: ContractVerificationStatus.ALL,
contractWhitelist: [currencyAddress],
contractBlacklist: []
},
omitMetadata: true
})

const { data: currencyInfoData, isLoading: isLoadingCurrencyInfo } = useContractInfo(chainId, currencyAddress)
Expand Down
15 changes: 10 additions & 5 deletions packages/checkout/src/views/PaymentSelection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
compareAddress,
TRANSACTION_CONFIRMATIONS_DEFAULT,
sendTransactions,
SwapPricesWithCurrencyInfo
SwapPricesWithCurrencyInfo,
ContractVerificationStatus
} from '@0xsequence/kit'
import { findSupportedNetwork } from '@0xsequence/network'
import { useState, useEffect } from 'react'
Expand Down Expand Up @@ -92,10 +93,14 @@ export const PaymentSelectionContent = () => {

const { data: currencyBalanceData, isLoading: currencyBalanceIsLoading } = useBalances({
chainIds: [chainId],
contractAddress: currencyAddress,
accountAddress: userAddress || '',
// includeMetadata must be false to work around a bug
includeMetadata: false
filter: {
accountAddresses: userAddress ? [userAddress] : [],
contractStatus: ContractVerificationStatus.ALL,
contractWhitelist: [currencyAddress],
contractBlacklist: []
},
// omitMetadata must be true to avoid a bug
omitMetadata: true
})

const { data: currencyInfoData, isLoading: isLoadingCurrencyInfo } = useContractInfo(chainId, currencyAddress)
Expand Down
10 changes: 7 additions & 3 deletions packages/kit/src/components/TxnDetails/TxnDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commons } from '@0xsequence/core'
import { Box, Card, GradientAvatar, Skeleton, Text, TokenImage } from '@0xsequence/design-system'
import { ContractType } from '@0xsequence/indexer'
import { ContractType, ContractVerificationStatus } from '@0xsequence/indexer'
import { ethers } from 'ethers'
import React, { useEffect, useState } from 'react'
import { useConfig } from 'wagmi'
Expand Down Expand Up @@ -96,8 +96,12 @@ const TransferItemInfo = ({ address, transferProps, chainId }: TransferItemInfoP

const { data: balances = [] } = useBalances({
chainIds: [chainId],
accountAddress: address,
contractAddress
filter: {
accountAddresses: [address],
contractStatus: ContractVerificationStatus.ALL,
contractWhitelist: [contractAddress],
contractBlacklist: []
}
})

const { data: tokenMetadata } = useTokenMetadata(chainId, contractAddress, transferProps.tokenIds ?? [])
Expand Down
Loading
Loading