This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7721f01
commit 5286d32
Showing
3 changed files
with
18 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './network'; | ||
export * from './network'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import type { Ethereum, Fuel } from "@fuels/assets"; | ||
import type { Ethereum, Fuel } from '@fuels/assets'; | ||
|
||
import type { Asset } from "../services"; | ||
import type { Asset } from '../services'; | ||
|
||
type Network = Ethereum | Fuel; // Assuming Ethereum and Fuel are your types | ||
type Network = Ethereum | Fuel; // Assuming Ethereum and Fuel are your types | ||
export type NetworkTypes = Ethereum['type'] | Fuel['type']; | ||
type NetworkTypeToNetwork<T> = | ||
T extends 'ethereum' ? Ethereum : | ||
T extends 'fuel' ? Fuel : | ||
Network; | ||
type NetworkTypeToNetwork<T> = T extends 'ethereum' | ||
? Ethereum | ||
: T extends 'fuel' | ||
? Fuel | ||
: Network; | ||
|
||
export type GetAssetNetworkParams<T extends NetworkTypes | undefined> = { | ||
asset: Asset; | ||
chainId: number; | ||
networkType?: T; | ||
}; | ||
|
||
export const getAssetNetwork = <T extends NetworkTypes | undefined>({ asset, chainId, networkType }: GetAssetNetworkParams<T>): NetworkTypeToNetwork<T> => { | ||
if (!asset.networks) { | ||
debugger; | ||
} | ||
const network = asset.networks.find(network => network.chainId === chainId && network.type === networkType) as NetworkTypeToNetwork<T>; | ||
export const getAssetNetwork = <T extends NetworkTypes | undefined>({ | ||
asset, | ||
chainId, | ||
networkType, | ||
}: GetAssetNetworkParams<T>): NetworkTypeToNetwork<T> => { | ||
const network = asset.networks.find( | ||
(network) => network.chainId === chainId && network.type === networkType | ||
) as NetworkTypeToNetwork<T>; | ||
|
||
return network; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters