diff --git a/netlify/functions/setup-xrpl-vault.ts b/netlify/functions/setup-xrpl-vault.ts index cd4e3ce2..2a8f1478 100644 --- a/netlify/functions/setup-xrpl-vault.ts +++ b/netlify/functions/setup-xrpl-vault.ts @@ -2,10 +2,32 @@ import { Handler } from '@netlify/functions'; const handler: Handler = async event => { try { + if (!event.queryStringParameters) { + return { + statusCode: 400, + body: JSON.stringify({ + message: 'No Parameters were provided', + }), + }; + } + + if (!event.queryStringParameters.userXRPLAddress) { + return { + statusCode: 400, + body: JSON.stringify({ + message: 'User Address was not provided', + }), + }; + } + const requestBody = JSON.stringify({ + user_xrpl_address: event.queryStringParameters.userXRPLAddress, + }); + const setupXRPLVaultEndpoint = `https://devnet-ripple.dlc.link/attestor-1/app/setup-xrpl-vault`; const response = await fetch(setupXRPLVaultEndpoint, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, + body: requestBody, }); if (!response.ok) { diff --git a/package.json b/package.json index dd80f0e9..009cd1e1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "concurrently": "^8.2.2", "d3": "^7.9.0", "decimal.js": "^10.4.3", - "dlc-btc-lib": "^2.2.10", + "dlc-btc-lib": "2.3.0", "dotenv": "^16.3.1", "ethers": "5.7.2", "formik": "^2.4.5", diff --git a/src/app/components/mint-unmint/components/burn-transaction-screen/burn-transaction-screen.tsx b/src/app/components/mint-unmint/components/burn-transaction-screen/burn-transaction-screen.tsx index 143b920b..099e8034 100644 --- a/src/app/components/mint-unmint/components/burn-transaction-screen/burn-transaction-screen.tsx +++ b/src/app/components/mint-unmint/components/burn-transaction-screen/burn-transaction-screen.tsx @@ -8,7 +8,8 @@ import { BitcoinWalletContext } from '@providers/bitcoin-wallet-context-provider import { ProofOfReserveContext } from '@providers/proof-of-reserve-context-provider'; import { RootState } from '@store/index'; import { mintUnmintActions } from '@store/slices/mintunmint/mintunmint.actions'; -import { RippleHandler } from 'dlc-btc-lib'; +import { Client } from 'dlc-btc-lib/models'; +import { createCheck, getRippleClient, getRippleWallet } from 'dlc-btc-lib/ripple-functions'; import { shiftValue } from 'dlc-btc-lib/utilities'; interface BurnTokenTransactionFormProps { @@ -44,8 +45,17 @@ export function BurnTokenTransactionForm({ // if (currentRisk === 'High') throw new Error('Risk Level is too high'); const formattedWithdrawAmount = BigInt(shiftValue(withdrawAmount)); - const xrplHandler = RippleHandler.fromSeed('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); - await xrplHandler.createCheck(formattedWithdrawAmount.toString(), currentVault.uuid.slice(2)); + const rippleWallet = getRippleWallet('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); + const issuerAddress = 'ra9epzthPkNXykgfadCwu8D7mtajj8DVCP'; + const rippleClient: Client = getRippleClient('wss://s.altnet.rippletest.net:51233'); + await createCheck( + rippleClient, + rippleWallet, + issuerAddress, + undefined, + formattedWithdrawAmount.toString(), + currentVault.uuid.slice(2) + ); // const updatedVault = await getAndFormatVault( // currentVault.uuid, diff --git a/src/app/components/mint-unmint/components/setup-vault-screen/setup-vault-screen.tsx b/src/app/components/mint-unmint/components/setup-vault-screen/setup-vault-screen.tsx index 8e030208..d9cb3984 100644 --- a/src/app/components/mint-unmint/components/setup-vault-screen/setup-vault-screen.tsx +++ b/src/app/components/mint-unmint/components/setup-vault-screen/setup-vault-screen.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; import { Button, VStack, useToast } from '@chakra-ui/react'; import { setupXRPLVault } from '@functions/fetch.functions'; +import { getRippleWallet } from 'dlc-btc-lib/ripple-functions'; import { SetupVaultScreenVaultGraphics } from './components/setup-vault-screen.vault-graphics'; @@ -13,8 +14,8 @@ export function SetupVaultScreen(): React.JSX.Element { async function handleSetup() { try { setIsSubmitting(true); - // const xrplHandler = RippleHandler.fromSeed('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); - await setupXRPLVault(); + const xrplWallet = getRippleWallet('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); + await setupXRPLVault(xrplWallet.classicAddress); } catch (error: any) { setIsSubmitting(false); toast({ diff --git a/src/app/functions/fetch.functions.ts b/src/app/functions/fetch.functions.ts index b8513453..1c68e9af 100644 --- a/src/app/functions/fetch.functions.ts +++ b/src/app/functions/fetch.functions.ts @@ -1,5 +1,5 @@ -export async function setupXRPLVault(): Promise { - const setupXRPLVaultEndpoint = `/.netlify/functions/setup-xrpl-vault`; +export async function setupXRPLVault(userAddress: string): Promise { + const setupXRPLVaultEndpoint = `/.netlify/functions/setup-xrpl-vault?userXRPLAddress=${userAddress}`; const response = await fetch(setupXRPLVaultEndpoint); return response.text(); diff --git a/src/app/hooks/use-nfts.ts b/src/app/hooks/use-nfts.ts index 52d9d7c5..0d3cc746 100644 --- a/src/app/hooks/use-nfts.ts +++ b/src/app/hooks/use-nfts.ts @@ -7,8 +7,8 @@ import { mintUnmintActions } from '@store/slices/mintunmint/mintunmint.actions'; import { modalActions } from '@store/slices/modal/modal.actions'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import Decimal from 'decimal.js'; -import { RippleHandler } from 'dlc-btc-lib'; -import { VaultState } from 'dlc-btc-lib/models'; +import { Client, VaultState } from 'dlc-btc-lib/models'; +import { getAllRippleVaults, getRippleClient } from 'dlc-btc-lib/ripple-functions'; import { isEmpty } from 'ramda'; interface useNFTsReturnType { @@ -23,7 +23,7 @@ interface useNFTsReturnType { export function useNFTs(): useNFTsReturnType { const queryClient = useQueryClient(); const dispatch = useDispatch(); - const xrplHandler = RippleHandler.fromSeed('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); + const rippleClient: Client = getRippleClient('wss://s.altnet.rippletest.net:51233'); const [dispatchTuple, setDispatchTuple] = useState< [ @@ -47,7 +47,9 @@ export function useNFTs(): useNFTsReturnType { const previousVaults: Vault[] | undefined = queryClient.getQueryData(['xrpl-vaults']); try { - xrplRawVaults = await xrplHandler.getContractVaults(); + const issuerAddress = 'ra9epzthPkNXykgfadCwu8D7mtajj8DVCP'; + + xrplRawVaults = await getAllRippleVaults(rippleClient, issuerAddress); } catch (error) { console.error('Error fetching XRPL Vaults', error); return previousVaults ?? []; diff --git a/src/app/hooks/use-psbt.ts b/src/app/hooks/use-psbt.ts index 388203e6..51b65711 100644 --- a/src/app/hooks/use-psbt.ts +++ b/src/app/hooks/use-psbt.ts @@ -5,12 +5,13 @@ import { BitcoinError } from '@models/error-types'; import { BitcoinWalletType } from '@models/wallet'; import { bytesToHex } from '@noble/hashes/utils'; import { BitcoinWalletContext } from '@providers/bitcoin-wallet-context-provider'; -import { LedgerDLCHandler, RippleHandler, SoftwareWalletDLCHandler } from 'dlc-btc-lib'; +import { LedgerDLCHandler, SoftwareWalletDLCHandler } from 'dlc-btc-lib'; import { submitFundingPSBT, submitWithdrawDepositPSBT, } from 'dlc-btc-lib/attestor-request-functions'; -import { Transaction, VaultState } from 'dlc-btc-lib/models'; +import { Client, Transaction, VaultState } from 'dlc-btc-lib/models'; +import { getRippleClient, getRippleVault } from 'dlc-btc-lib/ripple-functions'; // import { useAccount } from 'wagmi'; import { useLeather } from './use-leather'; @@ -65,8 +66,10 @@ export function usePSBT(): UsePSBTReturnType { const attestorGroupPublicKey = await getAttestorGroupPublicKey(); - const xrplHandler = RippleHandler.fromSeed('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); - const vault = await xrplHandler.getRawVault(vaultUUID); + const issuerAddress = 'ra9epzthPkNXykgfadCwu8D7mtajj8DVCP'; + const rippleClient: Client = getRippleClient('wss://s.altnet.rippletest.net:51233'); + + const vault = await getRippleVault(rippleClient, issuerAddress, vaultUUID); let fundingTransaction: Transaction; switch (bitcoinWalletType) { @@ -174,8 +177,10 @@ export function usePSBT(): UsePSBTReturnType { const feeRateMultiplier = import.meta.env.VITE_FEE_RATE_MULTIPLIER; const attestorGroupPublicKey = await getAttestorGroupPublicKey(); - const xrplHandler = RippleHandler.fromSeed('sEdSKUhR1Hhwomo7CsUzAe2pv7nqUXT'); - const vault = await xrplHandler.getRawVault(vaultUUID); + const issuerAddress = 'ra9epzthPkNXykgfadCwu8D7mtajj8DVCP'; + const rippleClient: Client = getRippleClient('wss://s.altnet.rippletest.net:51233'); + + const vault = await getRippleVault(rippleClient, issuerAddress, vaultUUID); if (!bitcoinWalletType) throw new Error('Bitcoin Wallet is not setup'); diff --git a/yarn.lock b/yarn.lock index 53d82aee..9ae08532 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5182,10 +5182,10 @@ dir-glob@^3.0.1: dependencies: path-type "^4.0.0" -dlc-btc-lib@^2.2.10: - version "2.2.10" - resolved "https://registry.yarnpkg.com/dlc-btc-lib/-/dlc-btc-lib-2.2.10.tgz#34bee9ee687c7ead3ec27498f1f80539003525a3" - integrity sha512-SzqnGptBUGexr5rbvc183sTY30SP0MUVX7wQAW0W5wJsuUvNgYfgboc+EC0fLxScwnm1H92mrvMWlovNu8d8iQ== +dlc-btc-lib@2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/dlc-btc-lib/-/dlc-btc-lib-2.3.0.tgz#e65fa4a56cb21dd14fe07f3d08c25327ea1be114" + integrity sha512-2yL+9tm1shpHpnwxRqJvW/aXzTlD3Vrc70I82h/FgSUY94X+qLlLCV5iItIHajm/gfevCjqgwObac0fHbgZAig== dependencies: "@ledgerhq/hw-app-btc" "10.4.1" "@noble/hashes" "1.4.0"