Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /v2/owners/:ownerAddress/safes to gracefully handle errors #2266

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/domain/safe/safe.repository.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ export interface ISafeRepository {
ownerAddress: `0x${string}`;
}): Promise<SafeList>;

getAllSafesByOwner(args: {
deprecated__getAllSafesByOwner(args: {
ownerAddress: `0x${string}`;
}): Promise<{ [chainId: string]: Array<string> }>;

getAllSafesByOwner(args: {
ownerAddress: `0x${string}`;
}): Promise<{ [chainId: string]: Array<string> | null }>;

getLastTransactionSortedByNonce(args: {
chainId: string;
safeAddress: `0x${string}`;
Expand Down
38 changes: 37 additions & 1 deletion src/domain/safe/safe.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export class SafeRepository implements ISafeRepository {
return SafeListSchema.parse(safeList);
}

async getAllSafesByOwner(args: {
async deprecated__getAllSafesByOwner(args: {
ownerAddress: `0x${string}`;
}): Promise<{ [chainId: string]: Array<string> }> {
const chains = await this.chainsRepository.getAllChains();
Expand All @@ -449,6 +449,42 @@ export class SafeRepository implements ISafeRepository {
}, {});
}

async getAllSafesByOwner(args: {
ownerAddress: `0x${string}`;
}): Promise<{ [chainId: string]: Array<string> | null }> {
const chains = await this.chainsRepository.getAllChains();
const allSafeLists = await Promise.allSettled(
chains.map(async ({ chainId }) => {
const safeList = await this.getSafesByOwner({
chainId,
ownerAddress: args.ownerAddress,
});

return {
chainId,
safeList,
};
}),
);

const result: { [chainId: string]: Array<string> | null } = {};

for (const [index, allSafeList] of allSafeLists.entries()) {
const chainId = chains[index].chainId;

if (allSafeList.status === 'fulfilled') {
result[chainId] = allSafeList.value.safeList.safes;
} else {
result[chainId] = null;
this.loggingService.warn(
`Failed to fetch Safe owners. chainId=${chainId}`,
);
}
}

return result;
}

async getLastTransactionSortedByNonce(args: {
chainId: string;
safeAddress: `0x${string}`;
Expand Down
6 changes: 4 additions & 2 deletions src/routes/owners/__tests__/get-safes-by-owner.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ describe('Get safes by owner e2e test', () => {
await redisClient.quit();
});

it('GET /owners/<owner_address>/safes', async () => {
it('GET /v1/chains/<chain_id>/owners/<owner_address>/safes', async () => {
const ownerCacheKey = `${cacheKeyPrefix}-${TEST_SAFE.chainId}_owner_safes_${TEST_SAFE.owners[0]}`;

await request(app.getHttpServer())
.get(`/chains/${TEST_SAFE.chainId}/owners/${TEST_SAFE.owners[0]}/safes`)
.get(
`/v1/chains/${TEST_SAFE.chainId}/owners/${TEST_SAFE.owners[0]}/safes`,
)
.expect(200)
.then(({ body }) => {
expect(body).toEqual(
Expand Down
Loading
Loading