Skip to content

Commit c07005f

Browse files
authored
Merge pull request #2041 from oasisprotocol/lw/dont-destroy-transak
Don't destroy Transak iframe every time pending transactions refresh
2 parents 296d8bd + 0fc6cea commit c07005f

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

.changelog/2041.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't destroy Transak iframe every time pending transactions refresh

src/app/pages/FiatOnrampPage/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { selectAddress } from 'app/state/wallet/selectors'
88
import { AlertBox } from 'app/components/AlertBox'
99
import { CircleAlert } from 'grommet-icons/es6/icons/CircleAlert'
1010
import { selectSelectedNetwork } from '../../state/network/selectors'
11-
import { selectAccountIsLoading } from '../../state/account/selectors'
11+
import { selectAccountAddress, selectAccountIsLoading } from '../../state/account/selectors'
1212
import { Button } from 'grommet/es6/components/Button'
1313
import { networkActions } from '../../state/network'
1414
import { CheckBox } from 'grommet/es6/components/CheckBox'
1515
import { selectThirdPartyAcknowledged } from './slice/selectors'
1616
import { fiatOnrampActions } from './slice'
17-
import { useState } from 'react'
17+
import { useEffect, useState } from 'react'
1818
import { ShareRounded } from 'grommet-icons/es6/icons/ShareRounded'
1919
import { Paragraph } from 'grommet/es6/components/Paragraph'
2020

@@ -48,6 +48,7 @@ export function FiatOnramp() {
4848
const { t } = useTranslation()
4949
const dispatch = useDispatch()
5050
const selectedNetwork = useSelector(selectSelectedNetwork)
51+
const address = useSelector(selectAccountAddress)
5152
const accountIsLoading = useSelector(selectAccountIsLoading)
5253
const isAddressInWallet = useSelector(selectIsAddressInWallet)
5354
const walletAddress = useSelector(selectAddress)
@@ -56,6 +57,14 @@ export function FiatOnramp() {
5657
// inputs some data, then resizes: do not lose user's inputs!
5758
const [shouldOpenTransakInNewTab] = useState(window.innerWidth <= 768 || window.innerHeight <= 700)
5859

60+
// Ignore refreshing account balance. Don't destroy and re-create iframe if balance changes and account balance is loading again.
61+
const [isInitialLoading, setInitialLoading] = useState(true)
62+
useEffect(() => {
63+
if (!!address && !accountIsLoading) {
64+
setInitialLoading(false)
65+
}
66+
}, [address, accountIsLoading])
67+
5968
if (selectedNetwork !== 'mainnet') {
6069
return (
6170
<Layout>
@@ -73,7 +82,7 @@ export function FiatOnramp() {
7382
</Layout>
7483
)
7584
}
76-
if (accountIsLoading) {
85+
if (isInitialLoading) {
7786
return <Layout />
7887
}
7988
if (!walletAddress || !isAddressInWallet) {

src/app/state/account/saga.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function* fetchingOnAccountPage() {
136136
staleBalances.available !== refreshedAccount.available ||
137137
staleBalances.delegations !== refreshedAccount.delegations ||
138138
staleBalances.debonding !== refreshedAccount.debonding ||
139-
hasPendingTxs
139+
hasPendingTxs // TODO: reduce setLoading if reloaded transactions haven't changed
140140
) {
141141
// Wait for oasisscan to update transactions (it updates balances faster)
142142
yield* call(fetchAccount, startAction)

0 commit comments

Comments
 (0)