Skip to content

Commit

Permalink
Merge pull request #841 from airgap-it/feat/beacon_styles
Browse files Browse the repository at this point in the history
Feat/beacon styles
  • Loading branch information
IsaccoSordo authored Jan 13, 2025
2 parents e888c0e + 881c107 commit c698ba7
Show file tree
Hide file tree
Showing 32 changed files with 5,083 additions and 3,275 deletions.
5,575 changes: 3,180 additions & 2,395 deletions package-lock.json

Large diffs are not rendered by default.

106 changes: 53 additions & 53 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ export class DAppClient extends Client {
connectionInfo.origin === Origin.P2P
? this.p2pTransport
: connectionInfo.origin === Origin.WALLETCONNECT
? this.walletConnectTransport
: this.postMessageTransport ?? (await this.transport)
? this.walletConnectTransport
: this.postMessageTransport ?? (await this.transport)

if (relevantTransport) {
const peers: ExtendedPeerInfo[] = await relevantTransport.getPeers()
Expand Down Expand Up @@ -440,8 +440,8 @@ export class DAppClient extends Client {
res.status === 426
? console.error('Metrics are no longer supported for this version, please upgrade.')
: console.warn(
'Network error encountered. Metrics sharing have been automatically disabled.'
)
'Network error encountered. Metrics sharing have been automatically disabled.'
)
}
this.enableMetrics = res.ok
this.storage.set(StorageKey.ENABLE_METRICS, res.ok)
Expand Down Expand Up @@ -814,7 +814,7 @@ export class DAppClient extends Client {
this.postMessageTransport =
this.walletConnectTransport =
this.p2pTransport =
undefined
undefined
this._activeAccount.isResolved() && this.clearActiveAccount()
this._initPromise = undefined
},
Expand Down Expand Up @@ -1380,9 +1380,9 @@ export class DAppClient extends Client {
logger.time(true, logId)
const res = (await this.checkMakeRequest())
? this.makeRequestV3<
BlockchainRequestV3<string>,
BeaconMessageWrapper<BlockchainResponseV3<string>>
>(request)
BlockchainRequestV3<string>,
BeaconMessageWrapper<BlockchainResponseV3<string>>
>(request)
: this.makeRequestBC<any, any>(request)

res.catch(async (requestError: ErrorResponse) => {
Expand Down Expand Up @@ -1594,13 +1594,13 @@ export class DAppClient extends Client {

const res = (await this.checkMakeRequest())
? this.makeRequest<
SimulatedProofOfEventChallengeRequest,
SimulatedProofOfEventChallengeResponse
>(request)
SimulatedProofOfEventChallengeRequest,
SimulatedProofOfEventChallengeResponse
>(request)
: this.makeRequestBC<
SimulatedProofOfEventChallengeRequest,
SimulatedProofOfEventChallengeResponse
>(request)
SimulatedProofOfEventChallengeRequest,
SimulatedProofOfEventChallengeResponse
>(request)

res.catch(async (requestError: ErrorResponse) => {
requestError.errorType === BeaconErrorType.ABORTED_ERROR
Expand Down Expand Up @@ -2064,50 +2064,50 @@ export class DAppClient extends Client {
request: BeaconRequestInputMessage,
response:
| {
account: AccountInfo
output: PermissionResponseOutput
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
account: AccountInfo
output: PermissionResponseOutput
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
| {
account: AccountInfo
output: ProofOfEventChallengeResponse
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
account: AccountInfo
output: ProofOfEventChallengeResponse
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
| {
account: AccountInfo
output: SimulatedProofOfEventChallengeResponse
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
account: AccountInfo
output: SimulatedProofOfEventChallengeResponse
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
| {
account: AccountInfo
output: OperationResponseOutput
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
account: AccountInfo
output: OperationResponseOutput
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
| {
output: SignPayloadResponseOutput
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
output: SignPayloadResponseOutput
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
// | {
// output: EncryptPayloadResponseOutput
// connectionContext: ConnectionContext
// walletInfo: WalletInfo
// }
| {
network: Network
output: BroadcastResponseOutput
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
network: Network
output: BroadcastResponseOutput
blockExplorer: BlockExplorer
connectionContext: ConnectionContext
walletInfo: WalletInfo
}
): Promise<void> {
this.events
.emit(messageEvents[request.type].success, response)
Expand Down Expand Up @@ -2348,7 +2348,7 @@ export class DAppClient extends Client {

logger.log('makeRequest', 'sending message', request)
try {
; (await this.transport).send(payload, peer)
;(await this.transport).send(payload, peer)
if (
request.type !== BeaconMessageType.PermissionRequest ||
(this._activeAccount.isResolved() && (await this._activeAccount.promise))
Expand Down Expand Up @@ -2464,7 +2464,7 @@ export class DAppClient extends Client {

logger.log('makeRequest', 'sending message', request)
try {
; (await this.transport).send(payload, peer)
;(await this.transport).send(payload, peer)
if (
request.message.type !== BeaconMessageType.PermissionRequest ||
(this._activeAccount.isResolved() && (await this._activeAccount.promise))
Expand Down Expand Up @@ -2511,9 +2511,9 @@ export class DAppClient extends Client {
request: Optional<T, IgnoredRequestInputProperties>
): Promise<
| {
message: U
connectionInfo: ConnectionContext
}
message: U
connectionInfo: ConnectionContext
}
| undefined
> {
if (!this._transport.isResolved()) {
Expand Down
166 changes: 83 additions & 83 deletions packages/beacon-dapp/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,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 @@ -517,22 +517,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 @@ -551,22 +551,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 @@ -772,56 +772,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
Loading

0 comments on commit c698ba7

Please sign in to comment.