Skip to content

Commit

Permalink
chore: do not preselect jar on send page (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni authored Oct 12, 2023
1 parent c1d6bdf commit fcf23a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,6 @@ export default function Send({ wallet }: SendProps) {
)
}, [walletInfo])

useEffect(
function preSelectSourceJarIfPossible() {
if (isLoading) return

const jarsWithBalance = sortedAccountBalances.filter((it) => it.calculatedAvailableBalanceInSats > 0)
setSourceJarIndex((current) => {
if (jarsWithBalance.length === 0) return null

const currentJarHasBalance = current !== null && jarsWithBalance.some((it) => it.accountIndex === current)
if (currentJarHasBalance) return current
return jarsWithBalance[0].accountIndex
})
},
[isLoading, sourceJarIndex, sortedAccountBalances],
)

const accountBalance = useMemo(() => {
if (sourceJarIndex === null) return null
return sortedAccountBalances[sourceJarIndex]
Expand Down Expand Up @@ -469,6 +453,7 @@ export default function Send({ wallet }: SendProps) {
: await sendPayment(sourceJarIndex, destination, amount)

if (success) {
setSourceJarIndex(INITIAL_SOURCE_JAR_INDEX)
setDestination(INITIAL_DESTINATION)
setDestinationJar(null)
setAmount(INITIAL_AMOUNT)
Expand All @@ -477,9 +462,9 @@ export default function Send({ wallet }: SendProps) {
setIsSweep(false)

form.reset()

scrollToTop()
}

scrollToTop()
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ export const toSemVer = (raw?: string): SemVer => {
}
}

/**
* Scrolls to the top of the page.
*
* Hint: There is a small delay before the scrolling is initiated,
* in order to mitigate some weird browser behaviour, where it
* did not properly work without a timeout.
*/
export const scrollToTop = (options?: ScrollOptions) => {
setTimeout(() => window.scrollTo({ behavior: 'smooth', ...options, top: 0, left: 0 }), 21)
}

export const scrollToTop = () => window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })

export const noop = () => {}
Expand Down

0 comments on commit fcf23a9

Please sign in to comment.