Skip to content

Commit

Permalink
Add runes get balance
Browse files Browse the repository at this point in the history
  • Loading branch information
aryzing committed Jul 1, 2024
1 parent 3587cc1 commit 4a5cb0d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
4 changes: 3 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<BitcoinNetworkType>(
Expand Down Expand Up @@ -94,6 +95,7 @@ function App() {
<GetBtcBalance />
<MintRunes network={network} addresses={addressInfo} />
<EtchRunes network={network} addresses={addressInfo} />
<GetRunesBalance />
</div>
</div>
);
Expand Down
48 changes: 48 additions & 0 deletions example/src/components/GetRunesBalance/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useState } from 'react';
import Wallet, { GetRunesBalanceResult } from 'sats-connect';

const GetRunesBalance = () => {
const [balances, setBalances] = useState<GetRunesBalanceResult['balances']>([]);

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 (
<div className="card">
<h3>Runes Balance</h3>

<button onClick={getBalance}>Get Runes Balance</button>

<div>
{(() => {
if (!balances.length) {
return <div>No balances</div>;
}

return balances.map((balance) => (
<div key={balance.runeName} style={{ paddingBlockStart: '0.5rem' }}>
<div>Amount: {balance.amount}</div>
<div>Divisibility: {balance.divisibility}</div>
<div>Inscription ID: {balance.inscriptionId}</div>
<div>Rune name: {balance.runeName}</div>
<div>Rune symbol: {balance.symbol}</div>
</div>
));
})()}
</div>
</div>
);
};

export default GetRunesBalance;
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 4a5cb0d

Please sign in to comment.