Skip to content

Commit

Permalink
chore: Add api key for aptos api access (#10854)
Browse files Browse the repository at this point in the history
<!--
Before opening a pull request, please read the [contributing
guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md)
first
-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR primarily updates the dependency version of `@aptos-labs/ts-sdk`
from `1.12.2` to `1.30.0` across multiple package files and improves
type filtering in the `useAccountBalances` hook. It also modifies some
import statements and documentation links.

### Detailed summary
- Updated `@aptos-labs/ts-sdk` version to `1.30.0` in:
  - `pnpm-workspace.yaml`
  - `packages/aptos-swap-sdk/package.json`
  - `packages/awgmi/package.json`
  - `apps/aptos/package.json`
- Changed type filtering in `useAccountBalances` to ensure string type.
- Modified import statements in `apps/aptos/client.ts` to include
`Network`.
- Updated documentation link in `apps/aptos/next-env.d.ts`.
- Added `APTOS_GATEWAY_API_KEY` environment variable in
`apps/aptos/client.ts`.
- Updated `pnpm-lock.yaml` to reflect changes in dependencies.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
chefjackson authored Oct 25, 2024
1 parent 1153837 commit 63cec60
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 417 deletions.
19 changes: 15 additions & 4 deletions apps/aptos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { PetraConnector } from '@pancakeswap/awgmi/connectors/petra'
import { PontemConnector } from '@pancakeswap/awgmi/connectors/pontem'
import { RiseConnector } from '@pancakeswap/awgmi/connectors/rise'
import { SafePalConnector } from '@pancakeswap/awgmi/connectors/safePal'
import { Aptos, AptosConfig, NetworkToNetworkName } from '@aptos-labs/ts-sdk'
import { Aptos, AptosConfig, Network, NetworkToNetworkName } from '@aptos-labs/ts-sdk'
import { chains, defaultChain } from 'config/chains'

const NODE_REAL_API = process.env.NEXT_PUBLIC_NODE_REAL_API
const NODE_REAL_API_TESTNET = process.env.NEXT_PUBLIC_NODE_REAL_API_TESTNET
const APTOS_GATEWAY_API_KEY = process.env.NEXT_PUBLIC_APTOS_GATEWAY_API_KEY

const nodeReal = {
...(NODE_REAL_API && {
Expand Down Expand Up @@ -39,13 +40,21 @@ export const client = createClient({
],
provider: ({ networkName }) => {
const networkNameLowerCase = networkName?.toLowerCase()
const network = NetworkToNetworkName[networkNameLowerCase ?? defaultChain.network.toLowerCase()]
const clientConfig =
network === Network.MAINNET
? {
API_KEY: APTOS_GATEWAY_API_KEY,
}
: undefined

if (networkNameLowerCase) {
const foundChain = chains.find((c) => c.network === networkNameLowerCase)
if (foundChain) {
if (foundChain.nodeUrls.nodeReal && nodeReal[networkNameLowerCase]) {
return new Aptos(
new AptosConfig({
network: NetworkToNetworkName[networkNameLowerCase],
network,
fullnode: `${foundChain.nodeUrls.nodeReal}/${nodeReal[networkNameLowerCase]}/v1`,
clientConfig: {
WITH_CREDENTIALS: false,
Expand All @@ -55,16 +64,18 @@ export const client = createClient({
}
return new Aptos(
new AptosConfig({
network: NetworkToNetworkName[networkNameLowerCase],
network,
clientConfig,
}),
)
}
}

return new Aptos(
new AptosConfig({
network: NetworkToNetworkName[defaultChain.network.toLowerCase()],
network,
fullnode: defaultChain.nodeUrls.default,
clientConfig,
}),
)
},
Expand Down
2 changes: 1 addition & 1 deletion apps/aptos/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion apps/aptos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"node": ">=18.20.0"
},
"dependencies": {
"@aptos-labs/ts-sdk": "1.12.2",
"@aptos-labs/ts-sdk": "catalog:",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@pancakeswap/aptos-swap-sdk": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/aptos-swap-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@aptos-labs/ts-sdk": "1.x"
},
"devDependencies": {
"@aptos-labs/ts-sdk": "1.12.2",
"@aptos-labs/ts-sdk": "catalog:",
"@types/big.js": "^4.0.5",
"tsup": "^6.7.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/awgmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"react": "^18.2.0"
},
"devDependencies": {
"@aptos-labs/ts-sdk": "1.12.2",
"@aptos-labs/ts-sdk": "catalog:",
"@blocto/sdk": "^0.5.4",
"@msafe/aptos-wallet": "^3.0.6",
"@pancakeswap/tsconfig": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/awgmi/src/hooks/useAccountBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function useAccountBalances<TData = unknown>({
const v2Balances = coinsData?.[1]
const v1AssetsTypes = useV1CoinAssetTypes({
networkName,
assetTypes: v2Balances?.map((b) => b.asset_type) || [],
assetTypes: v2Balances?.map((b) => b.asset_type).filter((b): b is string => typeof b === 'string') || [],
enabled: Boolean(isSuccess && v2Balances?.length),
})
const { isFetched, data: mappedV2Balances } = useMemo(() => {
Expand Down Expand Up @@ -108,6 +108,7 @@ export function useAccountBalances<TData = unknown>({
for (const b of allBalances) {
if (!b) continue
const id = b.asset_type
if (typeof id !== 'string') continue
const amount = assetTypeToBalance.get(id) || 0
assetTypeToBalance.set(id, amount + b.amount)
}
Expand Down
Loading

0 comments on commit 63cec60

Please sign in to comment.