Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:pancakeswap/pancake-frontend int…
Browse files Browse the repository at this point in the history
…o feature/uikit-multi-select
  • Loading branch information
chef-eric committed Jul 9, 2024
2 parents a14b2b3 + 809c756 commit e0579ba
Show file tree
Hide file tree
Showing 79 changed files with 1,397 additions and 445 deletions.
6 changes: 6 additions & 0 deletions .changeset/lucky-peaches-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@pancakeswap/tokens': patch
'@pancakeswap/farms': patch
---

Add Subsquid (SQD) token and SQD-ETH farm on Arbitrum
6 changes: 6 additions & 0 deletions .changeset/tasty-meals-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@pancakeswap/widgets-internal': minor
'@pancakeswap/uikit': minor
---

new UIKit: TreeSelect
2 changes: 1 addition & 1 deletion .github/workflows/deploy-apis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
fetch-depth: 2

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/farmConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fetch-depth: 2

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fetch-depth: 2

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unitTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fetch-depth: 2

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/updateCron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
- name: Set up node@18
uses: actions/setup-node@v3
with:
Expand Down
162 changes: 162 additions & 0 deletions apps/web/src/components/ClaimZksyncAirdropModal/hooks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { ChainId } from '@pancakeswap/chains'
import { useTranslation } from '@pancakeswap/localization'
import { useToast } from '@pancakeswap/uikit'
import { useQuery } from '@tanstack/react-query'
import { ToastDescriptionWithTx } from 'components/Toast'
import { zkSyncAirDropABI } from 'config/abi/zksyncAirdrop'
import useCatchTxError from 'hooks/useCatchTxError'
import { useZksyncAirDropContract } from 'hooks/useContract'
import { usePaymaster } from 'hooks/usePaymaster'
import { useSwitchNetwork } from 'hooks/useSwitchNetwork'
import { useCallback } from 'react'
import { calculateGasMargin } from 'utils'
import { getZkSyncAirDropAddress } from 'utils/addressHelpers'
import { getGasSponsorship } from 'utils/paymaster'
import { publicClient } from 'utils/wagmi'
import { Address, encodeFunctionData } from 'viem'
import { useAccount, useConfig } from 'wagmi'

interface ZksyncAirDropWhiteListData {
address: Address
amount: string
proof: any[]
}

export const fetchZksyncAirDropWhitelist = async (account: Address): Promise<ZksyncAirDropWhiteListData> => {
const response = await fetch(`https://proofs.pancakeswap.com/zksync-airdrop/v9/${account}`)
if (!response.ok) {
throw new Error('User is not in whitelist')
}
return response.json() as Promise<ZksyncAirDropWhiteListData>
}

export const fetchZksyncAirDropData = async (account: Address, address: Address, proof: any[]) => {
const zksyncAirDropData = await publicClient({ chainId: ChainId.ZKSYNC }).multicall({
contracts: [
{
abi: zkSyncAirDropABI,
address,
functionName: 'canClaim',
args: [account, 0n, proof],
},
{
abi: zkSyncAirDropABI,
address,
functionName: 'claimedAmounts',
args: [account],
},
],
allowFailure: false,
})

return { canClaim: zksyncAirDropData[0], claimedAmount: zksyncAirDropData[1] }
}

export const useZksyncAirDropData = (proof?: any[]) => {
const address = getZkSyncAirDropAddress(ChainId.ZKSYNC)
const { address: account } = useAccount()
const { data, refetch } = useQuery({
queryKey: ['zksyncAirdrop', account, address, proof],
queryFn: () => fetchZksyncAirDropData(account!, address, proof!),
enabled: Boolean(account) && Boolean(address) && Boolean(proof),
})
return { zksyncAirdropData: data, refetch }
}

export const useUserWhiteListData = () => {
const { address: account } = useAccount()
const { data } = useQuery({
queryKey: ['zksyncAirdropWhiteList', account],
queryFn: () => fetchZksyncAirDropWhitelist(account!),
enabled: Boolean(account),
})

return data
? {
account: data.address,
amount: BigInt(data.amount),
proof: data?.proof,
}
: undefined
}

export const useClaimZksyncAirdrop = (onDone?: () => void) => {
const { t } = useTranslation()
const { address: account, chainId } = useAccount()
const whiteListData = useUserWhiteListData()
const { toastSuccess } = useToast()
const zkSyncAirDropContract = useZksyncAirDropContract()
const { fetchWithCatchTxError, loading: pendingTx } = useCatchTxError()
const { isPaymasterAvailable, isPaymasterTokenActive, sendPaymasterTransaction } = usePaymaster()
const chainConfig = useConfig()
const chain = chainConfig.chains[ChainId.ZKSYNC]
const { switchNetwork } = useSwitchNetwork()

const claimAirDrop = useCallback(async () => {
if (!whiteListData || !zkSyncAirDropContract || !account || chainId !== ChainId.ZKSYNC) {
if (chainId !== ChainId.ZKSYNC) {
switchNetwork(ChainId.ZKSYNC)
}
return
}
const receipt = await fetchWithCatchTxError(async () => {
if (isPaymasterAvailable && isPaymasterTokenActive) {
// Check gas balance
const { isEnoughGasBalance } = await getGasSponsorship()

if (isEnoughGasBalance) {
const estimatedGas = await zkSyncAirDropContract.estimateGas.claim(
[account, whiteListData.amount, whiteListData.proof],
{
account,
},
)

const calldata = encodeFunctionData({
abi: zkSyncAirDropContract.abi,
functionName: 'claim',
args: [account, whiteListData.amount, whiteListData.proof],
})

const call = {
address: zkSyncAirDropContract.address,
calldata,
gas: calculateGasMargin(estimatedGas),
}

return sendPaymasterTransaction(call, account)
}
// If not enough gas balance, continue to normal claim
}

return zkSyncAirDropContract.write.claim([account, whiteListData.amount, whiteListData.proof], {
account,
chain,
})
})
if (receipt?.status) {
onDone?.()
toastSuccess(
`${t('AirDrop Claimed!')}`,
<ToastDescriptionWithTx txHash={receipt.transactionHash}>{t('ZK AirDrop Claimed')}</ToastDescriptionWithTx>,
)
}
}, [
whiteListData,
zkSyncAirDropContract,
account,
chainId,
fetchWithCatchTxError,
switchNetwork,
isPaymasterAvailable,
isPaymasterTokenActive,
chain,
sendPaymasterTransaction,
toastSuccess,
t,
onDone,
])

// eslint-disable-next-line consistent-return
return { claimAirDrop, pendingTx }
}
Loading

0 comments on commit e0579ba

Please sign in to comment.