Skip to content

Commit

Permalink
fix: hide UI notifications on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Nov 14, 2024
1 parent 0ab714e commit de660db
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 85 deletions.
169 changes: 85 additions & 84 deletions packages/beacon-dapp/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
// EncryptionOperation
} from '@airgap/beacon-core'
import { shortenString } from './utils/shorten-string'
import { isMobile } from '@airgap/beacon-ui'
import { isMobile, isMobileOS } from '@airgap/beacon-ui'

const logger = new Logger('BeaconEvents')

Expand Down Expand Up @@ -209,9 +209,9 @@ export interface BeaconEventType {
featuredWallets?: string[]
}
[BeaconEvent.PAIR_SUCCESS]:
| ExtendedPostMessagePairingResponse
| ExtendedP2PPairingResponse
| ExtendedWalletConnectPairingResponse
| ExtendedPostMessagePairingResponse
| ExtendedP2PPairingResponse
| ExtendedWalletConnectPairingResponse
[BeaconEvent.CHANNEL_CLOSED]: string
[BeaconEvent.INTERNAL_ERROR]: { text: string; buttons?: AlertButton[] }
[BeaconEvent.UNKNOWN]: undefined
Expand Down Expand Up @@ -261,6 +261,7 @@ const showSentToast = async (data: RequestSentInfo): Promise<void> => {
body: `Request sent to\u00A0 {{wallet}}`,
walletInfo: data.walletInfo,
state: 'loading',
timer: isMobileOS(window) ? SUCCESS_TIMER : 0,
actions,
openWalletAction
}).catch((toastError) => console.error(toastError))
Expand Down Expand Up @@ -518,22 +519,22 @@ const showProofOfEventChallengeSuccessAlert = async (
state: 'finished',
actions: output.isAccepted
? [
{
text: `Payload hash: ${output.payloadHash}`,
actionText: 'Copy to clipboard',
actionCallback: async (): Promise<void> => {
navigator.clipboard.writeText(output.payloadHash).then(
() => {
logger.log('showSignSuccessAlert', 'Copying to clipboard was successful!')
},
(err) => {
logger.error('showSignSuccessAlert', 'Could not copy text to clipboard: ', err)
}
)
await closeToast()
}
{
text: `Payload hash: ${output.payloadHash}`,
actionText: 'Copy to clipboard',
actionCallback: async (): Promise<void> => {
navigator.clipboard.writeText(output.payloadHash).then(
() => {
logger.log('showSignSuccessAlert', 'Copying to clipboard was successful!')
},
(err) => {
logger.error('showSignSuccessAlert', 'Could not copy text to clipboard: ', err)
}
)
await closeToast()
}
]
}
]
: []
})
}
Expand All @@ -552,22 +553,22 @@ const showSimulatedProofOfEventChallengeSuccessAlert = async (
state: 'finished',
actions: !output.errorMessage
? [
{
text: 'Operation list',
actionText: 'Copy to clipboard',
actionCallback: async (): Promise<void> => {
navigator.clipboard.writeText(output.operationsList).then(
() => {
logger.log('showSignSuccessAlert', 'Copying to clipboard was successful!')
},
(err) => {
logger.error('showSignSuccessAlert', 'Could not copy text to clipboard: ', err)
}
)
await closeToast()
}
{
text: 'Operation list',
actionText: 'Copy to clipboard',
actionCallback: async (): Promise<void> => {
navigator.clipboard.writeText(output.operationsList).then(
() => {
logger.log('showSignSuccessAlert', 'Copying to clipboard was successful!')
},
(err) => {
logger.error('showSignSuccessAlert', 'Could not copy text to clipboard: ', err)
}
)
await closeToast()
}
]
}
]
: [{ text: 'Error message', actionText: output.errorMessage }]
})
}
Expand Down Expand Up @@ -773,56 +774,56 @@ export class BeaconEventHandler {
private readonly callbackMap: {
[key in BeaconEvent]: BeaconEventHandlerFunction<any>[] // TODO: Fix type
} = {
[BeaconEvent.PERMISSION_REQUEST_SENT]: [defaultEventCallbacks.PERMISSION_REQUEST_SENT],
[BeaconEvent.PERMISSION_REQUEST_SUCCESS]: [defaultEventCallbacks.PERMISSION_REQUEST_SUCCESS],
[BeaconEvent.PERMISSION_REQUEST_ERROR]: [defaultEventCallbacks.PERMISSION_REQUEST_ERROR],
[BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT]: [
defaultEventCallbacks.PERMISSION_REQUEST_SENT
],
[BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS]: [
defaultEventCallbacks.PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS
],
[BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR]: [
defaultEventCallbacks.PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR
],
[BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT]: [
defaultEventCallbacks.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT
],
[BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS]: [
defaultEventCallbacks.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS
],
[BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR]: [
defaultEventCallbacks.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR
],
[BeaconEvent.OPERATION_REQUEST_SENT]: [defaultEventCallbacks.OPERATION_REQUEST_SENT],
[BeaconEvent.OPERATION_REQUEST_SUCCESS]: [defaultEventCallbacks.OPERATION_REQUEST_SUCCESS],
[BeaconEvent.OPERATION_REQUEST_ERROR]: [defaultEventCallbacks.OPERATION_REQUEST_ERROR],
[BeaconEvent.SIGN_REQUEST_SENT]: [defaultEventCallbacks.SIGN_REQUEST_SENT],
[BeaconEvent.SIGN_REQUEST_SUCCESS]: [defaultEventCallbacks.SIGN_REQUEST_SUCCESS],
[BeaconEvent.SIGN_REQUEST_ERROR]: [defaultEventCallbacks.SIGN_REQUEST_ERROR],
// TODO: ENCRYPTION
// [BeaconEvent.ENCRYPT_REQUEST_SENT]: [defaultEventCallbacks.ENCRYPT_REQUEST_SENT],
// [BeaconEvent.ENCRYPT_REQUEST_SUCCESS]: [defaultEventCallbacks.ENCRYPT_REQUEST_SUCCESS],
// [BeaconEvent.ENCRYPT_REQUEST_ERROR]: [defaultEventCallbacks.ENCRYPT_REQUEST_ERROR],
[BeaconEvent.BROADCAST_REQUEST_SENT]: [defaultEventCallbacks.BROADCAST_REQUEST_SENT],
[BeaconEvent.BROADCAST_REQUEST_SUCCESS]: [defaultEventCallbacks.BROADCAST_REQUEST_SUCCESS],
[BeaconEvent.BROADCAST_REQUEST_ERROR]: [defaultEventCallbacks.BROADCAST_REQUEST_ERROR],
[BeaconEvent.ACKNOWLEDGE_RECEIVED]: [defaultEventCallbacks.ACKNOWLEDGE_RECEIVED],
[BeaconEvent.LOCAL_RATE_LIMIT_REACHED]: [defaultEventCallbacks.LOCAL_RATE_LIMIT_REACHED],
[BeaconEvent.NO_PERMISSIONS]: [defaultEventCallbacks.NO_PERMISSIONS],
[BeaconEvent.ACTIVE_ACCOUNT_SET]: [defaultEventCallbacks.ACTIVE_ACCOUNT_SET],
[BeaconEvent.ACTIVE_TRANSPORT_SET]: [defaultEventCallbacks.ACTIVE_TRANSPORT_SET],
[BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: [
defaultEventCallbacks.INVALID_ACTIVE_ACCOUNT_STATE
],
[BeaconEvent.SHOW_PREPARE]: [defaultEventCallbacks.SHOW_PREPARE],
[BeaconEvent.HIDE_UI]: [defaultEventCallbacks.HIDE_UI],
[BeaconEvent.PAIR_INIT]: [defaultEventCallbacks.PAIR_INIT],
[BeaconEvent.PAIR_SUCCESS]: [defaultEventCallbacks.PAIR_SUCCESS],
[BeaconEvent.CHANNEL_CLOSED]: [defaultEventCallbacks.CHANNEL_CLOSED],
[BeaconEvent.INTERNAL_ERROR]: [defaultEventCallbacks.INTERNAL_ERROR],
[BeaconEvent.UNKNOWN]: [defaultEventCallbacks.UNKNOWN]
}
[BeaconEvent.PERMISSION_REQUEST_SENT]: [defaultEventCallbacks.PERMISSION_REQUEST_SENT],
[BeaconEvent.PERMISSION_REQUEST_SUCCESS]: [defaultEventCallbacks.PERMISSION_REQUEST_SUCCESS],
[BeaconEvent.PERMISSION_REQUEST_ERROR]: [defaultEventCallbacks.PERMISSION_REQUEST_ERROR],
[BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT]: [
defaultEventCallbacks.PERMISSION_REQUEST_SENT
],
[BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS]: [
defaultEventCallbacks.PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS
],
[BeaconEvent.PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR]: [
defaultEventCallbacks.PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR
],
[BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT]: [
defaultEventCallbacks.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SENT
],
[BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS]: [
defaultEventCallbacks.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_SUCCESS
],
[BeaconEvent.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR]: [
defaultEventCallbacks.SIMULATED_PROOF_OF_EVENT_CHALLENGE_REQUEST_ERROR
],
[BeaconEvent.OPERATION_REQUEST_SENT]: [defaultEventCallbacks.OPERATION_REQUEST_SENT],
[BeaconEvent.OPERATION_REQUEST_SUCCESS]: [defaultEventCallbacks.OPERATION_REQUEST_SUCCESS],
[BeaconEvent.OPERATION_REQUEST_ERROR]: [defaultEventCallbacks.OPERATION_REQUEST_ERROR],
[BeaconEvent.SIGN_REQUEST_SENT]: [defaultEventCallbacks.SIGN_REQUEST_SENT],
[BeaconEvent.SIGN_REQUEST_SUCCESS]: [defaultEventCallbacks.SIGN_REQUEST_SUCCESS],
[BeaconEvent.SIGN_REQUEST_ERROR]: [defaultEventCallbacks.SIGN_REQUEST_ERROR],
// TODO: ENCRYPTION
// [BeaconEvent.ENCRYPT_REQUEST_SENT]: [defaultEventCallbacks.ENCRYPT_REQUEST_SENT],
// [BeaconEvent.ENCRYPT_REQUEST_SUCCESS]: [defaultEventCallbacks.ENCRYPT_REQUEST_SUCCESS],
// [BeaconEvent.ENCRYPT_REQUEST_ERROR]: [defaultEventCallbacks.ENCRYPT_REQUEST_ERROR],
[BeaconEvent.BROADCAST_REQUEST_SENT]: [defaultEventCallbacks.BROADCAST_REQUEST_SENT],
[BeaconEvent.BROADCAST_REQUEST_SUCCESS]: [defaultEventCallbacks.BROADCAST_REQUEST_SUCCESS],
[BeaconEvent.BROADCAST_REQUEST_ERROR]: [defaultEventCallbacks.BROADCAST_REQUEST_ERROR],
[BeaconEvent.ACKNOWLEDGE_RECEIVED]: [defaultEventCallbacks.ACKNOWLEDGE_RECEIVED],
[BeaconEvent.LOCAL_RATE_LIMIT_REACHED]: [defaultEventCallbacks.LOCAL_RATE_LIMIT_REACHED],
[BeaconEvent.NO_PERMISSIONS]: [defaultEventCallbacks.NO_PERMISSIONS],
[BeaconEvent.ACTIVE_ACCOUNT_SET]: [defaultEventCallbacks.ACTIVE_ACCOUNT_SET],
[BeaconEvent.ACTIVE_TRANSPORT_SET]: [defaultEventCallbacks.ACTIVE_TRANSPORT_SET],
[BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: [
defaultEventCallbacks.INVALID_ACTIVE_ACCOUNT_STATE
],
[BeaconEvent.SHOW_PREPARE]: [defaultEventCallbacks.SHOW_PREPARE],
[BeaconEvent.HIDE_UI]: [defaultEventCallbacks.HIDE_UI],
[BeaconEvent.PAIR_INIT]: [defaultEventCallbacks.PAIR_INIT],
[BeaconEvent.PAIR_SUCCESS]: [defaultEventCallbacks.PAIR_SUCCESS],
[BeaconEvent.CHANNEL_CLOSED]: [defaultEventCallbacks.CHANNEL_CLOSED],
[BeaconEvent.INTERNAL_ERROR]: [defaultEventCallbacks.INTERNAL_ERROR],
[BeaconEvent.UNKNOWN]: [defaultEventCallbacks.UNKNOWN]
}
constructor(
eventsToOverride: {
[key in BeaconEvent]?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient {
}

private async checkWalletReadiness(_topic: string) {
if (this.pingInterval) {
if (this.isMobileOS() || this.pingInterval) {
return
}

Expand Down

0 comments on commit de660db

Please sign in to comment.