Skip to content

Commit

Permalink
feat: modify requests to match updated attestor endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Oct 10, 2024
1 parent 703324b commit 4f81a82
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 22 deletions.
22 changes: 22 additions & 0 deletions netlify/functions/setup-xrpl-vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions src/app/functions/fetch.functions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export async function setupXRPLVault(): Promise<string> {
const setupXRPLVaultEndpoint = `/.netlify/functions/setup-xrpl-vault`;
export async function setupXRPLVault(userAddress: string): Promise<string> {
const setupXRPLVaultEndpoint = `/.netlify/functions/setup-xrpl-vault?userXRPLAddress=${userAddress}`;

const response = await fetch(setupXRPLVaultEndpoint);
return response.text();
Expand Down
10 changes: 6 additions & 4 deletions src/app/hooks/use-nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<
[
Expand All @@ -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);

Check warning on line 54 in src/app/hooks/use-nfts.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
return previousVaults ?? [];
Expand Down
17 changes: 11 additions & 6 deletions src/app/hooks/use-psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4f81a82

Please sign in to comment.