From 4a5cb0d0b0977ae5ea864514b7b1306de2ca3f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Mon, 1 Jul 2024 15:12:22 +0100 Subject: [PATCH] Add runes get balance --- example/src/App.tsx | 4 +- .../src/components/GetRunesBalance/index.tsx | 48 +++++++++++++++++++ package-lock.json | 8 ++-- package.json | 2 +- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 example/src/components/GetRunesBalance/index.tsx diff --git a/example/src/App.tsx b/example/src/App.tsx index 7b53bb9..476eae0 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,4 +1,4 @@ -import Wallet, { Address, AddressPurpose, BitcoinNetworkType } from 'sats-connect'; +import Wallet, { type Address, AddressPurpose, BitcoinNetworkType } from 'sats-connect'; import './App.css'; import { AddressDisplay, @@ -11,6 +11,7 @@ import { import { useLocalStorage } from './hooks'; import { useCallback, useState } from 'react'; import GetBtcBalance from './components/GetBtcBalance'; +import GetRunesBalance from './components/GetRunesBalance'; function App() { const [network, setNetwork] = useLocalStorage( @@ -94,6 +95,7 @@ function App() { + ); diff --git a/example/src/components/GetRunesBalance/index.tsx b/example/src/components/GetRunesBalance/index.tsx new file mode 100644 index 0000000..a707d3f --- /dev/null +++ b/example/src/components/GetRunesBalance/index.tsx @@ -0,0 +1,48 @@ +import { useState } from 'react'; +import Wallet, { GetRunesBalanceResult } from 'sats-connect'; + +const GetRunesBalance = () => { + const [balances, setBalances] = useState([]); + + const getBalance = async () => { + try { + const response = await Wallet.request('runes_getBalance', null); + if (response.status === 'success') { + setBalances(response.result.balances); + } else { + alert('Error getting runes balance. Check console for error logs'); + console.error(response.error); + } + } catch (err) { + console.log(err); + } + }; + + return ( +
+

Runes Balance

+ + + +
+ {(() => { + if (!balances.length) { + return
No balances
; + } + + return balances.map((balance) => ( +
+
Amount: {balance.amount}
+
Divisibility: {balance.divisibility}
+
Inscription ID: {balance.inscriptionId}
+
Rune name: {balance.runeName}
+
Rune symbol: {balance.symbol}
+
+ )); + })()} +
+
+ ); +}; + +export default GetRunesBalance; diff --git a/package-lock.json b/package-lock.json index 442e908..f6875de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.4.1", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.11-a4c2633", + "@sats-connect/core": "0.0.11-bed3235", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, @@ -1715,9 +1715,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.0.11-a4c2633", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.11-a4c2633.tgz", - "integrity": "sha512-gBliUGSJbWPi7GUIPy7foMh8hntz2iBigamnR4Q5rDvNLRH29XshK7lL4GLpLkG4u5LpyxswA1pDdeN4qSVz2g==", + "version": "0.0.11-bed3235", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.11-bed3235.tgz", + "integrity": "sha512-jhy5OWzxYC3xdRX78YgBijrjYMi0v+BuS7HrTTRCxVjoDpj5nVE1rwlmLOvbiVg/HyTTfwNbWXsGSK3mPj/g3Q==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index 013e494..b6aa5b4 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.0.11-a4c2633", + "@sats-connect/core": "0.0.11-bed3235", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" },