@ape.swap/bonds-sdk 1.0.520 → 1.0.522

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.
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import '../../scss/BondMenu.scss';
3
+ interface BondMenuProps {
4
+ setChainFilterOption: (newValue: string[]) => void;
5
+ chainFilterOption: string[];
6
+ filterOptions: string[];
7
+ filterOption: string;
8
+ setFilterOption: (newOption: string) => void;
9
+ }
10
+ declare const BondMenu: React.FC<BondMenuProps>;
11
+ export default BondMenu;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
2
+ import { useCallback } from 'react';
3
+ import { Flex } from '../uikit-sdk';
4
+ import RecommendationSelector from '../MenuSelect/RecommendationSelector';
5
+ import MenuSelect from '../MenuSelect/MenuSelect';
6
+ import '../../scss/BondMenu.scss';
7
+ import NetworkFilter from '../NetworkFilter';
8
+ var BondMenu = function (_a) {
9
+ var setChainFilterOption = _a.setChainFilterOption, chainFilterOption = _a.chainFilterOption, filterOptions = _a.filterOptions, filterOption = _a.filterOption, setFilterOption = _a.setFilterOption;
10
+ var mappedFilters = filterOptions.map(function (filter) {
11
+ return {
12
+ label: filter.charAt(0).toUpperCase() + filter.slice(1).toLowerCase(),
13
+ value: filter,
14
+ };
15
+ });
16
+ var handleFilterSelection = useCallback(function (newOption) {
17
+ //setChainFilterOption(['All Chains'])
18
+ setFilterOption(newOption);
19
+ }, [setFilterOption]);
20
+ return (_jsxs(Flex, { className: "menu-container filters", children: [_jsx(Flex, { className: "filters network", sx: { width: ['49%', '49%', '49%', 'unset'], minWidth: '120px' }, children: _jsx(NetworkFilter, { chainFilterOption: chainFilterOption, setChainFilterOption: setChainFilterOption }) }), _jsx(Flex, { className: "filters desktop-rec", sx: { display: ['none', 'none', 'none', 'flex'], mr: '20px' }, children: _jsx(RecommendationSelector, { options: filterOptions, activeOption: filterOption, setActiveOption: handleFilterSelection }) }), _jsx(Flex, { className: "filtesr mobile-rec", sx: { display: ['flex', 'flex', 'flex', 'none'], width: '100%' }, children: _jsx(MenuSelect, { selectedOption: filterOption, setOption: setFilterOption, options: mappedFilters, sx: { background: 'white2' } }) })] }));
21
+ };
22
+ export default BondMenu;
@@ -0,0 +1,4 @@
1
+ export default function useChainFilterOption(): {
2
+ data: string[];
3
+ setChainFilterOption: (newValue: string[]) => void;
4
+ };
@@ -0,0 +1,34 @@
1
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
2
+ import { QUERY_KEYS } from '../../config/constants/queryKeys';
3
+ import useCookie from '../../hooks/useCookie';
4
+ import { useCallback } from 'react';
5
+ import { useRouter } from 'next/router';
6
+ export default function useChainFilterOption() {
7
+ var _a;
8
+ var _b = useCookie(QUERY_KEYS.CHAIN_FILTER_OPTION, ['All Chains']), cookie = _b.cookie, updateCookie = _b.updateCookie;
9
+ var data = useQuery({
10
+ queryKey: ["".concat(QUERY_KEYS.CHAIN_FILTER_OPTION)],
11
+ queryFn: function () { return cookie; },
12
+ initialData: cookie,
13
+ }).data;
14
+ var _c = useRouter(), asPath = _c.asPath, query = _c.query, replace = _c.replace, pathname = _c.pathname;
15
+ var urlParams = typeof window !== 'undefined' ? new URLSearchParams(new URL(asPath, window.location.origin).search) : null;
16
+ var urlChain = (_a = urlParams === null || urlParams === void 0 ? void 0 : urlParams.get('chain')) !== null && _a !== void 0 ? _a : '';
17
+ var queryClient = useQueryClient();
18
+ var removeURLChain = useCallback(function () {
19
+ if (urlChain) {
20
+ console.log('remove url');
21
+ delete query.chain;
22
+ replace({
23
+ pathname: pathname,
24
+ query: query,
25
+ }, undefined, { scroll: false });
26
+ }
27
+ }, [urlChain, pathname, query, replace]);
28
+ var setChainFilterOption = useCallback(function (newValue) {
29
+ updateCookie(newValue);
30
+ queryClient.setQueryData(["".concat(QUERY_KEYS.CHAIN_FILTER_OPTION)], newValue);
31
+ removeURLChain();
32
+ }, [updateCookie, queryClient, removeURLChain]);
33
+ return { data: data, setChainFilterOption: setChainFilterOption };
34
+ }
@@ -9,9 +9,5 @@ interface BondRowHeaderProps {
9
9
  onInputChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
10
10
  onSort: (key: 'discount' | 'arr' | 'terms' | 'tokensRemaining') => void;
11
11
  }
