Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
anondev2323 committed Oct 17, 2023
1 parent 7125678 commit 43af821
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion core/definitions/src/testing/mocks/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class MockPlatform<P extends PlatformName> implements Platform<P> {
walletAddress: string,
tokens: AnyAddress[],
): Promise<Balances> {
throw new Error("method not implemented")
throw new Error("method not implemented");
}

getChain(chain: ChainName): ChainContext<P> {
Expand Down
11 changes: 9 additions & 2 deletions core/definitions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export type SequenceId = bigint;
export type SignedTx = any;

// TODO: Can we make this more dynamic?
export type AnyAddress = NativeAddress<PlatformName> | UniversalAddress | string | number | Uint8Array | number[] | "native";
export type AnyAddress =
| NativeAddress<PlatformName>
| UniversalAddress
| string
| number
| Uint8Array
| number[]
| "native";

export type TokenId = ChainAddress;
export function isTokenId(thing: TokenId | any): thing is TokenId {
Expand All @@ -28,7 +35,7 @@ export function isTokenId(thing: TokenId | any): thing is TokenId {

export type Balances = {
[key: string]: BigInt | null;
}
};

export interface Signer {
chain(): ChainName;
Expand Down
14 changes: 12 additions & 2 deletions platforms/cosmwasm/src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { BankExtension, IbcExtension, QueryClient, setupBankExtension, setupIbcExtension } from "@cosmjs/stargate";
import {
BankExtension,
IbcExtension,
QueryClient,
setupBankExtension,
setupIbcExtension,
} from "@cosmjs/stargate";
import { TendermintClient } from "@cosmjs/tendermint-rpc";

import {
Expand Down Expand Up @@ -115,7 +121,11 @@ export module CosmwasmPlatform {
): QueryClient & BankExtension & IbcExtension => {
// @ts-ignore
const tmClient: TendermintClient = rpc.getTmClient()!;
return QueryClient.withExtensions(tmClient, setupBankExtension, setupIbcExtension);
return QueryClient.withExtensions(
tmClient,
setupBankExtension,
setupIbcExtension,
);
};

// cached channels from config if available
Expand Down
23 changes: 13 additions & 10 deletions platforms/cosmwasm/src/platformUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import {
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { CosmwasmPlatform } from "./platform";
import { CosmwasmAddress } from "./address";
import { BankExtension, IbcExtension, QueryClient, setupIbcExtension } from "@cosmjs/stargate";
import {
BankExtension,
IbcExtension,
QueryClient,
setupIbcExtension,
} from "@cosmjs/stargate";
import { AnyCosmwasmAddress } from "./types";

// forces CosmwasmUtils to implement PlatformUtils
Expand Down Expand Up @@ -93,18 +98,16 @@ export module CosmwasmUtils {
): Promise<Balances> {
const allBalances = await rpc.bank.allBalances(walletAddress);
const balancesArr = tokens.map((token) => {
const address = token === 'native' ? getNativeDenom(chain) : new CosmwasmAddress(token).toString();
const balance = allBalances.find(
(balance) => balance.denom === address,
);
const address =
token === "native"
? getNativeDenom(chain)
: new CosmwasmAddress(token).toString();
const balance = allBalances.find((balance) => balance.denom === address);
const balanceBigInt = balance ? BigInt(balance.amount) : null;
return { [address]: balanceBigInt }
return { [address]: balanceBigInt };
});

return balancesArr.reduce(
(obj, item) => Object.assign(obj, item),
{}
);
return balancesArr.reduce((obj, item) => Object.assign(obj, item), {});
}

function getNativeDenom(chain: ChainName): string {
Expand Down
16 changes: 8 additions & 8 deletions platforms/evm/src/platformUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ export module EvmUtils {
walletAddr: string,
tokens: (AnyEvmAddress | 'native')[],
): Promise<Balances> {
const balancesArr = await Promise.all(tokens.map(async (token) => {
const balance = await getBalance(chain, rpc, walletAddr, token);
const address = token === 'native' ? 'native' : new EvmAddress(token).toString();
return { [address]: balance }
}))
return balancesArr.reduce(
(obj, item) => Object.assign(obj, item),
{}
const balancesArr = await Promise.all(
tokens.map(async (token) => {
const balance = await getBalance(chain, rpc, walletAddr, token);
const address =
token === 'native' ? 'native' : new EvmAddress(token).toString();
return { [address]: balance };
}),
);
return balancesArr.reduce((obj, item) => Object.assign(obj, item), {});
}

export async function sendWait(
Expand Down
18 changes: 7 additions & 11 deletions platforms/solana/src/platformUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ export module SolanaUtils {
native = BigInt(await rpc.getBalance(new PublicKey(walletAddress)));
}

const splParsedTokenAccounts =
await rpc.getParsedTokenAccountsByOwner(
new PublicKey(walletAddress),
{
programId: new PublicKey(TOKEN_PROGRAM_ID),
},
);
const splParsedTokenAccounts = await rpc.getParsedTokenAccountsByOwner(
new PublicKey(walletAddress),
{
programId: new PublicKey(TOKEN_PROGRAM_ID),
},
);

const balancesArr = tokens.map((token) => {
if (token === 'native') {
Expand All @@ -118,10 +117,7 @@ export module SolanaUtils {
return { [addrString]: BigInt(amount) };
});

return balancesArr.reduce(
(obj, item) => Object.assign(obj, item),
{}
);
return balancesArr.reduce((obj, item) => Object.assign(obj, item), {});
}

export async function sendWait(
Expand Down

0 comments on commit 43af821

Please sign in to comment.