From aab17520e2cc22eb790e564c51486bba009ed77d Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Tue, 10 Dec 2024 16:13:55 +0100 Subject: [PATCH] fix: connect button status based on interactions status --- .../connect-button/connect-button.module.ts | 51 +++++++------------ .../modules/storage/local-storage.module.ts | 1 - .../dapp-toolkit/src/radix-dapp-toolkit.ts | 4 +- 3 files changed, 19 insertions(+), 37 deletions(-) diff --git a/packages/dapp-toolkit/src/modules/connect-button/connect-button.module.ts b/packages/dapp-toolkit/src/modules/connect-button/connect-button.module.ts index d6fa601a..3ea51ace 100644 --- a/packages/dapp-toolkit/src/modules/connect-button/connect-button.module.ts +++ b/packages/dapp-toolkit/src/modules/connect-button/connect-button.module.ts @@ -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' @@ -49,9 +48,6 @@ export type ConnectButtonModuleInput = { stateModule: StateModule gatewayModule: GatewayModule walletRequestModule: WalletRequestModule - storageModule: StorageModule<{ - status: ConnectButtonStatus - }> } } @@ -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 @@ -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) diff --git a/packages/dapp-toolkit/src/modules/storage/local-storage.module.ts b/packages/dapp-toolkit/src/modules/storage/local-storage.module.ts index 888a8204..61645765 100644 --- a/packages/dapp-toolkit/src/modules/storage/local-storage.module.ts +++ b/packages/dapp-toolkit/src/modules/storage/local-storage.module.ts @@ -8,7 +8,6 @@ type PartitionKey = | 'identities' | 'requests' | 'state' - | 'connectButton' | 'walletResponses' | 'connectorExtension' type dAppDefinitionAddress = string diff --git a/packages/dapp-toolkit/src/radix-dapp-toolkit.ts b/packages/dapp-toolkit/src/radix-dapp-toolkit.ts index 5973ef90..d68446c0 100644 --- a/packages/dapp-toolkit/src/radix-dapp-toolkit.ts +++ b/packages/dapp-toolkit/src/radix-dapp-toolkit.ts @@ -98,7 +98,6 @@ export const RadixDappToolkit = ( stateModule, walletRequestModule, gatewayModule, - storageModule: storageModule.getPartition('connectButton'), }, }) @@ -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$,