@goodaofi/bonds-sdk 3.0.177 → 3.0.179
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +3 -200
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { forwardRef, useContext, useState, useEffect, useCallback, useMemo, useLayoutEffect, createContext as createContext$1, useRef, useId, useInsertionEffect as useInsertionEffect$1, Children, isValidElement, Fragment as Fragment$1, createElement as createElement$1, Component } from 'react';
|
|
3
3
|
import { useAccount, useWaitForTransactionReceipt, useChainId, useSwitchChain, useWriteContract, useSendTransaction } from 'wagmi';
|
|
4
|
-
import { useQueryClient, useQuery
|
|
4
|
+
import { useQueryClient, useQuery } from '@tanstack/react-query';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import { ConnectButton as ConnectButton$1 } from '@rainbow-me/rainbowkit';
|
|
7
7
|
|
|
@@ -59469,8 +59469,6 @@ const QUERY_KEYS = {
|
|
|
59469
59469
|
USER_INFO: 'Goomoney-SDK-userInfo',
|
|
59470
59470
|
USER_GOO_DATA: 'Goomoney-SDK-userGooData',
|
|
59471
59471
|
PRIVATE_PARTNER_INFO: 'Goomoney-SDK-privatePartnerInfo',
|
|
59472
|
-
GOO_ELIGIBILITY: 'Goomoney-SDK-gooEligibility',
|
|
59473
|
-
CBBTC_BALANCE: 'Goomoney-SDK-cbBTCBalance',
|
|
59474
59472
|
// used values on SDK
|
|
59475
59473
|
BOND_API_STATS: 'Goomoney-SDK-bondApiStats',
|
|
59476
59474
|
SDK_CONFIG: 'Goomoney-SDK-sdkConfig',
|
|
@@ -100094,7 +100092,7 @@ const YourGoo = ({ yourGoo, isLoading, isFetching, }) => {
|
|
|
100094
100092
|
symbol: 'sGOO',
|
|
100095
100093
|
},
|
|
100096
100094
|
};
|
|
100097
|
-
return (jsxs(Flex, { sx: { width: '100%', justifyContent: 'center', flexDirection: 'column', alignItems: 'center' }, children: [jsx$2(Text, { sx: { fontSize: '20px', fontWeight: 'bold', opacity: 0.5 }, children: "Your Pending Tokens" }), isLoading
|
|
100095
|
+
return (jsxs(Flex, { sx: { width: '100%', justifyContent: 'center', flexDirection: 'column', alignItems: 'center' }, children: [jsx$2(Text, { sx: { fontSize: '20px', fontWeight: 'bold', opacity: 0.5 }, children: "Your Pending Tokens" }), isLoading ? (jsx$2(Flex, { sx: { justifyContent: 'center', alignItems: 'center', p: '30px' }, children: jsx$2(Spinner, {}) })) : (jsx$2(Flex, { sx: {
|
|
100098
100096
|
flexDirection: ['column', 'column', 'row', 'row'],
|
|
100099
100097
|
width: '100%',
|
|
100100
100098
|
}, children: Object.entries(cardInfo).map(([key, value]) => {
|
|
@@ -100171,7 +100169,7 @@ const YourGoo = ({ yourGoo, isLoading, isFetching, }) => {
|
|
|
100171
100169
|
textAlign: 'center',
|
|
100172
100170
|
fontWeight: 'bold',
|
|
100173
100171
|
fontSize: ['12px', '12px', '14px', '14px'],
|
|
100174
|
-
}, children: `${depositBtcTotal.toFixed(3)} BTC` })] }), jsx$2(Flex, { sx: { justifyContent: 'center', mt: '20px' }, children: jsx$2(Button, { onClick: () => (window.location.href = '/bonds?yourBonds'), children: "Claim Here" }) })] })] }, key)) : (jsx$2(Flex, { sx: {
|
|
100172
|
+
}, children: `${depositBtcTotal.toFixed(3)} BTC` })] }), jsx$2(Flex, { sx: { justifyContent: 'center', mt: '20px' }, children: jsx$2(Button, { onClick: () => (window.location.href = 'https://app.goo.money/bonds?yourBonds'), children: "Claim Here" }) })] })] }, key)) : (jsx$2(Flex, { sx: {
|
|
100175
100173
|
flexDirection: 'column',
|
|
100176
100174
|
width: '100%',
|
|
100177
100175
|
background: 'white2',
|
|
@@ -100189,159 +100187,6 @@ const YourGoo = ({ yourGoo, isLoading, isFetching, }) => {
|
|
|
100189
100187
|
}) }))] }));
|
|
100190
100188
|
};
|
|
100191
100189
|
|
|
100192
|
-
const checkEligibility = async (address) => {
|
|
100193
|
-
if (!address)
|
|
100194
|
-
return null;
|
|
100195
|
-
const response = await axios.get('https://strapi-api.ape.bond/goomoney-whitelist');
|
|
100196
|
-
if (response.data) {
|
|
100197
|
-
// map through the tier mapping and return the tier for the address, if no address return undefined
|
|
100198
|
-
const userTier = response.data
|
|
100199
|
-
.filter((data) => data.wallets.map((w) => w.toLowerCase()).includes(address.toLowerCase()))
|
|
100200
|
-
.sort((a, b) => a.tier - b.tier)[0];
|
|
100201
|
-
return userTier?.tier ?? null;
|
|
100202
|
-
}
|
|
100203
|
-
else {
|
|
100204
|
-
return null;
|
|
100205
|
-
}
|
|
100206
|
-
};
|
|
100207
|
-
const addToWhitelist = async (address) => {
|
|
100208
|
-
try {
|
|
100209
|
-
// First, get the current tier 2 collection to get its ID and existing wallets
|
|
100210
|
-
const response = await axios.get('https://strapi-api.ape.bond/goomoney-whitelist');
|
|
100211
|
-
const tier2Collection = response.data.find((item) => item.tier === 2);
|
|
100212
|
-
if (!tier2Collection) {
|
|
100213
|
-
console.error('Tier 2 collection not found');
|
|
100214
|
-
return false;
|
|
100215
|
-
}
|
|
100216
|
-
// Check if wallet is already in the list
|
|
100217
|
-
if (tier2Collection.wallets.some((w) => w.toLowerCase() === address.toLowerCase())) {
|
|
100218
|
-
return true;
|
|
100219
|
-
}
|
|
100220
|
-
// Add the new wallet to the existing wallets array
|
|
100221
|
-
const updatedWallets = [...tier2Collection.wallets, address];
|
|
100222
|
-
// PUT request to update the tier 2 collection with the new wallets array
|
|
100223
|
-
await axios.put(`https://strapi-api.ape.bond/goomoney-whitelist/${tier2Collection.id}`, {
|
|
100224
|
-
wallets: updatedWallets,
|
|
100225
|
-
});
|
|
100226
|
-
return true;
|
|
100227
|
-
}
|
|
100228
|
-
catch (error) {
|
|
100229
|
-
console.error('Failed to add to whitelist:', error);
|
|
100230
|
-
return false;
|
|
100231
|
-
}
|
|
100232
|
-
};
|
|
100233
|
-
// Helper function to get chain name
|
|
100234
|
-
const getChainName = (chainId) => {
|
|
100235
|
-
const chainNames = {
|
|
100236
|
-
[main.ChainId.BASE]: 'Base',
|
|
100237
|
-
[main.ChainId.ARBITRUM]: 'Arbitrum',
|
|
100238
|
-
[main.ChainId.BSC]: 'BSC',
|
|
100239
|
-
[main.ChainId.MAINNET]: 'Ethereum',
|
|
100240
|
-
};
|
|
100241
|
-
return chainNames[chainId] || `Chain ${chainId}`;
|
|
100242
|
-
};
|
|
100243
|
-
function useGooEligibility() {
|
|
100244
|
-
const { address } = useAccount();
|
|
100245
|
-
const queryClient = useQueryClient();
|
|
100246
|
-
const [cbBTCBalanceChecked, setCbBTCBalanceChecked] = useState(false);
|
|
100247
|
-
const SDKConfig = useSDKConfig();
|
|
100248
|
-
const isFake = SDKConfig?.isFakeBTC ?? false;
|
|
100249
|
-
// Get BTC tokens for all chains
|
|
100250
|
-
const btcTokensSource = isFake ? FAKE_BTC_TOKENS : BTC_TOKENS;
|
|
100251
|
-
const chainsToCheck = [main.ChainId.BASE, main.ChainId.ARBITRUM, main.ChainId.BSC, main.ChainId.MAINNET];
|
|
100252
|
-
// Fetch balances for all chains - call hooks at top level
|
|
100253
|
-
const baseToken = btcTokensSource[main.ChainId.BASE];
|
|
100254
|
-
const arbitrumToken = btcTokensSource[main.ChainId.ARBITRUM];
|
|
100255
|
-
const bscToken = btcTokensSource[main.ChainId.BSC];
|
|
100256
|
-
const mainnetToken = btcTokensSource[main.ChainId.MAINNET];
|
|
100257
|
-
const baseBalanceQuery = useUserTokensBalance(baseToken ? [baseToken] : [], main.ChainId.BASE);
|
|
100258
|
-
const arbitrumBalanceQuery = useUserTokensBalance(arbitrumToken ? [arbitrumToken] : [], main.ChainId.ARBITRUM);
|
|
100259
|
-
const bscBalanceQuery = useUserTokensBalance(bscToken ? [bscToken] : [], main.ChainId.BSC);
|
|
100260
|
-
const mainnetBalanceQuery = useUserTokensBalance(mainnetToken ? [mainnetToken] : [], main.ChainId.MAINNET);
|
|
100261
|
-
// Collect balance queries and data
|
|
100262
|
-
const balanceQueries = [baseBalanceQuery, arbitrumBalanceQuery, bscBalanceQuery, mainnetBalanceQuery];
|
|
100263
|
-
const balancesData = balanceQueries.map((q) => q.data);
|
|
100264
|
-
const refetchAllBalances = async () => {
|
|
100265
|
-
await Promise.all(balanceQueries.map((q) => q.refetch()));
|
|
100266
|
-
};
|
|
100267
|
-
// Check BTC balance across all chains
|
|
100268
|
-
const cbBTCBalanceInfo = useQuery({
|
|
100269
|
-
queryKey: [QUERY_KEYS.CBBTC_BALANCE, address, balancesData, cbBTCBalanceChecked],
|
|
100270
|
-
queryFn: () => {
|
|
100271
|
-
// Check if we have any balance data
|
|
100272
|
-
const hasData = balancesData.some((data) => data && data.length > 0);
|
|
100273
|
-
if (!hasData) {
|
|
100274
|
-
return null;
|
|
100275
|
-
}
|
|
100276
|
-
// Collect all BTC balances from all chains
|
|
100277
|
-
const allBalances = chainsToCheck.map((chainId, index) => {
|
|
100278
|
-
const chainBalances = balancesData[index];
|
|
100279
|
-
const token = btcTokensSource[chainId];
|
|
100280
|
-
const tokenAddress = token?.address[chainId];
|
|
100281
|
-
if (!chainBalances || !tokenAddress) {
|
|
100282
|
-
return { chainId, balance: 0, symbol: token?.symbol || 'BTC' };
|
|
100283
|
-
}
|
|
100284
|
-
// Find the balance for this token
|
|
100285
|
-
const tokenBalance = chainBalances.find((b) => b.address?.toLowerCase() === tokenAddress.toLowerCase());
|
|
100286
|
-
const balance = tokenBalance ? parseFloat(tokenBalance.balance) : 0;
|
|
100287
|
-
return {
|
|
100288
|
-
chainId,
|
|
100289
|
-
chainName: getChainName(chainId),
|
|
100290
|
-
balance,
|
|
100291
|
-
symbol: token?.symbol || 'BTC',
|
|
100292
|
-
};
|
|
100293
|
-
});
|
|
100294
|
-
// Calculate total balance and check eligibility
|
|
100295
|
-
const totalBalance = allBalances.reduce((sum, item) => sum + item.balance, 0);
|
|
100296
|
-
const isEligible = totalBalance >= 0.001;
|
|
100297
|
-
// Find which chains have balance
|
|
100298
|
-
const chainsWithBalance = allBalances.filter((item) => item.balance > 0);
|
|
100299
|
-
const result = {
|
|
100300
|
-
balance: totalBalance,
|
|
100301
|
-
isEligible,
|
|
100302
|
-
balancesByChain: allBalances,
|
|
100303
|
-
chainsWithBalance,
|
|
100304
|
-
};
|
|
100305
|
-
return result;
|
|
100306
|
-
},
|
|
100307
|
-
enabled: cbBTCBalanceChecked && balancesData.some((data) => data && data.length > 0),
|
|
100308
|
-
staleTime: 0,
|
|
100309
|
-
gcTime: 0,
|
|
100310
|
-
});
|
|
100311
|
-
// Mutation to add user to whitelist
|
|
100312
|
-
const addToWhitelistMutation = useMutation({
|
|
100313
|
-
mutationFn: () => addToWhitelist(address),
|
|
100314
|
-
onSuccess: () => {
|
|
100315
|
-
// Refetch eligibility after successful addition
|
|
100316
|
-
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GOO_ELIGIBILITY, address] });
|
|
100317
|
-
},
|
|
100318
|
-
});
|
|
100319
|
-
const eligibilityQuery = useQuery({
|
|
100320
|
-
queryKey: [QUERY_KEYS.GOO_ELIGIBILITY, address],
|
|
100321
|
-
queryFn: () => checkEligibility(address),
|
|
100322
|
-
refetchInterval: 600000,
|
|
100323
|
-
refetchOnWindowFocus: false,
|
|
100324
|
-
refetchOnMount: false,
|
|
100325
|
-
refetchOnReconnect: false,
|
|
100326
|
-
});
|
|
100327
|
-
// Function to check BTC balance across all chains
|
|
100328
|
-
const checkCbBTCBalance = async () => {
|
|
100329
|
-
await refetchAllBalances();
|
|
100330
|
-
setCbBTCBalanceChecked(true);
|
|
100331
|
-
};
|
|
100332
|
-
return {
|
|
100333
|
-
...eligibilityQuery,
|
|
100334
|
-
cbBTCBalance: cbBTCBalanceInfo.data,
|
|
100335
|
-
isCbBTCBalanceLoading: cbBTCBalanceInfo.isLoading || cbBTCBalanceInfo.isFetching,
|
|
100336
|
-
cbBTCBalanceChecked,
|
|
100337
|
-
checkCbBTCBalance,
|
|
100338
|
-
addToWhitelist: addToWhitelistMutation.mutate,
|
|
100339
|
-
isAddingToWhitelist: addToWhitelistMutation.isPending,
|
|
100340
|
-
addToWhitelistSuccess: addToWhitelistMutation.isSuccess,
|
|
100341
|
-
addToWhitelistError: addToWhitelistMutation.isError,
|
|
100342
|
-
};
|
|
100343
|
-
}
|
|
100344
|
-
|
|
100345
100190
|
function useYourGoo(userAddress) {
|
|
100346
100191
|
const SDKConfig = useSDKConfig();
|
|
100347
100192
|
const apiAddress = SDKConfig?.urls?.apiV2;
|
|
@@ -100413,32 +100258,11 @@ var BondsViewOptions;
|
|
|
100413
100258
|
const GooSale = () => {
|
|
100414
100259
|
// Fetch data
|
|
100415
100260
|
const { data: chainFilterOption, setChainFilterOption } = useChainFilterOption();
|
|
100416
|
-
const { data: saleInfo, isLoading: isLoadingSaleInfo } = useSaleInfo();
|
|
100417
100261
|
const SDKConfig = useSDKConfig();
|
|
100418
|
-
saleInfo?.isInBreakPeriod
|
|
100419
|
-
? saleInfo?.nextStage?.stageNumber || 1
|
|
100420
|
-
: saleInfo?.currentStage?.stageNumber || 1;
|
|
100421
100262
|
const { address } = useAccount();
|
|
100422
100263
|
const { data: yourGoo, isLoading, isFetching } = useYourGoo(address);
|
|
100423
100264
|
const userParticipated = address && !isLoading && !isFetching && (yourGoo?.depositToGooBond !== '0' || yourGoo?.depositToSGooBond !== '0');
|
|
100424
100265
|
const chainId = useChainId();
|
|
100425
|
-
useGooEligibility();
|
|
100426
|
-
const [checkButtonPushed, setCheckButtonPushed] = useState(false);
|
|
100427
|
-
saleInfo?.currentStage?.progressPercentage === 100;
|
|
100428
|
-
// // Wrapper function that sets chain filter AND switches wallet chain
|
|
100429
|
-
// const handleChainFilterChange = useCallback(
|
|
100430
|
-
// (newChainFilter: string[]) => {
|
|
100431
|
-
// setChainFilterOption(newChainFilter)
|
|
100432
|
-
// // Switch wallet to the selected chain if it's different from current
|
|
100433
|
-
// if (newChainFilter.length > 0 && switchChain) {
|
|
100434
|
-
// const targetChainId = parseInt(newChainFilter[0])
|
|
100435
|
-
// if (targetChainId !== chainId) {
|
|
100436
|
-
// switchChain({ chainId: targetChainId })
|
|
100437
|
-
// }
|
|
100438
|
-
// }
|
|
100439
|
-
// },
|
|
100440
|
-
// [setChainFilterOption, switchChain, chainId],
|
|
100441
|
-
// )
|
|
100442
100266
|
// Sync chain filter with connected chain
|
|
100443
100267
|
useEffect(() => {
|
|
100444
100268
|
if (chainId) {
|
|
@@ -100449,27 +100273,6 @@ const GooSale = () => {
|
|
|
100449
100273
|
}
|
|
100450
100274
|
}
|
|
100451
100275
|
}, [chainId, chainFilterOption, setChainFilterOption]);
|
|
100452
|
-
// // Filter contracts by chain
|
|
100453
|
-
// const filteredContractsByChain = useMemo(() => {
|
|
100454
|
-
// const contractsByChain = saleInfo?.currentStage?.contractsByChain
|
|
100455
|
-
// if (!contractsByChain) return undefined
|
|
100456
|
-
// // Filter by selected chains
|
|
100457
|
-
// const filtered: Record<number, GooSaleContractData[]> = {}
|
|
100458
|
-
// Object.entries(contractsByChain).forEach(([chainId, contracts]) => {
|
|
100459
|
-
// if (chainFilterOption?.includes(chainId)) {
|
|
100460
|
-
// filtered[parseInt(chainId)] = contracts
|
|
100461
|
-
// }
|
|
100462
|
-
// })
|
|
100463
|
-
// return filtered
|
|
100464
|
-
// }, [saleInfo?.currentStage?.contractsByChain, chainFilterOption])
|
|
100465
|
-
// Dynamic title based on current period (hidden during refund period)
|
|
100466
|
-
useMemo(() => {
|
|
100467
|
-
if (saleInfo?.isRefundPeriod)
|
|
100468
|
-
return null;
|
|
100469
|
-
if (saleInfo?.currentStage?.key === 'TGE')
|
|
100470
|
-
return 'GOO Token Generation Event';
|
|
100471
|
-
return 'Buy GOO at a discount';
|
|
100472
|
-
}, [saleInfo?.isRefundPeriod, saleInfo?.currentStage?.key]);
|
|
100473
100276
|
return (jsxs(Flex, { className: "bonds-container", children: [jsx$2(CheckUrl, {}), !SDKConfig.bondsComingSoon && (jsx$2(Flex, { sx: {
|
|
100474
100277
|
display: 'flex',
|
|
100475
100278
|
flexDirection: 'column',
|