Skip to content

Commit

Permalink
getRelatedWallets
Browse files Browse the repository at this point in the history
  • Loading branch information
acedward committed Dec 18, 2023
1 parent 60c124f commit a3c326e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/node-sdk/paima-db/src/delegate-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,25 @@ export async function getRelatedWallets(
): Promise<{
from: IGetDelegationsFromWithAddressResult[];
to: IGetDelegationsToWithAddressResult[];
id: number;
}> {
const address = _address.toLocaleLowerCase();
const [addressResult] = await getAddressFromAddress.run({ address }, DBConn);
const from = await getDelegationsFromWithAddress.run({ from_id: addressResult.id }, DBConn);
const to = await getDelegationsToWithAddress.run({ to_id: addressResult.id }, DBConn);
return { from, to };
if (!addressResult) {
return { from: [], to: [], id: NO_USER_ID };
}
let to: IGetDelegationsToWithAddressResult[] = [];
let from: IGetDelegationsFromWithAddressResult[] = [];

to = await getDelegationsToWithAddress.run({ to_id: addressResult.id }, DBConn);
if (!to.length) {
// cannot be both from and to.
from = await getDelegationsFromWithAddress.run({ from_id: addressResult.id }, DBConn);
}

return {
from,
to,
id: to.length ? to[0].id : addressResult.id,
};
}

0 comments on commit a3c326e

Please sign in to comment.