Skip to content

Commit

Permalink
feat: wallectConnect preloader (#81)
Browse files Browse the repository at this point in the history
* feat: wallet connect preloader

* feat: connection qr expired

* feat: log error if brave
  • Loading branch information
anukulpandey authored May 27, 2024
1 parent 0f406f6 commit 2bce138
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
12 changes: 12 additions & 0 deletions public/img/wallets/walletconnect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 32 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const App = (): JSX.Element => {
}

const [selExtensionName, setSelExtensionName] = useState<string | undefined>(selectedWallet || undefined);
const [wcPreloader,setWcPreloader] = useState<boolean>(false);
const {
loading, error, signers, selectedReefSigner, network, provider, reefState, extension
} = hooks.useInitReefStateExtension(
Expand Down Expand Up @@ -113,12 +114,23 @@ window.addEventListener("unhandledrejection", (event) => {
}
});

//handle preloader
useEffect(()=>{
// preloader active
if(wcPreloader && signers.length){
// if account connected , hide preloader
setWcPreloader(false)
}

Check warning on line 123 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

React Hook useEffect has a missing dependency: 'wcPreloader'. Either include it or remove the dependency array
},[signers])

Check failure on line 125 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

Missing return type on function
const connectWalletConnect = async(ident:string)=>{
const response:reefExt.WcConnection | undefined = await connectWc()
console.log('connectWalletConnect',response);
if (response) {
reefExt.injectWcAsExtension(response, { name: reefExt.REEF_WALLET_CONNECT_IDENT, version: "1.0.0" });
setSelExtensionName(ident);
// display preloader
setWcPreloader(true);
} else {
// if proposal expired, recursively call
Uik.notify.danger("Connection QR expired, reloading")
Expand All @@ -130,10 +142,14 @@ const connectWalletConnect = async(ident:string)=>{

const onExtensionSelected = async(ident: string) => {
console.log('onExtensionSelected', ident);
if (ident === reefExt.REEF_WALLET_CONNECT_IDENT) {
await connectWalletConnect(ident);
} else {
setSelExtensionName(ident);
try {
if (ident === reefExt.REEF_WALLET_CONNECT_IDENT) {
await connectWalletConnect(ident);
} else {

Check failure on line 148 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

'error' is already declared in the upper scope
setSelExtensionName(ident);
}
} catch (error) {
console.log(error);
}
}

Expand Down Expand Up @@ -187,6 +203,18 @@ const connectWalletConnect = async(ident:string)=>{
accountSelectorOpen={history.location.pathname !== SNAP_URL} />
<ContentRouter />
<NetworkSwitching isOpen={isNetworkSwitching} />
<Uik.Modal title="Connecting to Mobile App"
isOpen={wcPreloader}>
<div>
<div className='wc-preloader'>
<div className='wc-loader'></div>
<img src="/img/wallets/walletconnect.svg" alt="" className='wc-icon-preloader' />

Check failure on line 211 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

Expected indentation of 30 space characters but found 28
</div>
<div className='wc-loader-label' >
<Uik.Text type="mini" text="wait while we are establishing a connection"/>
</div>

Check failure on line 215 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

Expected indentation of 30 space characters but found 28
</div>
</Uik.Modal>

Check failure on line 218 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

Expected closing tag to match indentation of opening

Check failure on line 218 in src/App.tsx

View workflow job for this annotation

GitHub Actions / unit-lint

Expected indentation of 28 space characters but found 26
<ToastContainer
draggable
Expand Down
38 changes: 37 additions & 1 deletion src/assets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,40 @@ input.form-control:focus {
.modal-backdrop {
z-index: 999 !important;
opacity: 0 !important;
}
}

.wc-icon-preloader{
width: 4rem;
height: 4rem;
position: absolute;
}

.wc-preloader{
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.wc-loader {
border: 5px solid #f3f3f3;
border-top: 5px solid #3496ff;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

.wc-loader-label{
padding-top: 1rem;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
}

0 comments on commit 2bce138

Please sign in to comment.