-
Notifications
You must be signed in to change notification settings - Fork 11
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
59d4345
commit a1cf8e8
Showing
5 changed files
with
134 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { EthereumChainId, AccountAddress } from '@injectivelabs/ts-types' | ||
import { | ||
ErrorType, | ||
GeneralException, | ||
UnspecifiedErrorCode, | ||
BitGetException | ||
} from '@injectivelabs/exceptions' | ||
import { UtilsWallets } from '@injectivelabs/wallet-ts' | ||
import { ETHEREUM_CHAIN_ID } from './../utils/constant' | ||
import { walletStrategy } from './wallet-strategy' | ||
|
||
export const isBitGetInstalled = async (): Promise<boolean> => { | ||
const provider = await UtilsWallets.getBitGetProvider() | ||
|
||
return !!provider | ||
} | ||
|
||
export const validateBitGet = async ( | ||
address: AccountAddress, | ||
chainId: EthereumChainId = ETHEREUM_CHAIN_ID | ||
) => { | ||
const addresses = await walletStrategy.getAddresses() | ||
const bitGetIsLocked = addresses.length === 0 | ||
|
||
if (bitGetIsLocked) { | ||
throw new BitGetException( | ||
new Error('Your BitGet is currently locked. Please unlock your BitGet.'), | ||
{ | ||
code: UnspecifiedErrorCode, | ||
type: ErrorType.WalletError | ||
} | ||
) | ||
} | ||
|
||
const [bitGetActiveAddress] = addresses | ||
const bitGetActiveAddressDoesntMatchTheActiveAddress = | ||
address && bitGetActiveAddress.toLowerCase() !== address.toLowerCase() | ||
|
||
if (bitGetActiveAddressDoesntMatchTheActiveAddress) { | ||
throw new BitGetException( | ||
new Error( | ||
'You are connected to the wrong address. Please logout and connect to BitGet again' | ||
), | ||
{ | ||
code: UnspecifiedErrorCode, | ||
type: ErrorType.WalletError | ||
} | ||
) | ||
} | ||
|
||
const bitGetChainId = parseInt(await walletStrategy.getEthereumChainId(), 16) | ||
const bitGetChainIdDoesntMatchTheActiveChainId = chainId !== bitGetChainId | ||
|
||
if (bitGetChainIdDoesntMatchTheActiveChainId) { | ||
return await UtilsWallets.updateBitGetNetwork(chainId) | ||
} | ||
|
||
const bitGetProvider = await UtilsWallets.getBitGetProvider() | ||
|
||
if (!bitGetProvider) { | ||
throw new GeneralException( | ||
new Error('You are connected to the wrong wallet. Please use BitGet.'), | ||
{ | ||
code: UnspecifiedErrorCode, | ||
type: ErrorType.WalletError | ||
} | ||
) | ||
} | ||
} |
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