Skip to content

Commit

Permalink
feat: update gardenfi packages, modify functions according to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Jan 6, 2025
1 parent 7bd30c6 commit 39711f2
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 95 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
"@fontsource/inter": "^5.0.18",
"@fontsource/onest": "^5.0.3",
"@fontsource/poppins": "^5.0.8",
"@gardenfi/core": "0.3.0-beta.14",
"@gardenfi/orderbook": "0.2.0-beta.41",
"@gardenfi/react-hooks": "0.0.1-beta.135",
"@gardenfi/core": "2.0.1",
"@gardenfi/orderbook": "2.0.0",
"@gardenfi/react-hooks": "2.0.0",
"@gardenfi/utils": "2.0.0",
"@gemwallet/api": "^3.8.0",
"@ledgerhq/hw-app-xrp": "^6.29.4",
"@ledgerhq/hw-transport-webusb": "^6.28.6",
Expand All @@ -50,7 +51,7 @@
"concurrently": "^8.2.2",
"d3": "^7.9.0",
"decimal.js": "^10.4.3",
"dlc-btc-lib": "2.5.3",
"dlc-btc-lib": "2.5.5",
"dotenv": "^16.3.1",
"ethers": "5.7.2",
"formik": "^2.4.5",
Expand All @@ -68,9 +69,9 @@
"redux": "^4.2.1",
"redux-persist": "^6.0.0",
"redux-persist-expire": "^1.1.1",
"viem": "2.x",
"vite-plugin-toml": "^0.7.0",
"wagmi": "2.14.3",
"viem": "^2.21.15",
"wagmi": "^2.12.16",
"xrpl": "^4.0.0"
},
"devDependencies": {
Expand Down
11 changes: 3 additions & 8 deletions src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AppLayout } from '@components/app.layout';
import { MerchantDetails } from '@components/proof-of-reserve/components/merchant-details/merchant-details';
import { SwapPage } from '@components/swap/pages/swap-page';
import { getWagmiConfiguration } from '@functions/configuration.functions';
import { GardenProvider, environment } from '@gardenfi/react-hooks';
import { AttestorDetailsPage } from '@pages/attestor-details/attestor-details-page';
import { AttestorDetailsSelectPage } from '@pages/attestor-details/attestor-details-select-page';
import { MyVaults } from '@pages/my-vaults/my-vaults';
Expand All @@ -18,6 +17,7 @@ import { NetworkConfigurationContextProvider } from '@providers/network-configur
import { NetworkConnectionContextProvider } from '@providers/network-connection.provider';
import { ProofOfReserveContextProvider } from '@providers/proof-of-reserve-context-provider';
import { RippleNetworkConfigurationContextProvider } from '@providers/ripple-network-configuration.provider';
import { SwapContextProvider } from '@providers/swap-context-provider';
import { XRPWalletContextProvider } from '@providers/xrp-wallet-context-provider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { WagmiProvider } from 'wagmi';
Expand All @@ -33,12 +33,7 @@ export function App(): React.JSX.Element {
return (
<WagmiProvider config={wagmiConfiguration}>
<QueryClientProvider client={queryClient}>
<GardenProvider
config={{
store: localStorage,
environment: environment.testnet,
}}
>
<SwapContextProvider>
<NetworkConfigurationContextProvider>
<RippleNetworkConfigurationContextProvider>
<EthereumNetworkConfigurationContextProvider>
Expand Down Expand Up @@ -76,7 +71,7 @@ export function App(): React.JSX.Element {
</EthereumNetworkConfigurationContextProvider>
</RippleNetworkConfigurationContextProvider>
</NetworkConfigurationContextProvider>
</GardenProvider>
</SwapContextProvider>
</QueryClientProvider>
</WagmiProvider>
);
Expand Down
33 changes: 19 additions & 14 deletions src/app/components/swap/swap.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useEffect } from 'react';

import { CheckCircleIcon, ChevronDownIcon, ChevronUpIcon } from '@chakra-ui/icons';
import { Button, HStack, Input, Spinner, Text, VStack } from '@chakra-ui/react';
import { useBitcoinPrice } from '@hooks/use-bitcoin-price';
Expand Down Expand Up @@ -37,6 +39,12 @@ export function Swap(): React.JSX.Element {

const { bitcoinPrice } = useBitcoinPrice();

useEffect(() => {
console.log('isProcessing', isProcessing);

Check warning on line 43 in src/app/components/swap/swap.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
console.log('isCompleted', isCompleted);

Check warning on line 44 in src/app/components/swap/swap.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
console.log('quoteError', quoteError);

Check warning on line 45 in src/app/components/swap/swap.tsx

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
}, [isProcessing, isCompleted, quoteError]);

return (
<VStack
alignItems={'flex-start'}
Expand Down Expand Up @@ -130,19 +138,17 @@ export function Swap(): React.JSX.Element {
/>
</>
)}
{isQuoteLoading ||
(isProcessing && (
<HStack w={'100%'} justifyContent={'start'} spacing={'15px'}>
<Spinner color={'white'} size={'sm'} />
<Text color={'white'}>Loading</Text>
</HStack>
))}
{quoteError ||
(swapError && (
<HStack w={'100%'} justifyContent={'start'} spacing={'15px'}>
<Text color={'red'}>{`Error: ${quoteError ? quoteError : swapError}`}</Text>
</HStack>
))}
{(isQuoteLoading || isProcessing) && (
<HStack w={'100%'} justifyContent={'start'} spacing={'15px'}>
<Spinner color={'white'} size={'sm'} />
<Text color={'white'}>Loading</Text>
</HStack>
)}
{(quoteError || swapError) && (
<HStack w={'100%'} justifyContent={'start'} spacing={'15px'}>
<Text color={'red'}>{quoteError || swapError}</Text>
</HStack>
)}
{isCompleted && (
<HStack w={'100%'} justifyContent={'start'} spacing={'15px'}>
<Text
Expand All @@ -152,7 +158,6 @@ export function Swap(): React.JSX.Element {
</HStack>
)}
</VStack>

<VStack w={'100%'} alignItems={'flex-start'}>
<Text color={'white'} fontWeight={'600'}>
{`${outputToken.symbol === 'BTC' ? 'Receive' : 'Refund'}`} Address
Expand Down
8 changes: 5 additions & 3 deletions src/app/hooks/use-swap-order-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OrderStatus, ParseOrderStatus } from '@gardenfi/core';
import { Chain, MatchedOrder } from '@gardenfi/orderbook';
import { GARDEN_CONFIG } from '@gardenfi/react-hooks';

async function fetchJson<T>(url: string, options?: RequestInit): Promise<T> {
async function fetchJSON<T>(url: string, options?: RequestInit): Promise<T> {
const response = await fetch(url, {
headers: { 'Content-Type': 'application/json' },
...options,
Expand Down Expand Up @@ -54,10 +54,10 @@ export const useOrderStatus = (order: MatchedOrder): OrderStatus | undefined =>
useEffect(() => {
const fetchBlockNumbers = async () => {
try {
const data = await fetchJson<Record<Chain, number>>(
const currentBlockNumbers = await fetchJSON<Record<Chain, number>>(
createAPI(isTestnet).data.blockNumbers('testnet')
);
setBlockNumbers(data);
setBlockNumbers(currentBlockNumbers);
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to fetch Block Numbers:', error);
Expand All @@ -72,12 +72,14 @@ export const useOrderStatus = (order: MatchedOrder): OrderStatus | undefined =>
if (!blockNumbers) return;

const { source_swap, destination_swap } = order;

const sourceBlockNumber = blockNumbers[source_swap.chain];
const destinationBlockNumber = blockNumbers[destination_swap.chain];

if (!sourceBlockNumber || !destinationBlockNumber) return;

const orderStatus = ParseOrderStatus(order, sourceBlockNumber, destinationBlockNumber);

setStatus(orderStatus);
}, [blockNumbers, order]);

Expand Down
34 changes: 8 additions & 26 deletions src/app/hooks/use-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ enum SupportedEVMNetworks {
}

const SUPPORTED_ASSETS_BTC_MAP = {
mainnet: SupportedAssets.mainnet.bitcoin_primary,
testnet: SupportedAssets.testnet.bitcoin_testnet_primary,
devnet: SupportedAssets.testnet.bitcoin_testnet_primary,
localhost: SupportedAssets.testnet.bitcoin_testnet_primary,
mainnet: SupportedAssets.mainnet.bitcoin_BTC,
testnet: SupportedAssets.testnet.bitcoin_testnet_BTC,
devnet: SupportedAssets.testnet.bitcoin_testnet_BTC,
localhost: SupportedAssets.testnet.bitcoin_testnet_BTC,
};

const SUPPORTED_ASSETS_IBTC_MAP = {
[SupportedEVMNetworks.ArbitrumSepolia]:
SupportedAssets.testnet.arbitrum_sepolia_0xdfe6d9363ee96152d39391009a6723819d9e25eb,
[SupportedEVMNetworks.BaseSepolia]:
SupportedAssets.testnet.base_sepolia_0xbcdad29ac77e5bb27fd528ab0045af630259fe4f,
[SupportedEVMNetworks.ArbitrumSepolia]: SupportedAssets.testnet.arbitrum_sepolia_iBTC,
[SupportedEVMNetworks.BaseSepolia]: SupportedAssets.testnet.base_sepolia_iBTC,
};

function useDebounce<T>(value: T, delay: number): T {
Expand Down Expand Up @@ -70,7 +68,7 @@ interface UseSwapReturnType {
}

export function useSwap(): UseSwapReturnType {
const { initializeSecretManager, swapAndInitiate, getQuote } = useGarden();
const { swapAndInitiate, getQuote } = useGarden();

const [inputToken, setInputToken] = useState<Asset>(
SUPPORTED_ASSETS_IBTC_MAP[SupportedEVMNetworks.ArbitrumSepolia]
Expand Down Expand Up @@ -139,7 +137,7 @@ export function useSwap(): UseSwapReturnType {
amount: sendAmount,
});

setOutputAmount(unshiftValue(new Decimal(amount).toNumber()).toString()); // Assuming 8 decimals for BTC
setOutputAmount(unshiftValue(new Decimal(amount).toNumber()).toString());
} catch (error) {
setQuoteError(error instanceof Error ? error.message : 'Failed to fetch quote');
setOutputAmount('0');
Expand All @@ -152,20 +150,6 @@ export function useSwap(): UseSwapReturnType {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedInputAmount, inputToken, outputToken, getQuote]);

const initializeSecret = async () => {
if (!initializeSecretManager) {
throw new Error('Secret Manager initializer not available');
}

const response = await initializeSecretManager();

if (!response.ok || !response.val.getMasterPrivKey()) {
throw new Error('Failed to initialize Secret Manager');
}

return response;
};

const fetchQuote = async (quoteParams: QuoteParams) => {
if (!getQuote) {
throw new Error('Quote service not available');
Expand Down Expand Up @@ -205,8 +189,6 @@ export function useSwap(): UseSwapReturnType {
return;
}

await initializeSecret();

const sendAmount = shiftValue(new Decimal(inputAmount).toNumber());

const { strategy, amount } = await fetchQuote({
Expand Down
29 changes: 29 additions & 0 deletions src/app/providers/swap-context-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

import { GardenProvider } from '@gardenfi/react-hooks';
import { Environment } from '@gardenfi/utils';
import { HasChildren } from '@models/has-children';
import { useWalletClient } from 'wagmi';

const SWAP_ENVIRONMENT_MAP = {
mainnet: Environment.MAINNET,
testnet: Environment.TESTNET,
devnet: Environment.TESTNET,
localhost: Environment.TESTNET,
};

export function SwapContextProvider({ children }: HasChildren): React.JSX.Element {
const { data: walletClient } = useWalletClient();

return (
<GardenProvider
config={{
store: localStorage,
environment: SWAP_ENVIRONMENT_MAP[appConfiguration.appEnvironment],
walletClient: walletClient,
}}
>
{children}
</GardenProvider>
);
}
61 changes: 23 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1932,52 +1932,52 @@
resolved "https://registry.npmjs.org/@fontsource/poppins/-/poppins-5.0.12.tgz"
integrity sha512-0qzBxtIJLh82iMJ9pCXKYwGs1zyS+jyUmwVJ59+JdYnEaFVkDsxVOk9yDWfVOs14ALUneodU2m5YSGma6dCYCw==

"@gardenfi/core@0.3.0-beta.14", "@gardenfi/core@^0.3.0-beta.14":
version "0.3.0-beta.14"
resolved "https://registry.yarnpkg.com/@gardenfi/core/-/core-0.3.0-beta.14.tgz#e66599cff3ddb4584648d628dbae02d4aa3836a6"
integrity sha512-V73jDvdchN09UqYdcyOCI4s4ekHY94NLoGnxqp2579y6sSYjqJf+5WXyn89Pb7bjrCOpYOfldivWKXYfwfLkWQ==
"@gardenfi/core@2.0.1", "@gardenfi/core@^2.0.0":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@gardenfi/core/-/core-2.0.1.tgz#987a49267c08c1f8b7951d1c6a0c15d2dd14328d"
integrity sha512-EQrLsJPpagUwqV85f/eNUi8uEWe/4oXE560rX8u1SCfaZM2MAeaat3+K6yUjWTkSuuR0gUQlga0TnTj2Zb76og==
dependencies:
"@catalogfi/utils" "^0.1.6"
"@catalogfi/wallets" "^0.2.51"
"@gardenfi/orderbook" "^0.2.0-beta.41"
"@gardenfi/utils" "^0.0.1-beta.19"
"@gardenfi/orderbook" "^2.0.0"
"@gardenfi/utils" "^2.0.0"
bignumber.js "^9.1.2"
bitcoinjs-lib "^6.1.6"
tiny-secp256k1 "^2.2.3"
varuint-bitcoin "^1.1.2"
viem "^2.21.15"

"@gardenfi/orderbook@0.2.0-beta.41", "@gardenfi/orderbook@^0.2.0-beta.41":
version "0.2.0-beta.41"
resolved "https://registry.yarnpkg.com/@gardenfi/orderbook/-/orderbook-0.2.0-beta.41.tgz#a802ddba48023956160fa2d2fda0676c520a5dbb"
integrity sha512-I8GisEgUGNX84WKZSKEAqMsSD9wvfY9hzY5iL2V5vc+jqblpc+5Exbk/yVFINI3DoqtuaVb1h/dqTmMFotu0hA==
"@gardenfi/[email protected].0", "@gardenfi/orderbook@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@gardenfi/orderbook/-/orderbook-2.0.0.tgz#d13b3d3e8667245a8b1ffe52e262e0b83ad33359"
integrity sha512-mNBhgrpCRkMP9far0883hZ1eECBujioyc+joetHuhRJ//dOzWvHSaEP+uxdb4WNhcWahb6ZbHLa7+FBa3+DdJQ==
dependencies:
"@catalogfi/utils" "^0.1.6"
"@gardenfi/utils" "^0.0.1-beta.19"
"@gardenfi/utils" "^2.0.0"
bufferutil "^4.0.8"
siwe "^2.1.4"
utf-8-validate "^6.0.3"
viem "^2.21.15"
ws "^8.14.2"

"@gardenfi/react-hooks@0.0.1-beta.135":
version "0.0.1-beta.135"
resolved "https://registry.yarnpkg.com/@gardenfi/react-hooks/-/react-hooks-0.0.1-beta.135.tgz#a74d538b455b4a2baff1401eb65c4ea42e194c80"
integrity sha512-I4R391jusGV30K8s+6cDgc7xwAcwj1rUeg2Uw3a/N96KjO2f0l+cn8NQZsSIcJMzL4GTgICpQv2Ci/JIe0VdbQ==
"@gardenfi/react-hooks@2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@gardenfi/react-hooks/-/react-hooks-2.0.0.tgz#03d7c3d6fd982adb21901b04ded2f8f3ffe557cd"
integrity sha512-lG14FCBM09p84PVSld2k1x091uEE4oUjJUcUgHItSvTwy3x7rvRbj4jEoeYdq4gyTmLMCYRWOFOjA+HKkTIadg==
dependencies:
"@catalogfi/utils" "^0.1.6"
"@catalogfi/wallets" "^0.2.51"
"@gardenfi/core" "^0.3.0-beta.14"
"@gardenfi/orderbook" "^0.2.0-beta.41"
"@gardenfi/utils" "^0.0.1-beta.19"
"@gardenfi/core" "^2.0.0"
"@gardenfi/orderbook" "^2.0.0"
"@gardenfi/utils" "^2.0.0"
react "^18.3.1"
viem "^2.21.15"
wagmi "^2.12.16"

"@gardenfi/utils@^0.0.1-beta.19":
version "0.0.1-beta.19"
resolved "https://registry.yarnpkg.com/@gardenfi/utils/-/utils-0.0.1-beta.19.tgz#e74cdc12ff04bed142ebedc32f063daec145ef06"
integrity sha512-hgTc3iy2TM7Rr2J7ApM+yzSOSsisHW3T3+PKMWcBZcc4CIwBAquTCRdQNkMKFbawsvB4LMieIiWYWjm+IQqckQ==
"@gardenfi/utils@2.0.0", "@gardenfi/utils@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@gardenfi/utils/-/utils-2.0.0.tgz#2d68dae3ebc7d0bc4fdcec74af50b714cdc0338b"
integrity sha512-J0q0L76+hIi+N6QOWko8idizxuo2fTNs9fGMxwXkpA1pQigHdSdBbdYg8GmJQhZk0a1tim8D6mjB6GaOIx0xEA==
dependencies:
"@catalogfi/utils" "^0.1.11"
axios "^1.7.2"
Expand Down Expand Up @@ -9388,21 +9388,6 @@ [email protected], varuint-bitcoin@^1.0.4, varuint-bitcoin@^1.1.2:
dependencies:
safe-buffer "^5.1.1"

[email protected]:
version "2.21.57"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.21.57.tgz#bedbb444bb42e07ccc2264a9a0441903a113aab8"
integrity sha512-Mw4f4Dw0+Y/wSHdynVmP4uh+Cw15HEoj8BOKvKH5nGA6oFZYRxSy9Ruu7ZG8jexeAVCZ57aIuXb0gNg6Vb1x0g==
dependencies:
"@noble/curves" "1.7.0"
"@noble/hashes" "1.6.1"
"@scure/bip32" "1.6.0"
"@scure/bip39" "1.5.0"
abitype "1.0.7"
isows "1.0.6"
ox "0.1.2"
webauthn-p256 "0.0.10"
ws "8.18.0"

viem@^2.1.1:
version "2.18.6"
resolved "https://registry.yarnpkg.com/viem/-/viem-2.18.6.tgz#527c54a032cdd4c1f1795fcb44072e8c3efd16c6"
Expand Down Expand Up @@ -9525,7 +9510,7 @@ vitest@^0.34.6:
vite-node "0.34.6"
why-is-node-running "^2.2.2"

wagmi@2.14.3, wagmi@^2.12.16:
wagmi@^2.12.16:
version "2.14.3"
resolved "https://registry.yarnpkg.com/wagmi/-/wagmi-2.14.3.tgz#3abfe5e9f796890d75d1b7d506e9dccd6b87f254"
integrity sha512-sr8o7+EBw22GhieDyXLv8Zr2vgC6xKrYoSuUIpq0xOqEhvMP1q880VtR4lFG1capc2QEWvK72pJ/+jpsEQcMYQ==
Expand Down

0 comments on commit 39711f2

Please sign in to comment.