Skip to content

Commit

Permalink
fix(ordit-sdk): use datasource ordit-sdk 2.0 (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevzzsk authored Sep 30, 2023
1 parent 7a60e74 commit dfb619a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions packages/ord-connect/src/hooks/useBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from "react";
import {
addressNameToType,
OrditApi,
getAddressesFromPublicKey,
JsonRpcDatasource,
} from "@sadoprotocol/ordit-sdk";
import { useOrdContext, Wallet } from "../providers/OrdContext.tsx";

Expand All @@ -11,6 +11,8 @@ export function useBalance(): [() => Promise<number>, string | null, boolean] {
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

const datasource = new JsonRpcDatasource({ network });

const getSafeBalance = async (): Promise<number> => {
setLoading(true);
try {
Expand All @@ -23,11 +25,11 @@ export function useBalance(): [() => Promise<number>, string | null, boolean] {
network,
addressNameToType[format.payments],
)[0];
const { spendableUTXOs } = await OrditApi.fetchUnspentUTXOs({

const { spendableUTXOs } = await datasource.getUnspents({
address,
network,
sort: "desc",
type: "spendable",
decodeMetadata: false,
});

const totalCardinalsAvailable = spendableUTXOs.reduce(
Expand Down
10 changes: 5 additions & 5 deletions packages/ord-connect/src/hooks/useSend.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { ordit, PSBTBuilder } from "@sadoprotocol/ordit-sdk";
import { PSBTBuilder, JsonRpcDatasource } from "@sadoprotocol/ordit-sdk";
import { sendBtcTransaction } from "sats-connect";

import { useOrdContext, Wallet } from "../providers/OrdContext.tsx";
Expand All @@ -17,6 +17,8 @@ export function useSend(): [SendFunction, string | null, boolean] {
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

const datasource = new JsonRpcDatasource({ network });

const safeSend: SendFunction = async (toAddress, satoshis, feeRate) => {
setLoading(true);
try {
Expand Down Expand Up @@ -46,10 +48,8 @@ export function useSend(): [SendFunction, string | null, boolean] {
psbt: psbtBuilder.toPSBT(),
});

const txId = await ordit.transactions.relayTransaction(
signedPsbt.hex,
network,
);
const txId = await datasource.relay({ hex: signedPsbt.hex });

setLoading(false);
return txId;
} catch (err: any) {
Expand Down

0 comments on commit dfb619a

Please sign in to comment.