Skip to content

Commit

Permalink
Merge pull request #295 from radixdlt/fix-cb-status
Browse files Browse the repository at this point in the history
fix: connect button status based on interactions status
  • Loading branch information
xstelea authored Dec 10, 2024
2 parents 98b5da5 + aab1752 commit 12c23bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import {
} from '../wallet-request'
import { GatewayModule, RadixNetworkConfigById } from '../gateway'
import { StateModule } from '../state'
import { StorageModule } from '../storage'
import { ConnectButtonModuleOutput, ConnectButtonStatus } from './types'
import { ConnectButtonModuleOutput } from './types'
import { isBrowser } from '../../helpers/is-browser'
import { ConnectButtonNoopModule } from './connect-button-noop.module'

Expand All @@ -49,9 +48,6 @@ export type ConnectButtonModuleInput = {
stateModule: StateModule
gatewayModule: GatewayModule
walletRequestModule: WalletRequestModule
storageModule: StorageModule<{
status: ConnectButtonStatus
}>
}
}

Expand All @@ -73,7 +69,6 @@ export const ConnectButtonModule = (
subintentPath: '/subintent/',
accountsPath: '/account/',
}
const statusStorage = input.providers.storageModule

const stateModule = input.providers.stateModule
const gatewayModule = input.providers.gatewayModule
Expand Down Expand Up @@ -448,48 +443,36 @@ export const ConnectButtonModule = (
.subscribe(),
)

subscriptions.add(
statusStorage.storage$
.pipe(
switchMap(() =>
statusStorage.getState().map((state) => {
if (state?.status) {
subjects.status.next(state.status)
}
}),
),
const setPendingOrDefault = () =>
walletRequestModule
.getPendingRequests()
.andTee((items) =>
subjects.status.next(items.length ? 'pending' : 'default'),
)
.subscribe(),
)

subscriptions.add(
walletRequestModule.interactionStatusChange$
.pipe(
mergeMap((newStatus) =>
from(
statusStorage.setState({
status:
newStatus === 'success'
? 'success'
: newStatus === 'fail'
? 'error'
: 'pending',
}),
of(
subjects.status.next(
newStatus === 'success'
? 'success'
: newStatus === 'fail'
? 'error'
: 'pending',
),
).pipe(
delay(2000),
concatMap(() =>
walletRequestModule.getPendingRequests().andThen((items) =>
statusStorage.setState({
status: items.length ? 'pending' : 'default',
}),
),
),
concatMap(() => setPendingOrDefault()),
),
),
)
.subscribe(),
)

setPendingOrDefault()

if (dAppDefinitionAddress) {
gatewayModule.gatewayApi
.getEntityMetadataPage(dAppDefinitionAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type PartitionKey =
| 'identities'
| 'requests'
| 'state'
| 'connectButton'
| 'walletResponses'
| 'connectorExtension'
type dAppDefinitionAddress = string
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp-toolkit/src/radix-dapp-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export const RadixDappToolkit = (
stateModule,
walletRequestModule,
gatewayModule,
storageModule: storageModule.getPartition('connectButton'),
},
})

Expand All @@ -119,7 +118,8 @@ export const RadixDappToolkit = (
walletRequestModule.provideConnectResponseCallback,
updateSharedAccounts: () => walletRequestModule.updateSharedAccounts(),
sendOneTimeRequest: walletRequestModule.sendOneTimeRequest,
sendPreAuthorizationRequest: walletRequestModule.sendPreAuthorizationRequest,
sendPreAuthorizationRequest:
walletRequestModule.sendPreAuthorizationRequest,
sendTransaction: (input: SendTransactionInput) =>
walletRequestModule.sendTransaction(input),
walletData$: stateModule.walletData$,
Expand Down

0 comments on commit 12c23bd

Please sign in to comment.