Skip to content

Commit

Permalink
fixup! Add getAddresses engine method
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Nov 20, 2024
1 parent 27208cf commit 8a3375d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
88 changes: 58 additions & 30 deletions src/core/currency/wallet/currency-wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,53 +385,81 @@ export function makeCurrencyWalletApi(
if (engine.getAddresses != null) {
return await engine.getAddresses(opts)
} else {
// Upgrade getReceiveAddress to getAddresses
const receiveAddress = await this.getReceiveAddress(opts)
const allAddresses: EdgeAddress[] = []
const upgradedCurrency = upgradeCurrencyCode({
allTokens: input.props.state.accounts[accountId].allTokens[pluginId],
currencyInfo: plugin.currencyInfo,
tokenId: opts.tokenId
})

if (receiveAddress.segwitAddress != null) {
allAddresses.push({
const freshAddress = await engine.getFreshAddress({
...upgradedCurrency,
forceIndex: opts.forceIndex
})

const {
publicAddress,
legacyAddress,
segwitAddress,
nativeBalance,
legacyNativeBalance,
segwitNativeBalance
} = freshAddress

const addresses: EdgeAddress[] = [
{
addressType: 'publicAddress',
publicAddress,
nativeBalance
}
]

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

if (legacyAddress != null) {
addresses.push({
addressType: 'legacyAddress',
publicAddress: receiveAddress.legacyAddress,
nativeBalance: receiveAddress.legacyNativeBalance
publicAddress: legacyAddress,
nativeBalance: legacyNativeBalance
})
}

return allAddresses
return addresses
}
},

async getReceiveAddress(
opts: EdgeGetReceiveAddressOptions
): Promise<EdgeReceiveAddress> {
const upgradedCurrency = upgradeCurrencyCode({
allTokens: input.props.state.accounts[accountId].allTokens[pluginId],
currencyInfo: plugin.currencyInfo,
tokenId: opts.tokenId
})
const addresses = await this.getAddresses(opts)

const freshAddress = await engine.getFreshAddress({
...upgradedCurrency,
forceIndex: opts.forceIndex
})
const receiveAddress: EdgeReceiveAddress = {
...freshAddress,
nativeAmount: '0',
metadata: fakeMetadata
publicAddress: addresses[0].publicAddress,
nativeBalance: addresses[0].nativeBalance,
metadata: fakeMetadata,
nativeAmount: '0'
}

const segwitAddress = addresses.find(address => {
return address.addressType === 'segwitAddress'
})
if (segwitAddress != null) {
receiveAddress.segwitAddress = segwitAddress.publicAddress
receiveAddress.segwitNativeBalance = segwitAddress.nativeBalance
}
const legacyAddress = addresses.find(address => {
return address.addressType === 'legacyAddress'
})
if (legacyAddress != null) {
receiveAddress.legacyAddress = legacyAddress.publicAddress
receiveAddress.legacyNativeBalance = legacyAddress.nativeBalance
}

return receiveAddress
},
async lockReceiveAddress(
Expand Down
4 changes: 1 addition & 3 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,8 @@ export interface EdgeAddress {
nativeBalance?: string
}

/** Deprecated */
export interface EdgeFreshAddress {
allAddresses?: EdgeAddress[]

/** Deprecated */
publicAddress: string
segwitAddress?: string
legacyAddress?: string
Expand Down

0 comments on commit 8a3375d

Please sign in to comment.