Skip to content

Commit 62cff31

Browse files
authored
Merge pull request #296 from blocknative/enhancement/wallet-check-loading
Enhancement: Wallet Check Loading. Closes #294
2 parents 91b87b0 + f115e02 commit 62cff31

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

src/elements/Spinner.svelte

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
<script>
2+
export let description
3+
</script>
4+
15
<style>
6+
.bn-onboard-loading-container {
7+
display: flex;
8+
flex-direction: column;
9+
align-items: center;
10+
justify-content: center;
11+
font-family: inherit;
12+
font-size: inherit;
13+
color: inherit;
14+
}
15+
16+
span {
17+
font-family: inherit;
18+
font-size: 0.889em;
19+
margin-top: 1rem;
20+
}
21+
222
:global(.bn-onboard-loading) {
323
display: inline-block;
424
position: relative;
@@ -36,8 +56,13 @@
3656
}
3757
</style>
3858

39-
<div class="bn-onboard-custom bn-onboard-loading">
40-
<div class="bn-onboard-loading-first" />
41-
<div class="bn-onboard-loading-second" />
42-
<div class="bn-onboard-loading-third" />
59+
<div class="bn-onboard-loading-container">
60+
<div class="bn-onboard-custom bn-onboard-loading">
61+
<div class="bn-onboard-loading-first" />
62+
<div class="bn-onboard-loading-second" />
63+
<div class="bn-onboard-loading-third" />
64+
</div>
65+
{#if description}
66+
<span>{description}</span>
67+
{/if}
4368
</div>

src/views/WalletCheck.svelte

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
}
187187
188188
function runModules(modules: WalletCheckModule[]) {
189-
loadingModal = true
190189
return new Promise(
191190
async (
192191
resolve: (result: {
@@ -198,12 +197,10 @@
198197
const result = await invalidState(module, currentState)
199198
200199
if (result) {
201-
loadingModal = false
202200
return resolve(result)
203201
}
204202
}
205203
206-
loadingModal = false
207204
return resolve({ modal: undefined, module: undefined })
208205
}
209206
)
@@ -238,7 +235,25 @@
238235
}
239236
} else {
240237
// module returned a promise, so await it for val
241-
const modal = await result
238+
// show loading spinner if promise doesn't resolve within 150ms
239+
let modal
240+
await new Promise(resolve => {
241+
let completed: boolean = false
242+
243+
result.then(res => {
244+
loadingModal = false
245+
completed = true
246+
modal = res
247+
resolve()
248+
})
249+
250+
setTimeout(() => {
251+
if (!completed) {
252+
loadingModal = true
253+
}
254+
}, 150)
255+
})
256+
242257
if (modal) {
243258
validateModal(modal)
244259
return {
@@ -294,7 +309,7 @@
294309

295310
{#if loadingModal}
296311
<Modal closeable={false}>
297-
<Spinner />
312+
<Spinner description="Checking wallet" />
298313
</Modal>
299314
{/if}
300315

0 commit comments

Comments
 (0)