12
- export declare enum BondsViewOptions {
13
- BONDSMARKET = "Bonds Market",
14
- YOURBONDS = "Your Bonds"
15
- }
16
12
  declare const BondRowHeader: React.FC<BondRowHeaderProps>;
17
13
  export default BondRowHeader;
@@ -6,13 +6,8 @@ import { Input } from '../uikit-sdk/Input';
6
6
  import { Svg, TooltipBubble } from '../uikit-sdk';
7
7
  import { TooltipText } from '../../enum/tooltips';
8
8
  import '../../scss/BondRowHeader.scss';
9
- import MenuSelect from '../MenuSelect/MenuSelect';
10
- import RecommendationSelector from '../MenuSelect/RecommendationSelector';
11
- export var BondsViewOptions;
12
- (function (BondsViewOptions) {
13
- BondsViewOptions["BONDSMARKET"] = "Bonds Market";
14
- BondsViewOptions["YOURBONDS"] = "Your Bonds";
15
- })(BondsViewOptions || (BondsViewOptions = {}));
9
+ import BondMenu from '../BondMenu/BondMenu';
10
+ import useChainFilterOption from '../BondMenu/useChainFilterOption';
16
11
  var BondRowHeader = function (_a) {
17
12
  var inputValue = _a.inputValue, filterOptions = _a.filterOptions, filterOption = _a.filterOption, setFilterOption = _a.setFilterOption, onInputChange = _a.onInputChange, onSort = _a.onSort;
18
13
  var mappedFilters = filterOptions.map(function (filter) {
@@ -25,18 +20,7 @@ var BondRowHeader = function (_a) {
25
20
  //setChainFilterOption(['All Chains'])
26
21
  setFilterOption(newOption);
27
22
  }, [setFilterOption]);
28
- // const handleChangeNav = useCallback(
29
- // (navOption: string) => {
30
- // if (navOption === BondsViewOptions.BONDSMARKET) {
31
- // setBillsView(BondsViewOptions.BONDSMARKET)
32
- // replace('/bonds', undefined, { shallow: true })
33
- // } else {
34
- // setBillsView(BondsViewOptions.YOURBONDS)
35
- // push('/bonds?yourBonds', undefined, { shallow: true })
36
- // }
37
- // },
38
- // [push, replace, setBillsView],
39
- // )
40
- return (_jsxs(Flex, { className: "header-container", children: [_jsx(Flex, { sx: { width: ['100%', '100%', '100%', '325px'] } }), _jsxs(Flex, { className: "header-container filters", children: [_jsx(Flex, { sx: { display: ['none', 'none', 'none', 'flex'], mr: '20px' }, children: _jsx(RecommendationSelector, { options: filterOptions, activeOption: filterOption, setActiveOption: handleFilterSelection }) }), _jsx(Flex, { sx: { display: ['flex', 'flex', 'flex', 'none'], width: '100%' }, children: _jsx(MenuSelect, { selectedOption: filterOption, setOption: setFilterOption, options: mappedFilters, sx: { background: 'white2' } }) })] }), _jsxs(Flex, { className: "header-container rows", children: [_jsxs(Flex, { className: "column column-tokens", children: [_jsx(Flex, { className: "column column-search", sx: { width: '100%', maxWidth: ['200px', '200px', '200px', '340px'] }, children: _jsx(Input, { value: inputValue, onChange: onInputChange, variant: "search", sx: { fontWeight: 400, background: 'white2', height: '30px', fontSize: '14px', color: 'white' }, width: '100%', placeholder: 'Search...' }) }), _jsx(Flex, { className: "column column-tokenicons" })] }), _jsxs(Flex, { className: "column column-bondinfo", children: [_jsxs(Flex, { className: "column column-discount", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(18%, -4%)", children: ["DISCOUNT", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('discount'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column column-arr", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(8%, -5%)", children: ["ARR", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('arr'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column column-terms", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomRight", transformTip: "translate(11%, -5%)", children: ["TERMS", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('terms'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column column-tokensremaining", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.TokensRemaining }), width: "230px", placement: "bottomRight", transformTip: "translate(12%, -4%)", children: ["TOKENS REMAINING", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('tokensRemaining'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsx(Flex, { className: "column column-hotbond" })] })] })] }));
23
+ var _b = useChainFilterOption(), chainFilterOption = _b.data, setChainFilterOption = _b.setChainFilterOption;
24
+ return (_jsxs(Flex, { className: "header-container", children: [_jsx(Flex, { className: "header-container filters", children: _jsx(BondMenu, { chainFilterOption: chainFilterOption, setChainFilterOption: setChainFilterOption, filterOptions: filterOptions, filterOption: filterOption, setFilterOption: handleFilterSelection }) }), _jsxs(Flex, { className: "header-container rows", children: [_jsxs(Flex, { className: "column column-tokens", children: [_jsx(Flex, { className: "column column-search", sx: { width: '100%', maxWidth: ['200px', '200px', '200px', '340px'] }, children: _jsx(Input, { value: inputValue, onChange: onInputChange, variant: "search", sx: { fontWeight: 400, background: 'white2', height: '30px', fontSize: '14px', color: 'white' }, width: '100%', placeholder: 'Search...' }) }), _jsx(Flex, { className: "column column-tokenicons" })] }), _jsxs(Flex, { className: "column column-bondinfo", children: [_jsxs(Flex, { className: "column column-discount", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(18%, -4%)", children: ["DISCOUNT", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('discount'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column column-arr", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(8%, -5%)", children: ["ARR", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('arr'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column column-terms", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomRight", transformTip: "translate(11%, -5%)", children: ["TERMS", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('terms'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsxs(Flex, { className: "column column-tokensremaining", children: [_jsx(Flex, { className: "column tooltip", children: _jsxs(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.TokensRemaining }), width: "230px", placement: "bottomRight", transformTip: "translate(12%, -4%)", children: ["TOKENS REMAINING", _jsx(Flex, { className: "column header-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px", color: "textDisabledButton" }) })] }) }), _jsx(Flex, { className: "column header-icon", onClick: function () { return onSort('tokensRemaining'); }, children: _jsx(Svg, { icon: "sort", width: "12px", color: "textDisabledButton" }) })] }), _jsx(Flex, { className: "column column-hotbond" })] })] })] }));
41
25
  };
42
26
  export default BondRowHeader;
@@ -0,0 +1,9 @@
1
+ interface UseCookieOptions {
2
+ expires?: number;
3
+ }
4
+ declare function useCookie<T>(key: string, defaultValue: T): {
5
+ cookie: T;
6
+ updateCookie: (value: T, options?: UseCookieOptions) => void;
7
+ removeCookie: () => void;
8
+ };
9
+ export default useCookie;
@@ -0,0 +1,29 @@
1
+ import { useCallback, useState } from 'react';
2
+ function useCookie(key, defaultValue) {
3
+ var getCookie = function () {
4
+ var cookie = typeof window !== 'undefined' ? window.document.cookie.split('; ').find(function (row) { return row.startsWith(key); }) : null;
5
+ if (cookie)
6
+ return JSON.parse(cookie.slice(key.length + 1));
7
+ return defaultValue;
8
+ };
9
+ var _a = useState(getCookie), cookie = _a[0], setCookieState = _a[1];
10
+ var updateCookie = useCallback(function (value) {
11
+ if (typeof window === 'undefined')
12
+ return;
13
+ var defaultExpiry = 6 * 30; // Default to approximately six months
14
+ var str = "".concat(key, "=").concat(JSON.stringify(value));
15
+ var date = new Date();
16
+ date.setTime(date.getTime() + defaultExpiry * 24 * 60 * 60 * 1000);
17
+ str += "; expires=".concat(date.toUTCString());
18
+ window.document.cookie = str;
19
+ setCookieState(value);
20
+ }, [key]);
21
+ var removeCookie = useCallback(function () {
22
+ if (typeof window === 'undefined')
23
+ return;
24
+ document.cookie = "".concat(key, "=; Expires=Thu, 01 Jan 1970 00:00:01 GMT;");
25
+ setCookieState(defaultValue);
26
+ }, [defaultValue, key]);
27
+ return { cookie: cookie, updateCookie: updateCookie, removeCookie: removeCookie };
28
+ }
29
+ export default useCookie;
@@ -113,18 +113,13 @@ var YourBonds = function (_a) {
113
113
  return __generator(this, function (_a) {
114
114
  switch (_a.label) {
115
115
  case 0:
116
- console.log("ACCOUNT");
117
- console.log(account);
118
- if (!account) return [3 /*break*/, 4];
116
+ if (!(account && bondData)) return [3 /*break*/, 4];
119
117
  _a.label = 1;
120
118
  case 1:
121
119
  _a.trys.push([1, 3, , 4]);
122
120
  return [4 /*yield*/, Promise.all(MAINNET_CHAINS.map(function (chain) { return fetchUserOwnedBillsDataAsync(chain, account, bondData); }))];
123
121
  case 2:
124
122
  results = _a.sent();
125
- console.log('RESULTS-----');
126
- console.log(results);
127
- console.log('-----');
128
123
  mappedBills = results.flat().flatMap(function (results) { return results.userOwnedBills; });
129
124
  setMappedUserBills(mappedBills);
130
125
  console.log('User owned bills data:', mappedBills);
@@ -138,7 +133,7 @@ var YourBonds = function (_a) {
138
133
  });
139
134
  }); };
140
135
  fetchData();
141
- }, [account]);
136
+ }, [account, bondData]);
142
137
  var _f = useState(null), sortConfig = _f[0], setSortConfig = _f[1];
143
138
  var _g = useState(mappedUserBills), sortedBonds = _g[0], setSortedBonds = _g[1];
144
139
  var handleSort = function (key) {
@@ -0,0 +1,22 @@
1
+ .menu-container.filters {
2
+ display: flex;
3
+ justify-content: space-around;
4
+ align-items: center;
5
+ flex-direction: row;
6
+ width: 100%;
7
+ }
8
+
9
+ .filters.network {
10
+ display: flex;
11
+ width: 100%
12
+ }
13
+
14
+ .filters.desktop-rec {
15
+ display: flex;
16
+ width: 100%
17
+ }
18
+
19
+ .filters.mobile-rec {
20
+ display: flex;
21
+ width: 100%
22
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ape Bond SDK",
4
4
  "author": "Ape Bond",
5
5
  "license": "MIT",
6
- "version": "1.0.520",
6
+ "version": "1.0.522",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- declare const Toggle: ({ options, activeOption, handleToggle, }: {
3
- options: string[];
4
- activeOption: string;
5
- handleToggle: (newOption: string) => void;
6
- }) => React.JSX.Element;
7
- export default Toggle;
@@ -1,44 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsx as _jsx } from "theme-ui/jsx-runtime";
13
- import styles from './styles';
14
- import Text from '../Text';
15
- import Flex from '../Flex';
16
- import { AnimatePresence, motion } from 'framer-motion';
17
- // import { useBills } from 'state/bills/hooks'
18
- // import { BondsViewOptions } from '../../../views/Bonds/BondsListView'
19
- // import useRefresh from '../../../hooks/useRefresh'
20
- var Toggle = function (_a) {
21
- // const bills = useBills()
22
- // const { fastRefresh } = useRefresh()
23
- // const claimableBillsAmount = useMemo(() => {
24
- // return bills
25
- // ?.filter((bill) => (bill?.userOwnedBillsData?.length ?? 0) > 0)
26
- // ?.map((bill) => {
27
- // return {
28
- // billIds: bill.userOwnedBillsData
29
- // ?.filter((b) => parseFloat(b.pendingRewards) > 0)
30
- // .map((b) => {
31
- // return b.id
32
- // }),
33
- // }
34
- // })
35
- // ?.filter((bill) => bill?.billIds?.length ?? 0 > 0)
36
- // ?.reduce((total, ownerBills) => total + (ownerBills.billIds?.length || 0), 0)
37
- // /* eslint-disable react-hooks/exhaustive-deps */
38
- // }, [fastRefresh])
39
- var options = _a.options, activeOption = _a.activeOption, handleToggle = _a.handleToggle;
40
- return (_jsx(Flex, { sx: styles.container, children: _jsx(AnimatePresence, { initial: false, children: options.map(function (option) {
41
- return (_jsx(motion.div, { animate: { opacity: option === activeOption ? 1 : 0.6, scale: option === activeOption ? 1 : 0.9 }, exit: { opacity: 0, scale: 0.9 }, transition: { duration: 0.2, type: 'spring', stiffness: 50 }, sx: { overflow: 'hidden', width: '100%' }, children: _jsx(Flex, { sx: __assign(__assign({}, styles.switch), { background: option === activeOption ? 'primaryButton' : 'white2' }), onClick: function () { return handleToggle(option); }, children: _jsx(Text, { sx: { fontSize: '14px' }, children: option }) }) }, option));
42
- }) }) }));
43
- };
44
- export default Toggle;
@@ -1,3 +0,0 @@
1
- import { ThemeUIStyleObject } from 'theme-ui';
2
- declare const styles: Record<string, ThemeUIStyleObject>;
3
- export default styles;
@@ -1,40 +0,0 @@
1
- var styles = {
2
- container: {
3
- display: 'flex',
4
- borderRadius: '10px',
5
- background: 'white2',
6
- width: '100%',
7
- position: 'relative',
8
- },
9
- switch: {
10
- borderRadius: '10px',
11
- color: 'primaryButtonDisable',
12
- justifyContent: 'center',
13
- px: '14px',
14
- py: '5px',
15
- cursor: 'pointer',
16
- '&:hover': {
17
- filter: '20%',
18
- },
19
- },
20
- button: {
21
- position: 'absolute',
22
- border: 0,
23
- top: 0,
24
- height: '100%',
25
- transition: 'left 0.2s linear',
26
- textTransform: 'none',
27
- '&:hover': {
28
- filter: 'none',
29
- },
30
- },
31
- input: {
32
- bottom: 0,
33
- left: 0,
34
- position: 'absolute',
35
- opacity: 0,
36
- pointerEvents: 'none',
37
- width: '100%',
38
- },
39
- };
40
- export default styles;