-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6725d56
commit 7767ca7
Showing
9 changed files
with
138 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/desktop-client/src/components/mobile/usePrettyPayee.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { isPreviewId } from 'loot-core/shared/transactions'; | ||
import { useAccount } from '../../hooks/useAccount'; | ||
import { | ||
AccountEntity, | ||
PayeeEntity, | ||
TransactionEntity, | ||
} from 'loot-core/types/models'; | ||
|
||
type UsePrettyPayeeProps = { | ||
transaction: TransactionEntity & { _inverse?: boolean }; | ||
payee?: PayeeEntity; | ||
transferAccount?: AccountEntity; | ||
}; | ||
|
||
export function usePrettyPayee({ | ||
transaction, | ||
payee, | ||
transferAccount, | ||
}: UsePrettyPayeeProps) { | ||
const { id, amount: originalAmount, account, _inverse } = transaction; | ||
const transactionAccount = useAccount(account); | ||
|
||
const isPreview = isPreviewId(id); | ||
const amount = isPreview | ||
? (_inverse ? -1 : 1) * originalAmount | ||
: originalAmount; | ||
|
||
if (transferAccount) { | ||
const transferAccountName = isPreview | ||
? _inverse | ||
? transactionAccount?.name | ||
: transferAccount.name | ||
: transferAccount.name; | ||
return `Transfer ${amount > 0 ? 'from' : 'to'} ${transferAccountName}`; | ||
} else if (transaction.is_parent) { | ||
return 'Split'; | ||
} else if (payee) { | ||
return payee.name; | ||
} | ||
|
||
return ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.