-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathaccount.ts
40 lines (36 loc) · 1.08 KB
/
account.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Account, AccountType } from '@dao-dao/types'
export const areAccountsEqual = (a: Account, b: Account) =>
a.type === b.type && a.chainId === b.chainId && a.address === b.address
/**
* Gets the account on the specified chain or undefined if nonexistent.
*/
export const getAccount = ({
accounts,
chainId,
types = [AccountType.Base, AccountType.Polytone],
}: {
accounts: readonly Account[]
chainId?: string
types?: readonly AccountType[]
}): Account | undefined =>
accounts.find(
(account) =>
types.includes(account.type) && (!chainId || account.chainId === chainId)
)
/**
* Gets the account address on the specified chain or undefined if nonexistent.
*/
export const getAccountAddress = (
...params: Parameters<typeof getAccount>
): string | undefined => getAccount(...params)?.address
/**
* Gets the chain ID for an address or undefined if nonexistent.
*/
export const getAccountChainId = ({
accounts,
address,
}: {
accounts: readonly Account[]
address: string
}): string | undefined =>
accounts.find((account) => account.address === address)?.chainId