Skip to content

Commit

Permalink
chore: do not preselect jar on send page
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Oct 11, 2023
1 parent 687c031 commit 4b661db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 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: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,13 @@ export const toSemVer = (raw?: string): SemVer => {
}
}

export const scrollToTop = () => window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
/**
* 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)
}

0 comments on commit 4b661db

Please sign in to comment.