-
Notifications
You must be signed in to change notification settings - Fork 143
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
96dfbfa
commit a1e0317
Showing
17 changed files
with
541 additions
and
2 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
33 changes: 33 additions & 0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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" | ||
|
||
export const getPendingOnChainTransactionsForAccountByWalletIds = async ({ | ||
account, | ||
walletIds, | ||
}: { | ||
account: Account | ||
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 accountValidator = AccountValidator(account) | ||
if (accountValidator instanceof Error) return accountValidator | ||
const validateWallet = accountValidator.validateWalletForAccount(wallet) | ||
if (validateWallet instanceof Error) return validateWallet | ||
|
||
wallets.push(wallet) | ||
} | ||
|
||
return getPendingOnChainTransactionsForWallets({ wallets }) | ||
} |
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
21 changes: 21 additions & 0 deletions
21
core/api/src/app/wallets/get-pending-onchain-transactions-for-wallets.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CouldNotFindError } from "@/domain/errors" | ||
|
||
import { WalletOnChainPendingReceiveRepository } from "@/services/mongoose" | ||
|
||
export const getPendingOnChainTransactionsForWallets = async ({ | ||
wallets, | ||
}: { | ||
wallets: Wallet[] | ||
}): Promise<WalletOnChainSettledTransaction[] | ApplicationError> => { | ||
const walletIds = wallets.map((wallet) => wallet.id) | ||
|
||
const pendingHistory = await WalletOnChainPendingReceiveRepository().listByWalletIds({ | ||
walletIds, | ||
}) | ||
|
||
if (pendingHistory instanceof CouldNotFindError) { | ||
return [] | ||
} | ||
|
||
return pendingHistory | ||
} |
25 changes: 25 additions & 0 deletions
25
core/api/src/app/wallets/get-pending-transactions-by-addresses.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CouldNotFindError } from "@/domain/errors" | ||
|
||
import { WalletOnChainPendingReceiveRepository } from "@/services/mongoose" | ||
|
||
export const getPendingTransactionsForWalletsByAddresses = async ({ | ||
wallets, | ||
addresses, | ||
}: { | ||
wallets: Wallet[] | ||
addresses: OnChainAddress[] | ||
}): Promise<WalletOnChainSettledTransaction[] | ApplicationError> => { | ||
const walletIds = wallets.map((wallet) => wallet.id) | ||
|
||
const pendingHistory = | ||
await WalletOnChainPendingReceiveRepository().listByWalletIdsAndAddresses({ | ||
walletIds, | ||
addresses, | ||
}) | ||
|
||
if (pendingHistory instanceof CouldNotFindError) { | ||
return [] | ||
} | ||
|
||
return pendingHistory | ||
} |
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
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
Oops, something went wrong.