-
Notifications
You must be signed in to change notification settings - Fork 144
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
af4d06d
commit c57fb82
Showing
3 changed files
with
45 additions
and
25 deletions.
There are no files selected for viewing
33 changes: 18 additions & 15 deletions
33
core/api/src/app/accounts/get-pending-onchain-transactions-for-account.ts
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 |
---|---|---|
@@ -1,33 +1,36 @@ | ||
import { getPendingOnChainTransactionsForWallets } from "../wallets/get-pending-onchain-transactions-for-wallets" | ||
|
||
import { AccountValidator } from "@/domain/accounts" | ||
import { RepositoryError } from "@/domain/errors" | ||
import { WalletsRepository } from "@/services/mongoose" | ||
import { checkedToWalletId } from "@/domain/wallets" | ||
import { WalletsRepository } from "@/services/mongoose" | ||
|
||
export const getPendingOnChainTransactionsForAccountByWalletIds = async ({ | ||
account, | ||
walletIds, | ||
}: { | ||
account: Account | ||
walletIds: string[] | ||
walletIds?: string[] | ||
}): Promise<WalletOnChainSettledTransaction[] | ApplicationError> => { | ||
const walletsRepo = WalletsRepository() | ||
|
||
const wallets: Wallet[] = [] | ||
for (const uncheckedWalletId of walletIds) { | ||
const walletId = checkedToWalletId(uncheckedWalletId) | ||
if (walletId instanceof Error) return walletId | ||
const wallet = await walletsRepo.findById(walletId) | ||
if (wallet instanceof RepositoryError) return wallet | ||
const accountWallets = await walletsRepo.listByAccountId(account.id) | ||
if (accountWallets instanceof RepositoryError) return accountWallets | ||
|
||
const accountValidator = AccountValidator(account) | ||
if (accountValidator instanceof Error) return accountValidator | ||
const validateWallet = accountValidator.validateWalletForAccount(wallet) | ||
if (validateWallet instanceof Error) return validateWallet | ||
if (!walletIds) { | ||
return getPendingOnChainTransactionsForWallets({ wallets: accountWallets }) | ||
} | ||
|
||
wallets.push(wallet) | ||
const checkedWalletIds: WalletId[] = [] | ||
|
||
for (const walletId of walletIds) { | ||
const checkedWalletId = checkedToWalletId(walletId) | ||
if (checkedWalletId instanceof Error) return checkedWalletId | ||
checkedWalletIds.push(checkedWalletId) | ||
} | ||
|
||
return getPendingOnChainTransactionsForWallets({ wallets }) | ||
const selectedWallets = accountWallets.filter((wallet) => | ||
checkedWalletIds.includes(wallet.id), | ||
) | ||
|
||
return getPendingOnChainTransactionsForWallets({ wallets: selectedWallets }) | ||
} |
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