Skip to content

Commit

Permalink
feat(fractal): add fractal support (#376)
Browse files Browse the repository at this point in the history
* feat(fractal): add fractal support

* chore: version bump ordit-sdk
  • Loading branch information
veralygit authored Oct 30, 2024
1 parent c4759dc commit c9e23fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/ord-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
]
},
"peerDependencies": {
"@ordzaar/ordit-sdk": "^2.2.1",
"@ordzaar/ordit-sdk": "^3.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
10 changes: 8 additions & 2 deletions packages/ord-connect/src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { useOrdConnect } from "../providers/OrdConnectProvider";

export function useBalance() {
const { network, publicKey, format } = useOrdConnect();
const { network, publicKey, format, chain } = useOrdConnect();
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

Expand All @@ -21,18 +21,24 @@ export function useBalance() {
if (!format || !format.payments || !publicKey || !publicKey.payments) {
throw new Error("No wallet is connected");
}

const { address } = getAddressesFromPublicKey(
publicKey.payments,
network,
ADDRESS_FORMAT_TO_TYPE[format.payments] as Exclude<
AddressType,
"p2wsh"
>,
chain,
)[0];

const datasource = new JsonRpcDatasource({ network });
const datasource = new JsonRpcDatasource({
chain,
network,
});

const totalBalance = await datasource.getBalance({ address });

const totalAmountInSats = Number(
new BigNumber(totalBalance)
.multipliedBy(100_000_000)
Expand Down
5 changes: 3 additions & 2 deletions packages/ord-connect/src/hooks/useSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type SendFunction = (
) => Promise<string | null>;

export function useSend() {
const { wallet, network, address, publicKey } = useOrdConnect();
const { wallet, network, address, publicKey, chain } = useOrdConnect();
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

Expand All @@ -35,6 +35,7 @@ export function useSend() {
address: address.payments,
feeRate,
network,
chain,
publicKey: publicKey.payments,
outputs: [
{
Expand All @@ -53,7 +54,7 @@ export function useSend() {
});

if (relay) {
const datasource = new JsonRpcDatasource({ network });
const datasource = new JsonRpcDatasource({ network, chain });
const txId = await datasource.relay({ hex: signedPsbt.hex });
setLoading(false);
return txId;
Expand Down
5 changes: 3 additions & 2 deletions packages/ord-connect/src/hooks/useSendV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type SendResponse = {
};

export function useSendV2() {
const { wallet, network, address, publicKey } = useOrdConnect();
const { wallet, network, address, publicKey, chain } = useOrdConnect();
const [isLoading, setIsLoading] = useState<boolean>(false);

const send: SendFunction = useCallback(
Expand Down Expand Up @@ -49,6 +49,7 @@ export function useSendV2() {
address: address.payments,
feeRate,
network,
chain,
publicKey: publicKey.payments,
outputs: [
{
Expand All @@ -70,7 +71,7 @@ export function useSendV2() {
});

if (relay) {
const datasource = new JsonRpcDatasource({ network });
const datasource = new JsonRpcDatasource({ network, chain });
const txId = await datasource.relay({ hex: signedPsbt.hex });
setIsLoading(false);
return {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9e23fa

Please sign in to comment.