Skip to content

Commit

Permalink
feat(ux): add readOnly optional param to unisat getAddresses method (#88
Browse files Browse the repository at this point in the history
)

add readOnly optional param to unisat getAddresses method
  • Loading branch information
kainanaina authored Oct 31, 2023
1 parent fce5141 commit 0e3c322
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/sdk/src/browser-wallets/unisat/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getAddressFormat } from "../.."
import { Network } from "../../config/types"
import { isUnisatInstalled, UnisatNetwork } from "./utils"

export async function getAddresses(network: Network) {
export async function getAddresses(network: Network, readOnly?: boolean) {
if (!isUnisatInstalled()) {
throw new Error("Unisat not installed.")
}
Expand All @@ -22,7 +22,7 @@ export async function getAddresses(network: Network) {
await window.unisat.switchNetwork(targetNetwork)
}

const accounts = await window.unisat.requestAccounts()
const accounts = readOnly ? await window.unisat.getAccounts() : await window.unisat.requestAccounts()
const publicKey = await window.unisat.getPublicKey()

if (!accounts[0]) {
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Unisat = {
getNetwork: () => Promise<UnisatNetwork>
switchNetwork: (targetNetwork: UnisatNetwork) => Promise<void>
requestAccounts: () => Promise<string[]>
getAccounts: () => Promise<string[]>
getPublicKey: () => Promise<string>
signPsbt: (hex: string, { autoFinalized }: Record<string, boolean>) => Promise<string>
signMessage: (message: string) => Promise<string>
Expand Down

0 comments on commit 0e3c322

Please sign in to comment.