@ape.swap/bonds-sdk 4.1.0-test.11 → 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;
|
|
@@ -75445,6 +75443,7 @@ const YourBondsModalSolana = ({ billId, onDismiss }) => {
|
|
|
75445
75443
|
const UserBondRowSolana = ({ bill }) => {
|
|
75446
75444
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
75447
75445
|
// Hooks
|
|
75446
|
+
const SDKConfig = useSDKConfig();
|
|
75448
75447
|
const { setVisible } = useWalletModal();
|
|
75449
75448
|
const { publicKey: accountSolana, signTransaction } = useSOLAccount();
|
|
75450
75449
|
const { addToastError, addToastSuccess } = usePopups();
|
|
@@ -75459,7 +75458,7 @@ const UserBondRowSolana = ({ bill }) => {
|
|
|
75459
75458
|
const lastBlockTimestamp = parseInt((_d = bill === null || bill === void 0 ? void 0 : bill.lastBlockTimestamp) !== null && _d !== void 0 ? _d : '0');
|
|
75460
75459
|
const isPendingCliff = vestingCliff ? currentTime - lastBlockTimestamp < vestingCliff : false;
|
|
75461
75460
|
const cliffCountdown = getTimePeriods(lastBlockTimestamp + (vestingCliff !== null && vestingCliff !== void 0 ? vestingCliff : 0) - currentTime, true);
|
|
75462
|
-
const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModalSolana, {
|
|
75461
|
+
const [onOpenPurchasedBond] = useModal(jsx$2(YourBondsModalSolana, { userBill: bill }));
|
|
75463
75462
|
const ensureUserPayoutAtaExists = (_a) => __awaiter$9(void 0, [_a], void 0, function* ({ connection, payer, payoutMint, user, }) {
|
|
75464
75463
|
const userPayoutAta = yield getAssociatedTokenAddress(payoutMint, user);
|
|
75465
75464
|
try {
|
|
@@ -75490,7 +75489,7 @@ const UserBondRowSolana = ({ bill }) => {
|
|
|
75490
75489
|
return userPayoutAta;
|
|
75491
75490
|
});
|
|
75492
75491
|
const handleClaim = () => __awaiter$9(void 0, void 0, void 0, function* () {
|
|
75493
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
75492
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
75494
75493
|
try {
|
|
75495
75494
|
setLoadingTx(true);
|
|
75496
75495
|
const earnTokenAddress = (_c = (_b = (_a = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _a === void 0 ? void 0 : _a.earnToken) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c[(_d = bill === null || bill === void 0 ? void 0 : bill.bond) === null || _d === void 0 ? void 0 : _d.chainId];
|
|
@@ -75558,6 +75557,11 @@ const UserBondRowSolana = ({ bill }) => {
|
|
|
75558
75557
|
catch (error) {
|
|
75559
75558
|
console.error('Claim failed:', error);
|
|
75560
75559
|
addToastError((_k = error === null || error === void 0 ? void 0 : error.message) !== null && _k !== void 0 ? _k : 'Unknown error');
|
|
75560
|
+
reportError({
|
|
75561
|
+
apiUrl: (_l = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _l === void 0 ? void 0 : _l.apiV2,
|
|
75562
|
+
error,
|
|
75563
|
+
extraInfo: { type: 'claim', bill, error },
|
|
75564
|
+
});
|
|
75561
75565
|
}
|
|
75562
75566
|
finally {
|
|
75563
75567
|
setLoadingTx(false);
|
|
@@ -85111,7 +85115,7 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
|
|
|
85111
85115
|
setInputTokenString(newInputToken);
|
|
85112
85116
|
}, []);
|
|
85113
85117
|
const handleBuyCallback = () => __awaiter$9(void 0, void 0, void 0, function* () {
|
|
85114
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
85118
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
85115
85119
|
if (!accountSolana || !bondData || !inputValue || !inputToken || !bondData)
|
|
85116
85120
|
return;
|
|
85117
85121
|
track({
|
|
@@ -85213,30 +85217,30 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
|
|
|
85213
85217
|
blockhash,
|
|
85214
85218
|
lastValidBlockHeight,
|
|
85215
85219
|
}, 'confirmed');
|
|
85216
|
-
|
|
85217
|
-
|
|
85218
|
-
|
|
85219
|
-
|
|
85220
|
-
|
|
85221
|
-
|
|
85222
|
-
|
|
85220
|
+
console.log('tx confirmed');
|
|
85221
|
+
// axios
|
|
85222
|
+
// .post(`${SDKConfig?.urls?.apiV2}/bills/solana/ingest`, {
|
|
85223
|
+
// signature: txId,
|
|
85224
|
+
// })
|
|
85225
|
+
// .catch((e) => {
|
|
85226
|
+
// console.error(e)
|
|
85227
|
+
// })
|
|
85223
85228
|
track({
|
|
85224
85229
|
event: 'bond',
|
|
85225
85230
|
chain: bondChain,
|
|
85226
85231
|
data: {
|
|
85227
85232
|
cat: 'lp-buy',
|
|
85228
|
-
type: (
|
|
85233
|
+
type: (_d = bondData === null || bondData === void 0 ? void 0 : bondData.billType) !== null && _d !== void 0 ? _d : '',
|
|
85229
85234
|
typedValue: inputValue,
|
|
85230
|
-
principalToken: (
|
|
85231
|
-
earnToken: (
|
|
85232
|
-
address: remove0xPrefix((
|
|
85233
|
-
usdAmount: parseFloat(inputValue) * ((
|
|
85235
|
+
principalToken: (_e = bondData === null || bondData === void 0 ? void 0 : bondData.lpToken.symbol) !== null && _e !== void 0 ? _e : '',
|
|
85236
|
+
earnToken: (_f = bondData === null || bondData === void 0 ? void 0 : bondData.earnToken.symbol) !== null && _f !== void 0 ? _f : '',
|
|
85237
|
+
address: remove0xPrefix((_g = bondData === null || bondData === void 0 ? void 0 : bondData.contractAddress) === null || _g === void 0 ? void 0 : _g[bondData.chainId]),
|
|
85238
|
+
usdAmount: parseFloat(inputValue) * ((_h = inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price) !== null && _h !== void 0 ? _h : 0),
|
|
85234
85239
|
},
|
|
85235
85240
|
});
|
|
85236
|
-
|
|
85237
|
-
|
|
85238
|
-
|
|
85239
|
-
console.timeEnd('asd');
|
|
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');
|
|
85240
85244
|
addToastSuccess(txId, bondChain);
|
|
85241
85245
|
setBillId === null || setBillId === void 0 ? void 0 : setBillId(nftMint.publicKey.toString());
|
|
85242
85246
|
}
|
|
@@ -85244,7 +85248,7 @@ const BuyComponentSolana = ({ onDismiss, bondAddress, bondChain, isProjectView,
|
|
|
85244
85248
|
console.error('Error during bond purchase:', error);
|
|
85245
85249
|
addToastError((error === null || error === void 0 ? void 0 : error.message) || 'Unknown error');
|
|
85246
85250
|
reportError$1({
|
|
85247
|
-
apiUrl: (
|
|
85251
|
+
apiUrl: (_j = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _j === void 0 ? void 0 : _j.apiV2,
|
|
85248
85252
|
error: error.message,
|
|
85249
85253
|
extraInfo: { type: 'solanaBuyBond', error: error.message },
|
|
85250
85254
|
chainId: bondChain,
|
|
@@ -85318,11 +85322,16 @@ const ModalHandler = ({ onDismiss, bondAddress, bondChain, }) => {
|
|
|
85318
85322
|
// State
|
|
85319
85323
|
const [billId, setBillId] = useState('');
|
|
85320
85324
|
const [buyTxHash, setBuyTxHash] = useState('');
|
|
85325
|
+
const [userBill, setUserBill] = useState();
|
|
85321
85326
|
// Hooks
|
|
85322
85327
|
const { data: bondsData } = useBondsData();
|
|
85323
|
-
const { refetch } = useUserBonds(true);
|
|
85324
85328
|
const locationPath = window.location.pathname;
|
|
85325
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();
|
|
85326
85335
|
// EVM - Look for billId on tx logs
|
|
85327
85336
|
if (txReceipt) {
|
|
85328
85337
|
try {
|
|
@@ -85350,13 +85359,36 @@ const ModalHandler = ({ onDismiss, bondAddress, bondChain, }) => {
|
|
|
85350
85359
|
if (!hasRefetched.current) {
|
|
85351
85360
|
if (billId) {
|
|
85352
85361
|
console.log('Trigger user bonds refetch');
|
|
85353
|
-
|
|
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;
|
|
85354
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
|
+
});
|
|
85355
85387
|
}
|
|
85356
85388
|
}
|
|
85357
85389
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
85358
85390
|
}, [billId]);
|
|
85359
|
-
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: () => {
|
|
85360
85392
|
window.history.pushState({}, '', `${locationPath !== '/bonds' ? locationPath : '/bonds'}`);
|
|
85361
85393
|
onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
|
|
85362
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;
|