-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of wallet connect with ArConnect
- Loading branch information
1 parent
efdccec
commit 6f635a5
Showing
18 changed files
with
488 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useEffectOnce } from '@src/hooks/useEffectOnce'; | ||
import { ArConnectWalletConnector } from '@src/services/wallets/ArConnectWalletConnector'; | ||
import { useGlobalState } from '@src/store'; | ||
import { WALLET_TYPES } from '@src/types'; | ||
import { ReactElement, useEffect } from 'react'; | ||
|
||
const WalletProvider = ({ children }: { children: ReactElement }) => { | ||
const { setWalletStateInitialized, updateWallet } = useGlobalState(); | ||
|
||
useEffect(() => { | ||
window.addEventListener('arweaveWalletLoaded', updateIfConnected); | ||
|
||
return () => { | ||
window.removeEventListener('arweaveWalletLoaded', updateIfConnected); | ||
}; | ||
}, []); | ||
|
||
useEffectOnce(() => { | ||
setTimeout(() => { | ||
setWalletStateInitialized(true); | ||
}, 5000); | ||
}); | ||
|
||
// useEffect(() => { | ||
// if (walletAddress) { | ||
// updateBalances(walletAddress); | ||
// } | ||
// }, [walletAddress, blockHeight]); | ||
|
||
// const updateBalances = async (address: ArweaveTransactionID) => { | ||
// try { | ||
// const [ioBalance, arBalance] = await Promise.all([ | ||
// arweaveDataProvider.getTokenBalance(address, ARNS_REGISTRY_ADDRESS), | ||
// arweaveDataProvider.getArBalance(address), | ||
// ]); | ||
|
||
// dispatchWalletState({ | ||
// type: 'setBalances', | ||
// payload: { | ||
// [ioTicker]: ioBalance, | ||
// ar: arBalance, | ||
// }, | ||
// }); | ||
// } catch (error) { | ||
// eventEmitter.emit('error', error); | ||
// } | ||
// }; | ||
|
||
async function updateIfConnected() { | ||
const walletType = window.localStorage.getItem('walletType'); | ||
|
||
try { | ||
if (walletType === WALLET_TYPES.ARCONNECT) { | ||
const connector = new ArConnectWalletConnector(); | ||
const address = await connector?.getWalletAddress(); | ||
|
||
updateWallet(address.toString(), connector); | ||
} | ||
} catch (error) { | ||
// eventEmitter.emit('error', error); | ||
} finally { | ||
setWalletStateInitialized(true); | ||
} | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
// const updateIfConnected = async () => { | ||
|
||
// const walletType = window.localStorage.getItem('walletType'); | ||
// const globalState = useGlobalState(); | ||
|
||
// try { | ||
// if (walletType === WALLET_TYPES.ARCONNECT) { | ||
// const connector = new ArConnectWalletConnector(); | ||
// const address = await connector?.getWalletAddress(); | ||
|
||
// globalState.updateWallet(address.toString(), connector); | ||
// } | ||
// } catch (error) { | ||
// // eventEmitter.emit('error', error); | ||
// } finally { | ||
// globalState.setWalletStateInitialized(true); | ||
// } | ||
// } | ||
|
||
// export const initializeArConnect = async () => { | ||
|
||
// } | ||
|
||
export default WalletProvider; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
import { EffectCallback, useEffect, useRef } from 'react'; | ||
|
||
/** Hook for ensuring an effect is run only once for a component on first mount. | ||
* Will not be run on subsequent unmount/remounts of the component. Should only be used | ||
* for effects where cleanup code (i.e., the return Destructor value from the EffectCallback) | ||
* is not needed. | ||
* | ||
* @param effect The effect to run once. | ||
*/ | ||
export const useEffectOnce = (effect: EffectCallback) => { | ||
const initializationOccuredRef = useRef(false); | ||
|
||
useEffect(() => { | ||
if (initializationOccuredRef.current === false) { | ||
initializationOccuredRef.current = true; | ||
effect(); | ||
} | ||
}); | ||
}; |
Oops, something went wrong.