Skip to content

Commit

Permalink
fix: The order of addresses determined which account was displayed (#980
Browse files Browse the repository at this point in the history
)
  • Loading branch information
obany authored and cvarley100 committed Apr 21, 2021
1 parent f67bc70 commit edaa355
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/shared/components/ActivityDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
// especially if there was a remainder, so if any account addresses match
// we need to find the account details for our address match
if (getIncomingFlag(txPayload) || getInternalFlag(txPayload)) {
return findAccountWithAnyAddress(receiverAddresses)
return findAccountWithAnyAddress(receiverAddresses, senderAccount)
}
return null
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/components/ActivityRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
// especially if there was a remainder, so if any account addresses match
// we need to find the account details for our address match
$: receiverAccount =
getIncomingFlag(txPayload) || getInternalFlag(txPayload) ? findAccountWithAnyAddress(receiverAddresses) : null
getIncomingFlag(txPayload) || getInternalFlag(txPayload) ? findAccountWithAnyAddress(receiverAddresses, senderAccount) : null
let initialsColor
let accountAlias = ''
Expand Down
24 changes: 21 additions & 3 deletions packages/shared/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1607,12 +1607,30 @@ export const findAccountWithAddress = (address: string): WalletAccount | undefin
/**
* Find an address in one of our accounts
* @param addresses The addresses to find
* @param excludeFirst A wallet to exclude on first pass
* @returns The wallet account matching the address or undefined if not found
*/
export const findAccountWithAnyAddress = (addresses: string[]): WalletAccount | undefined => {
export const findAccountWithAnyAddress = (addresses: string[], excludeFirst?: WalletAccount): WalletAccount | undefined => {
if (!addresses || addresses.length === 0) {
return
}
const accounts = get(get(wallet).accounts)
return accounts.find((acc) => acc.addresses.some((add) => addresses.includes(add.address)))
let accounts = get(get(wallet).accounts)

let res = accounts.filter((acc) => acc.addresses.some((add) => addresses.includes(add.address)))

if (res.length > 0) {
if (excludeFirst) {
const initialLen = res.length
res = res.filter(a => a.id !== excludeFirst.id)
// If the length changed we removed it, so put it back
// at the end
if (res.length !== initialLen) {
res.push(excludeFirst)
}
}

if (res.length > 0) {
return res[0]
}
}
}

0 comments on commit edaa355

Please sign in to comment.