-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove experimental chains and strategy improvements
- Loading branch information
1 parent
44b9fcd
commit 2d396eb
Showing
15 changed files
with
162 additions
and
174 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
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
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
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
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
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
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
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
65 changes: 65 additions & 0 deletions
65
packages/wallet-ts/src/utils/wallets/cosmostation/CosmostationWallet.ts
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { cosmos, InstallError } from '@cosmostation/extension-client' | ||
import { | ||
ErrorType, | ||
UnspecifiedErrorCode, | ||
CosmosWalletException, | ||
} from '@injectivelabs/exceptions' | ||
import { | ||
ChainId, | ||
CosmosChainId, | ||
TestnetCosmosChainId, | ||
} from '@injectivelabs/ts-types' | ||
|
||
export class CosmostationWallet { | ||
private chainId: CosmosChainId | TestnetCosmosChainId | ChainId | ||
|
||
constructor(chainId: CosmosChainId | TestnetCosmosChainId | ChainId) { | ||
this.chainId = chainId | ||
} | ||
|
||
static async isChainIdSupported(chainId: CosmosChainId): Promise<boolean> { | ||
return new CosmostationWallet(chainId).checkChainIdSupport() | ||
} | ||
|
||
public async checkChainIdSupport() { | ||
const { chainId: actualChainId } = this | ||
const provider = await this.getCosmostationWallet() | ||
const chainName = actualChainId.split('-') | ||
|
||
try { | ||
const supportedChainIds = await provider.getSupportedChainIds() | ||
|
||
return !!supportedChainIds.official.find((chainId) => chainId === chainId) | ||
} catch (e) { | ||
throw new CosmosWalletException( | ||
new Error( | ||
`Cosmostation doesn't support ${ | ||
chainName[0] || actualChainId | ||
} network. Please use another Cosmos wallet`, | ||
), | ||
) | ||
} | ||
} | ||
|
||
async getCosmostationWallet() { | ||
try { | ||
const provider = await cosmos() | ||
|
||
return provider | ||
} catch (e) { | ||
if (e instanceof InstallError) { | ||
throw new CosmosWalletException( | ||
new Error('Please install the Cosmostation extension'), | ||
{ | ||
code: UnspecifiedErrorCode, | ||
type: ErrorType.WalletNotInstalledError, | ||
}, | ||
) | ||
} | ||
|
||
throw new CosmosWalletException(new Error((e as any).message), { | ||
code: UnspecifiedErrorCode, | ||
}) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CosmostationWallet' |
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,5 +1,7 @@ | ||
export * from './keplr' | ||
export * from './cosmostation' | ||
export * from './leap' | ||
export * from './phantom' | ||
export * from './metamask' | ||
export * from './ninji' | ||
export * from './trust-wallet' |
Oops, something went wrong.