Skip to content

Commit

Permalink
feat: add option to force wallet request
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Mar 27, 2023
1 parent b900e71 commit 2f1a22a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class ExampleDapp extends LitElement {
accountsPath: 'account/',
transactionPath: 'transaction/',
},
useCache: false,
}
)

Expand Down
3 changes: 3 additions & 0 deletions src/radix-dapp-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type RadixDappToolkitConfiguration = {
explorer?: Explorer
gatewayBaseUrl?: string
onStateChange?: (state: State) => void
useCache?: boolean
}
export const RadixDappToolkit = (
{ dAppDefinitionAddress, dAppName }: DappMetadata,
Expand All @@ -47,6 +48,7 @@ export const RadixDappToolkit = (
onDisconnect: onDisconnectCallback = () => {},
explorer,
gatewayBaseUrl,
useCache,
} = configuration || {}
const storageClient = providers?.storage || LocalStorageClient()

Expand Down Expand Up @@ -95,6 +97,7 @@ export const RadixDappToolkit = (
useDoneCallback: configuration?.useDoneCallback,
subjects: stateSubjects,
getState,
useCache,
})

if (configuration?.onStateChange)
Expand Down
7 changes: 6 additions & 1 deletion src/state/helpers/handle-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export const handleRequest = (
state,
logger,
walletClient,
useCache = true,
}: {
state: State
logger?: Logger<unknown>
walletClient: WalletClient
useCache: boolean
}
) => {
const canBeResolvedByState = resolvableByState(state, dataRequest)
Expand All @@ -41,7 +43,10 @@ export const handleRequest = (
dataRequest.oneTimePersonaData

const resolveByState =
canBeResolvedByState && !containsResetRequest && !containsOneTimeRequest
canBeResolvedByState &&
!containsResetRequest &&
!containsOneTimeRequest &&
useCache

if (resolveByState) {
logger?.debug(`resolvedByState`, state)
Expand Down
4 changes: 4 additions & 0 deletions src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const StateClient = (input: {
onDisconnectCallback: OnDisconnectCallback
useDoneCallback?: boolean
getState: GetState
useCache?: boolean
}) => {
const key = input.key
const subjects = input.subjects
Expand All @@ -64,6 +65,7 @@ export const StateClient = (input: {
const connectDoneCallback = input.useDoneCallback
const disconnectCallback = input.onDisconnectCallback
const getState = input.getState
const useCache = input.useCache ?? true
const subscriptions = new Subscription()

const readStateFromStorage = () =>
Expand Down Expand Up @@ -252,6 +254,7 @@ export const StateClient = (input: {
state,
logger,
walletClient,
useCache,
})
.map(({ data: response, resolvedBy }) => {
if (resolvedBy === 'wallet') {
Expand Down Expand Up @@ -318,6 +321,7 @@ export const StateClient = (input: {
state,
logger,
walletClient,
useCache,
})
.map(({ data }) => {
const {
Expand Down

0 comments on commit 2f1a22a

Please sign in to comment.