-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make single hook for connections and fix some ui details
- Loading branch information
Showing
12 changed files
with
99 additions
and
64 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
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,3 +1,4 @@ | ||
export * from './use-connect-kit-store'; | ||
export * from './use-is-mobile'; | ||
export * from './use-connect-wallet'; | ||
export * from './use-graz'; |
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,58 @@ | ||
import { | ||
useConnect, | ||
useSuggestChainAndConnect, | ||
type WalletType as GrazWalletType, | ||
} from 'graz'; | ||
import { useConnectWallet } from './use-connect-wallet'; | ||
import { useIsMobile } from './use-is-mobile'; | ||
import { useConnectKitStore } from './use-connect-kit-store'; | ||
import type { WalletType } from '~/types'; | ||
import { nillionTestnet } from '../chain'; | ||
import { errorHandler } from '../utils'; | ||
|
||
export const useGraz = () => { | ||
const { isMobile } = useIsMobile(); | ||
const isMobileDevice = isMobile(); | ||
|
||
const { setActiveWalletType, setError, setActiveScreen } = | ||
useConnectKitStore(); | ||
const { chainOptions } = useConnectWallet(); | ||
const { suggestAndConnectAsync } = useSuggestChainAndConnect(); | ||
const { connectAsync } = useConnect(); | ||
|
||
const connect = async (type: WalletType) => { | ||
try { | ||
setError(null); | ||
setActiveWalletType(type); | ||
setActiveScreen('connecting'); | ||
|
||
const chainInfo = chainOptions.chainInfos.find( | ||
(i) => i.chainId === chainOptions.defaultChain | ||
); | ||
|
||
let res; | ||
|
||
if (chainInfo && !isMobileDevice) { | ||
res = await suggestAndConnectAsync({ | ||
chainInfo: nillionTestnet, | ||
walletType: type as GrazWalletType, | ||
}); | ||
} else { | ||
res = await connectAsync({ | ||
chainId: chainOptions.defaultChain, | ||
walletType: type as GrazWalletType, | ||
}); | ||
} | ||
|
||
const address = res.accounts[chainOptions.defaultChain]?.bech32Address; | ||
if (!address) { | ||
throw new Error('Failed to connect'); | ||
} | ||
} catch (error) { | ||
const serialized = errorHandler(error); | ||
setError(serialized.message ?? 'An Unknown Error Occurred'); | ||
} | ||
}; | ||
|
||
return { connect }; | ||
}; |
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