Skip to content

Commit

Permalink
added decimals to UnattestedToken type
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Jan 21, 2025
1 parent a370e1c commit 1e6e315
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions connect/src/routes/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,21 @@ export class RouteTransferRequest<N extends Network> {
params: {
source: TokenId<FC>;
destination: TokenId<TC>;
sourceDecimals?: number;
destinationDecimals?: number;
},
fromChain?: ChainContext<N, FC>,
toChain?: ChainContext<N, TC>,
) {
fromChain = fromChain ?? wh.getChain(params.source.chain);
toChain = toChain ?? wh.getChain(params.destination.chain);

const sourceDetails = await getTokenDetails(fromChain, params.source);
const destDetails = await getTokenDetails(toChain, params.destination);
const sourceDetails = await getTokenDetails(fromChain, params.source, params.sourceDecimals);
const destDetails = await getTokenDetails(
toChain,
params.destination,
params.destinationDecimals,
);

const rtr = new RouteTransferRequest(fromChain, toChain, sourceDetails, destDetails);

Expand Down
3 changes: 2 additions & 1 deletion connect/src/routes/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function tokenAddresses(tokens: TokenId[]): string[] {
export async function getTokenDetails<N extends Network>(
chain: ChainContext<N>,
token: TokenId,
decimals?: number,
): Promise<TokenDetails> {
const address = canonicalAddress(token);

Expand All @@ -40,7 +41,7 @@ export async function getTokenDetails<N extends Network>(

const symbol = details ? details.symbol : undefined;
const wrapped = isNative(token.address) ? await chain.getNativeWrappedTokenId() : undefined;
const decimals = Number(await chain.getDecimals(token.address));
decimals = decimals ?? (await chain.getDecimals(token.address));

return {
id: token,
Expand Down
7 changes: 6 additions & 1 deletion core/definitions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ export function isTokenId<C extends Chain>(thing: any): thing is TokenId<C> {
*/
export type UnattestedTokenId<C extends Chain = Chain> = TokenId<C> & {
isUnattested: true;
decimals: number; // expected decimals for the token
};
export function isUnattestedTokenId<C extends Chain>(thing: any): thing is UnattestedTokenId<C> {
return isTokenId(thing) && (<UnattestedTokenId<C>>thing).isUnattested === true;
return (
isTokenId(thing) &&
(<UnattestedTokenId<C>>thing).isUnattested === true &&
(<UnattestedTokenId<C>>thing).decimals !== undefined
);
}

export function isSameToken(a: TokenId, b: TokenId): boolean {
Expand Down

0 comments on commit 1e6e315

Please sign in to comment.