Skip to content

Commit

Permalink
Add getAddresses engine method
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Nov 15, 2024
1 parent 2414b54 commit 27208cf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- added: Add `getAddresses` to `EdgeCurrencyWallet`
- changed: Deprecated `getReceiveAddress` field on `EdgeCurrencyWallet`

## 2.20.1 (2024-10-30)

- fixed: Correctly update info-server payload in the background.
Expand Down
36 changes: 36 additions & 0 deletions src/core/currency/wallet/currency-wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../client-side'
import { upgradeCurrencyCode } from '../../../types/type-helpers'
import {
EdgeAddress,
EdgeBalanceMap,
EdgeBalances,
EdgeCurrencyConfig,
Expand Down Expand Up @@ -378,6 +379,41 @@ export function makeCurrencyWalletApi(
streamTransactions,

// Addresses:
async getAddresses(
opts: EdgeGetReceiveAddressOptions
): Promise<EdgeAddress[]> {
if (engine.getAddresses != null) {
return await engine.getAddresses(opts)
} else {
// Upgrade getReceiveAddress to getAddresses
const receiveAddress = await this.getReceiveAddress(opts)
const allAddresses: EdgeAddress[] = []

if (receiveAddress.segwitAddress != null) {
allAddresses.push({
addressType: 'segwitAddress',
publicAddress: receiveAddress.segwitAddress,
nativeBalance: receiveAddress.segwitNativeBalance
})
}
allAddresses.push({
addressType: 'publicAddress',
publicAddress: receiveAddress.publicAddress,
nativeBalance:
receiveAddress.nativeBalance ?? receiveAddress.nativeAmount
})
if (receiveAddress.legacyAddress != null) {
allAddresses.push({
addressType: 'legacyAddress',
publicAddress: receiveAddress.legacyAddress,
nativeBalance: receiveAddress.legacyNativeBalance
})
}

return allAddresses
}
},

async getReceiveAddress(
opts: EdgeGetReceiveAddressOptions
): Promise<EdgeReceiveAddress> {
Expand Down
21 changes: 21 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,16 @@ export interface EdgeDataDump {
}
}

export interface EdgeAddress {
addressType: string // 'publicAddress' | 'segwitAddress' | 'legacyAddress' | 'fooAddress'
publicAddress: string
nativeBalance?: string
}

export interface EdgeFreshAddress {
allAddresses?: EdgeAddress[]

/** Deprecated */
publicAddress: string
segwitAddress?: string
legacyAddress?: string
Expand Down Expand Up @@ -945,6 +954,11 @@ export interface EdgeCurrencyEngine {
) => Promise<EdgeActivationQuote>

// Addresses:
readonly getAddresses?: (
opts: EdgeGetReceiveAddressOptions
) => Promise<EdgeAddress[]>

/** deprecated */
readonly getFreshAddress: (
opts: EdgeGetReceiveAddressOptions
) => Promise<EdgeFreshAddress>
Expand Down Expand Up @@ -1210,12 +1224,19 @@ export interface EdgeCurrencyWallet {
) => AsyncIterableIterator<EdgeTransaction[]>

// Addresses:
readonly getAddresses: (
opts: EdgeGetReceiveAddressOptions
) => Promise<EdgeAddress[]>

/** deprecated */
readonly getReceiveAddress: (
opts: EdgeGetReceiveAddressOptions
) => Promise<EdgeReceiveAddress>
/** deprecated */
readonly lockReceiveAddress: (
receiveAddress: EdgeReceiveAddress
) => Promise<void>
/** deprecated */
readonly saveReceiveAddress: (
receiveAddress: EdgeReceiveAddress
) => Promise<void>
Expand Down

0 comments on commit 27208cf

Please sign in to comment.