@ape.swap/bonds-sdk 4.1.0-test.12 → 4.1.0-test.13
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
CHANGED
|
@@ -65634,29 +65634,29 @@ const useSOLAccount = () => {
|
|
|
65634
65634
|
};
|
|
65635
65635
|
|
|
65636
65636
|
function useUserBonds(dontFetch) {
|
|
65637
|
-
var _a, _b
|
|
65637
|
+
var _a, _b;
|
|
65638
65638
|
// First fetch the full list of bonds
|
|
65639
65639
|
const { data: bondList } = useBondsList();
|
|
65640
65640
|
const { address } = useEVMAccount();
|
|
65641
65641
|
const { publicKey } = useSOLAccount();
|
|
65642
65642
|
const solanaAccount = publicKey === null || publicKey === void 0 ? void 0 : publicKey.toBase58();
|
|
65643
|
-
const SDKConfig = useSDKConfig();
|
|
65644
65643
|
const { data: tokenPrices } = useTokenPrices();
|
|
65645
|
-
const
|
|
65646
|
-
const apiUrl = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.apiV2;
|
|
65647
|
-
// Once the full list is fetched, fetch user's purchased bonds
|
|
65644
|
+
const queryClient = useQueryClient();
|
|
65648
65645
|
return useQuery({
|
|
65649
|
-
queryKey: [QUERY_KEYS.USER_BONDS, address, publicKey, (
|
|
65650
|
-
queryFn: () => getUserBonds(address, solanaAccount, bondList,
|
|
65646
|
+
queryKey: [QUERY_KEYS.USER_BONDS, address, publicKey, (_b = (_a = Object.keys(tokenPrices !== null && tokenPrices !== void 0 ? tokenPrices : {})) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : null],
|
|
65647
|
+
queryFn: () => getUserBonds(address, solanaAccount, bondList, queryClient),
|
|
65651
65648
|
refetchInterval: 120000, // TODO rollback this
|
|
65652
|
-
enabled: !!bondList && !!(address || solanaAccount) && !!tokenPrices &&
|
|
65649
|
+
enabled: !!bondList && !!(address || solanaAccount) && !!tokenPrices && true,
|
|
65653
65650
|
refetchOnWindowFocus: false,
|
|
65654
65651
|
refetchOnMount: false,
|
|
65655
65652
|
refetchOnReconnect: false,
|
|
65656
65653
|
retry: 1,
|
|
65657
65654
|
});
|
|
65658
65655
|
}
|
|
65659
|
-
const getUserBonds = (account, solanaAccount, bondList,
|
|
65656
|
+
const getUserBonds = (account, solanaAccount, bondList, queryClient) => __awaiter$9(void 0, void 0, void 0, function* () {
|
|
65657
|
+
const { chains, urls } = queryClient === null || queryClient === void 0 ? void 0 : queryClient.getQueryData([QUERY_KEYS.SDK_CONFIG]);
|
|
65658
|
+
const apiUrl = urls['apiV2'];
|
|
65659
|
+
const tokenPrices = queryClient === null || queryClient === void 0 ? void 0 : queryClient.getQueryData([QUERY_KEYS.TOKEN_PRICES]);
|
|
65660
65660
|
try {
|
|
65661
65661
|
console.time('getUserBonds');
|
|
65662
65662
|
const bondsByChain = bondList.reduce((acc, bond) => {
|
|
@@ -74918,10 +74918,9 @@ const SafeHTMLComponent = ({ html }) => {
|
|
|
74918
74918
|
return jsx$2("div", { dangerouslySetInnerHTML: { __html: sanitizedHTML } });
|
|
74919
74919
|
};
|
|
74920
74920
|
|
|
74921
|
-
const YourBondsModal = ({
|
|
74921
|
+
const YourBondsModal = ({ userBill, onDismiss }) => {
|
|
74922
74922
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
|
|
74923
|
-
const {
|
|
74924
|
-
const userBill = userBonds === null || userBonds === void 0 ? void 0 : userBonds.find((bill) => bill.id === billId);
|
|
74923
|
+
const { refetch: refetchUserBonds } = useUserBonds();
|
|
74925
74924
|
// Hooks
|
|
74926
74925
|
const SDKConfig = useSDKConfig();
|
|
74927
74926
|
const chainId = useChainId();
|
|
@@ -75189,7 +75188,7 @@ const UserBondRow = ({ bill }) => {
|
|
|
75189
75188
|
const { writeContractAsync } = useWriteContract();
|
|
75190
75189
|
const { addToastError } = usePopups();
|
|
75191
75190
|
const { refetch: refetchUserBonds } = useUserBonds();
|
|
75192
|
-
const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModal, {
|
|
75191
|
+
const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModal, { userBill: bill }));
|
|
75193
75192
|
// State
|
|
75194
75193
|
const [claimTxHash, setClaimTxHash] = useState(null);
|
|
75195
75194
|
const { isLoading: isConfirming, isSuccess: isConfirmed } = useMonitorTx(claimTxHash, (_a = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _a === void 0 ? void 0 : _a.chainId);
|
|
@@ -75272,20 +75271,19 @@ const UserBondRow = ({ bill }) => {
|
|
|
75272
75271
|
: 'Claim' })) })] })] }));
|
|
75273
75272
|
};
|
|
75274
75273
|
|
|
75275
|
-
const YourBondsModalSolana = ({
|
|
75274
|
+
const YourBondsModalSolana = ({ userBill, onDismiss }) => {
|
|
75276
75275
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
|
|
75277
75276
|
// Hooks
|
|
75278
75277
|
const SDKConfig = useSDKConfig();
|
|
75279
75278
|
const { publicKey: accountSolana, signTransaction } = useSOLAccount();
|
|
75280
75279
|
const { setVisible } = useWalletModal();
|
|
75281
75280
|
const { addToastError, addToastSuccess } = usePopups();
|
|
75282
|
-
const {
|
|
75281
|
+
const { refetch } = useUserBonds();
|
|
75283
75282
|
const connection = new Connection(getRPC(types$1.ChainId.SOL), 'confirmed');
|
|
75284
75283
|
// State
|
|
75285
75284
|
const [imgLoaded, setImgLoaded] = useState(false);
|
|
75286
75285
|
const [loadingTx, setLoadingTx] = useState(false);
|
|
75287
75286
|
// Static Data
|
|
75288
|
-
const userBill = userBonds === null || userBonds === void 0 ? void 0 : userBonds.find((bill) => bill.asset === billId);
|
|
75289
75287
|
const bondNFTData = userBill === null || userBill === void 0 ? void 0 : userBill.nftData;
|
|
75290
75288
|
// Cliff display info:
|
|
75291
75289
|
const vestingCliff = (_a = userBill === null || userBill === void 0 ? void 0 : userBill.bond) === null || _a === void 0 ? void 0 : _a.vestingCliff;
|
|
@@ -75460,7 +75458,7 @@ const UserBondRowSolana = ({ bill }) => {
|
|
|
75460
75458
|
const lastBlockTimestamp = parseInt((_d = bill === null || bill === void 0 ? void 0 : bill.lastBlockTimestamp) !== null && _d !== void 0 ? _d : '0');
|
|
75461
75459
|
const isPendingCliff = vestingCliff ? currentTime - lastBlockTimestamp < vestingCliff : false;
|
|
75462
75460
|
const cliffCountdown = getTimePeriods(lastBlockTimestamp + (vestingCliff !== null && vestingCliff !== void 0 ? vestingCliff : 0) - currentTime, true);
|
|
75463
|
-
const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModalSolana, {
|
|
75461
|
+
const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModalSolana, { userBill: bill }));
|
|
75464
75462
|
const ensureUserPayoutAtaExists = (_a) => __awaiter$9(void 0, [_a], void 0, function* ({ connection, payer, payoutMint, user, }) {
|
|
75465
75463
|
const userPayoutAta = yield getAssociatedTokenAddress(payoutMint, user);
|
|
75466
75464
|
try {
|
|
@@ -85240,9 +85238,9 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
|
|
|
85240
85238
|
usdAmount: parseFloat(inputValue) * ((_h = inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price) !== null && _h !== void 0 ? _h : 0),
|
|
85241
85239
|
},
|
|
85242
85240
|
});
|
|
85243
|
-
// waits
|
|
85244
|
-
yield new Promise((resolve) => setTimeout(resolve,
|
|
85245
|
-
console.timeEnd('
|
|
85241
|
+
// waits 2 seconds before triggering after-purchase flow
|
|
85242
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
85243
|
+
console.timeEnd('2 seconds elapsed. trigger bonds refetch');
|
|
85246
85244
|
addToastSuccess(txId, bondChain);
|
|
85247
85245
|
setBillId === null || setBillId === void 0 ? void 0 : setBillId(nftMint.publicKey.toString());
|
|
85248
85246
|
}
|
|
@@ -85324,11 +85322,16 @@ const ModalHandler = ({ onDismiss, bondAddress, bondChain, }) => {
|
|
|
85324
85322
|
// State
|
|
85325
85323
|
const [billId, setBillId] = useState('');
|
|
85326
85324
|
const [buyTxHash, setBuyTxHash] = useState('');
|
|
85325
|
+
const [userBill, setUserBill] = useState();
|
|
85327
85326
|
// Hooks
|
|
85328
85327
|
const { data: bondsData } = useBondsData();
|
|
85329
|
-
const { refetch } = useUserBonds(true);
|
|
85330
85328
|
const locationPath = window.location.pathname;
|
|
85331
85329
|
const { data: txReceipt } = useMonitorTx(buyTxHash, bondChain);
|
|
85330
|
+
const { address } = useEVMAccount();
|
|
85331
|
+
const { publicKey } = useSOLAccount();
|
|
85332
|
+
const solanaAccount = publicKey === null || publicKey === void 0 ? void 0 : publicKey.toBase58();
|
|
85333
|
+
const { data: bondList } = useBondsList();
|
|
85334
|
+
const queryClient = useQueryClient();
|
|
85332
85335
|
// EVM - Look for billId on tx logs
|
|
85333
85336
|
if (txReceipt) {
|
|
85334
85337
|
try {
|
|
@@ -85356,13 +85359,36 @@ const ModalHandler = ({ onDismiss, bondAddress, bondChain, }) => {
|
|
|
85356
85359
|
if (!hasRefetched.current) {
|
|
85357
85360
|
if (billId) {
|
|
85358
85361
|
console.log('Trigger user bonds refetch');
|
|
85359
|
-
|
|
85362
|
+
const bondToRefetch = bondList === null || bondList === void 0 ? void 0 : bondList.find((bond) => {
|
|
85363
|
+
var _a, _b;
|
|
85364
|
+
return (bondAddress === null || bondAddress === void 0 ? void 0 : bondAddress.toLowerCase()) === ((_b = (_a = bond === null || bond === void 0 ? void 0 : bond.contractAddress) === null || _a === void 0 ? void 0 : _a[bond === null || bond === void 0 ? void 0 : bond.chainId]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) &&
|
|
85365
|
+
bondChain === (bond === null || bond === void 0 ? void 0 : bond.chainId);
|
|
85366
|
+
});
|
|
85367
|
+
if (!bondToRefetch)
|
|
85368
|
+
return;
|
|
85360
85369
|
hasRefetched.current = true;
|
|
85370
|
+
getUserBonds(address, solanaAccount, [bondToRefetch], queryClient)
|
|
85371
|
+
.then((bonds) => {
|
|
85372
|
+
const purchasedBond = bonds.find((bond) => {
|
|
85373
|
+
var _a;
|
|
85374
|
+
if (((_a = bond === null || bond === void 0 ? void 0 : bond.bond) === null || _a === void 0 ? void 0 : _a.chainId) === types$1.ChainId.SOL) {
|
|
85375
|
+
return bond.asset === billId;
|
|
85376
|
+
}
|
|
85377
|
+
else {
|
|
85378
|
+
return bond.id === billId;
|
|
85379
|
+
}
|
|
85380
|
+
});
|
|
85381
|
+
console.log(purchasedBond);
|
|
85382
|
+
setUserBill(purchasedBond);
|
|
85383
|
+
})
|
|
85384
|
+
.catch((e) => {
|
|
85385
|
+
console.error(e);
|
|
85386
|
+
});
|
|
85361
85387
|
}
|
|
85362
85388
|
}
|
|
85363
85389
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
85364
85390
|
}, [billId]);
|
|
85365
|
-
return billId ? (bondChain === types$1.ChainId.SOL ? (jsx$2(YourBondsModalSolana, {
|
|
85391
|
+
return billId ? (bondChain === types$1.ChainId.SOL ? (jsx$2(YourBondsModalSolana, { userBill: userBill, onDismiss: onDismiss })) : (jsx$2(YourBondsModal, { userBill: userBill, onDismiss: onDismiss }))) : (jsx$2(BuyBondModal, { bondAddress: bondAddress, bondChain: bondChain, handlePurchasedBond: setBuyTxHash, setBillId: setBillId, onDismiss: () => {
|
|
85366
85392
|
window.history.pushState({}, '', `${locationPath !== '/bonds' ? locationPath : '/bonds'}`);
|
|
85367
85393
|
onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
|
|
85368
85394
|
} }));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { UseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import { BillsConfig
|
|
1
|
+
import { QueryClient, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { BillsConfig } from '@ape.swap/apeswap-lists';
|
|
3
3
|
import { UserBill } from '../../types/yourbonds';
|
|
4
|
-
import { TokenPrices } from '../tokenPrices/useTokenPrices';
|
|
5
4
|
export default function useUserBonds(dontFetch?: boolean): UseQueryResult<UserBill[]>;
|
|
6
|
-
export declare const getUserBonds: (account: string, solanaAccount: string, bondList: BillsConfig[],
|
|
5
|
+
export declare const getUserBonds: (account: string, solanaAccount: string, bondList: BillsConfig[], queryClient: QueryClient) => Promise<UserBill[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { UserBill } from '../../types/yourbonds';
|
|
3
|
+
declare const YourBondsModal: ({ userBill, onDismiss }: {
|
|
4
|
+
userBill?: UserBill;
|
|
4
5
|
onDismiss?: () => void;
|
|
5
6
|
}) => React.JSX.Element;
|
|
6
7
|
export default YourBondsModal;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { UserBill } from '../../types/yourbonds';
|
|
3
|
+
declare const YourBondsModalSolana: ({ userBill, onDismiss }: {
|
|
4
|
+
userBill?: UserBill;
|
|
4
5
|
onDismiss?: () => void;
|
|
5
6
|
}) => React.JSX.Element;
|
|
6
7
|
export default YourBondsModalSolana;
|