Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: react #815

Draft
wants to merge 94 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
47a470e
feat: init react
IsaccoSordo Sep 5, 2024
3c441aa
fix: info styles
IsaccoSordo Sep 5, 2024
bc8775b
feat: add info alert
IsaccoSordo Sep 5, 2024
930d0c5
fix: render
IsaccoSordo Sep 6, 2024
6e68846
feat: add useConnect
IsaccoSordo Sep 6, 2024
36e567a
feat: init useConnect
IsaccoSordo Sep 9, 2024
335348d
feat: use useConnect
IsaccoSordo Sep 9, 2024
3df3ca0
fix: removed unnecessary async
IsaccoSordo Sep 9, 2024
5c84a78
fix: onClose
IsaccoSordo Sep 9, 2024
024b1b4
chore: removed css files
IsaccoSordo Sep 9, 2024
1a141ec
feat: init mui
IsaccoSordo Sep 9, 2024
7f4e6fa
fix: render
IsaccoSordo Sep 9, 2024
5cef681
fix: styling
IsaccoSordo Sep 9, 2024
153d103
fix: display full list
IsaccoSordo Sep 10, 2024
5f496db
fix: showMore
IsaccoSordo Sep 10, 2024
d393902
fix: removed content in favor of children
IsaccoSordo Sep 10, 2024
24f829f
chore: rename
IsaccoSordo Sep 10, 2024
1028e2f
fix: conversion issue
IsaccoSordo Sep 10, 2024
c1bd891
fix: add all logic back
IsaccoSordo Sep 11, 2024
ceb1a69
fix: heder style
IsaccoSordo Sep 11, 2024
034fc1d
fix: styling
IsaccoSordo Sep 11, 2024
4a4c4a5
fix: button size
IsaccoSordo Sep 11, 2024
7d9eed7
fix: style
IsaccoSordo Sep 11, 2024
5f71a79
fix: styling
IsaccoSordo Sep 11, 2024
2c40f7a
fix: useWallets
IsaccoSordo Sep 11, 2024
936fa3b
fix: styling
IsaccoSordo Sep 11, 2024
a96c574
fix: positioning
IsaccoSordo Sep 12, 2024
70b73bd
fix: merge
IsaccoSordo Nov 29, 2024
4999720
fix: unnecessary hooks
IsaccoSordo Jan 7, 2025
c6b8b4d
fix: style
IsaccoSordo Jan 7, 2025
7e664ca
fix: styles
IsaccoSordo Jan 7, 2025
8570c30
feat: bug-report form mui converstion
IsaccoSordo Jan 7, 2025
8fe2a41
feat: pair-other mui migration
IsaccoSordo Jan 9, 2025
6fd8224
feat: wc error mui migration
IsaccoSordo Jan 9, 2025
4816e40
fix: styling
IsaccoSordo Jan 9, 2025
da62120
fix: wallets rendering
IsaccoSordo Jan 10, 2025
cb1b136
fix: padding
IsaccoSordo Jan 10, 2025
8ad7eb3
fix: size
IsaccoSordo Jan 10, 2025
c43a96b
feat: completed card styles migration
IsaccoSordo Jan 10, 2025
21e403f
Revert "chore: removed css files"
IsaccoSordo Jan 13, 2025
b5be8c2
fix: css bundling
IsaccoSordo Jan 13, 2025
ceccdf9
fix: revert
IsaccoSordo Jan 13, 2025
c054c0b
fix: revert
IsaccoSordo Jan 13, 2025
152fa42
fix: onClose
IsaccoSordo Jan 13, 2025
310564d
fix: background-color
IsaccoSordo Jan 13, 2025
1174df1
chore: code cleanup
IsaccoSordo Jan 15, 2025
d61702e
fix: alert animations
IsaccoSordo Jan 15, 2025
9816c39
feat: add toast back
IsaccoSordo Jan 14, 2025
edbeb18
feat: mount&unmount on root
IsaccoSordo Jan 16, 2025
5230106
fix: disable loader on dragging
IsaccoSordo Jan 16, 2025
146c45b
fix: toast animation
IsaccoSordo Jan 16, 2025
e262711
feat: add props to toast
IsaccoSordo Jan 16, 2025
35d2cd8
fix: double next
IsaccoSordo Jan 16, 2025
58804e2
fix: styles
IsaccoSordo Jan 16, 2025
43b7e88
fix: improved dragging
IsaccoSordo Jan 16, 2025
da1bcaf
fix: max width on desktop
IsaccoSordo Jan 16, 2025
cf022ab
fix: draggable image
IsaccoSordo Jan 16, 2025
430a4c4
fix: rebase
IsaccoSordo Jan 28, 2025
ce5452c
fix: rebase
IsaccoSordo Jan 28, 2025
d3a30b1
feat: add info alert
IsaccoSordo Jan 30, 2025
56afab2
fix: onClose
IsaccoSordo Jan 30, 2025
d3cacfc
fix: dynamic config
IsaccoSordo Jan 30, 2025
a7fa7c8
fix: color mode
IsaccoSordo Jan 30, 2025
ba20fda
fix: useWallets rewrite
IsaccoSordo Jan 31, 2025
21d0c22
fix: qr pairing button not appearing
IsaccoSordo Jan 31, 2025
0fe9226
fix: mobile pairing logic
IsaccoSordo Jan 31, 2025
5d1cfed
feat: init RTL and jest
IsaccoSordo Feb 4, 2025
85a4011
fix: npm test
IsaccoSordo Feb 4, 2025
9ddaa06
feat: add bug-report-form test
IsaccoSordo Feb 4, 2025
0ea5b4e
fix: add explanation for SDK_VERSION
IsaccoSordo Feb 4, 2025
addee80
feat: add Info test
IsaccoSordo Feb 4, 2025
becea96
feat: add pair other test
IsaccoSordo Feb 4, 2025
c384c2a
feat: add QR test
IsaccoSordo Feb 4, 2025
8b84a42
feat: toast test
IsaccoSordo Feb 4, 2025
727c74d
feat: add top wallets unit test
IsaccoSordo Feb 4, 2025
dc84075
feat: add wallet test
IsaccoSordo Feb 4, 2025
5fafc15
feat: wallets test
IsaccoSordo Feb 4, 2025
a8dacd0
feat: add info alert test
IsaccoSordo Feb 4, 2025
2a6d79a
feat: pairing alert test
IsaccoSordo Feb 4, 2025
2eb3afe
fix: jest setup
IsaccoSordo Feb 4, 2025
9312b7d
fix: setupFilesAfterEnv
IsaccoSordo Feb 4, 2025
d492c0b
fix: pipeline
IsaccoSordo Feb 4, 2025
03d320d
fix: coverage
IsaccoSordo Feb 4, 2025
b25994a
fix: padding
IsaccoSordo Feb 5, 2025
49bdb6f
feat: useConnect test
IsaccoSordo Feb 7, 2025
9780896
fix: coverage
IsaccoSordo Feb 7, 2025
1bb1744
feat: init useIsMobile test
IsaccoSordo Feb 7, 2025
2e39c6b
feat: useWallets unit test
IsaccoSordo Feb 7, 2025
6cb6f98
fix: coverage
IsaccoSordo Feb 7, 2025
83bacbe
fix: config
IsaccoSordo Feb 7, 2025
17e0d80
fix: pipeline
IsaccoSordo Feb 7, 2025
ca51bdc
feat: add terser
IsaccoSordo Feb 7, 2025
7270173
Merge pull request #850 from airgap-it/feat/react_unit_testing
IsaccoSordo Feb 7, 2025
eb3da5f
fix: coverage bump
IsaccoSordo Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19,380 changes: 10,958 additions & 8,422 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@
"pre-commit": "npm run check-version && pretty-quick --staged"
}
}
}
}
27 changes: 12 additions & 15 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,23 +818,20 @@ export class DAppClient extends Client {
this._initPromise = undefined
}

await p2pTransport.connect()

const serializer = new Serializer()
const p2pPeerInfo = await serializer.serialize(await p2pTransport.getPairingRequestInfo())
const walletConnectPeerInfo = (await walletConnectTransport.getPairingRequestInfo()).uri
const postmessagePeerInfo = await serializer.serialize(
await postMessageTransport.getPairingRequestInfo()
)

this.events
.emit(BeaconEvent.PAIR_INIT, {
p2pPeerInfo: () => {
p2pTransport
.connect()
.then()
.catch((err) => {
logger.error(err)
if (err.message === 'The account is deactivated.') {
this.hideUI(['alert'])
abortHandler()
}
})
return p2pTransport.getPairingRequestInfo()
},
postmessagePeerInfo: () => postMessageTransport.getPairingRequestInfo(),
walletConnectPeerInfo: () => walletConnectTransport.getPairingRequestInfo(),
p2pPeerInfo,
postmessagePeerInfo,
walletConnectPeerInfo,
networkType: this.network.type,
abortedHandler: abortHandler.bind(this),
disclaimerText: this.disclaimerText,
Expand Down
138 changes: 66 additions & 72 deletions packages/beacon-dapp/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
import {
BeaconErrorType,
ExtendedPostMessagePairingResponse,
PostMessagePairingRequest,
ExtendedP2PPairingResponse,
P2PPairingRequest,
AccountInfo,
ErrorResponse,
PermissionResponseOutput,
Expand All @@ -26,7 +24,6 @@ import {
AcknowledgeResponse,
WalletInfo,
ExtendedWalletConnectPairingResponse,
WalletConnectPairingRequest,
AnalyticsInterface,
ProofOfEventChallengeResponseOutput,
SimulatedProofOfEventChallengeResponseOutput
Expand Down Expand Up @@ -201,19 +198,19 @@ export interface BeaconEventType {
[BeaconEvent.SHOW_PREPARE]: { walletInfo?: WalletInfo }
[BeaconEvent.HIDE_UI]: ('alert' | 'toast')[] | undefined
[BeaconEvent.PAIR_INIT]: {
p2pPeerInfo: () => Promise<P2PPairingRequest>
postmessagePeerInfo: () => Promise<PostMessagePairingRequest>
walletConnectPeerInfo: () => Promise<WalletConnectPairingRequest>
p2pPeerInfo: string
postmessagePeerInfo: string
walletConnectPeerInfo: string
networkType: NetworkType
abortedHandler?(): void
disclaimerText?: string
analytics: AnalyticsInterface
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 @@ -249,7 +246,7 @@ const showSentToast = async (data: RequestSentInfo): Promise<void> => {
text: 'Wallet not receiving request?',
actionText: 'Reset Connection',
actionCallback: async (): Promise<void> => {
await closeToast()
closeToast()
// eslint-disable-next-line @typescript-eslint/unbound-method
const resetCallback = data.extraInfo.resetCallback
if (resetCallback) {
Expand All @@ -266,7 +263,7 @@ const showSentToast = async (data: RequestSentInfo): Promise<void> => {
timer: isMobileOS(window) ? SUCCESS_TIMER : 0,
actions,
openWalletAction
}).catch((toastError) => console.error(toastError))
})
}

const showAcknowledgedToast = async (data: {
Expand All @@ -278,7 +275,7 @@ const showAcknowledgedToast = async (data: {
body: 'Awaiting confirmation in\u00A0 {{wallet}}',
state: 'acknowledge',
walletInfo: data.walletInfo
}).catch((toastError) => console.error(toastError))
})
}

const showPrepare = async (data: { walletInfo?: WalletInfo }): Promise<void> => {
Expand All @@ -289,27 +286,24 @@ const showPrepare = async (data: { walletInfo?: WalletInfo }): Promise<void> =>
body: text,
state: 'prepare',
walletInfo: data.walletInfo
}).catch((toastError) => console.error(toastError))
})
}

const hideUI = async (elements?: ('alert' | 'toast')[]): Promise<void> => {
if (elements) {
if (elements.includes('alert')) {
await closeAlerts()
}
if (elements.includes('toast')) {
await closeToast()
}
} else {
await closeToast()
if (elements?.includes('alert')) {
closeAlerts()
}

if (elements?.includes('toast') || !elements) {
closeToast()
}
}

/**
* Show a "No Permission" alert
*/
const showNoPermissionAlert = async (): Promise<void> => {
await openAlert({
openAlert({
title: 'No Permission',
body: 'Please allow the wallet to handle this type of request.'
})
Expand All @@ -319,7 +313,7 @@ const showNoPermissionAlert = async (): Promise<void> => {
* Show an "Invalid state" alert
*/
const showInvalidActiveAccountState = async (): Promise<void> => {
await openAlert({
openAlert({
title: 'Invalid state',
body: `An active account has been received, but no active subscription was found for BeaconEvent.ACTIVE_ACCOUNT_SET.
For more information, visit: https://docs.walletbeacon.io/guides/migration-guide`
Expand Down Expand Up @@ -391,8 +385,8 @@ const showErrorToast = async (
text: '',
actionText: 'Show Details',
actionCallback: async (): Promise<void> => {
await closeToast()
await openAlert({
closeToast()
openAlert({
title: error.title,
// eslint-disable-next-line @typescript-eslint/unbound-method
body: error.fullDescription.description,
Expand All @@ -403,7 +397,7 @@ const showErrorToast = async (
})
}

await openToast({
openToast({
body: `{{wallet}}\u00A0 has returned an error`,
timer:
response.errorResponse.errorType === BeaconErrorType.ABORTED_ERROR
Expand All @@ -424,7 +418,7 @@ const showRateLimitReached = async (): Promise<void> => {
body: 'Rate limit reached. Please slow down',
buttons: [{ text: 'Done', style: 'outline' }],
timer: 3000
}).catch((toastError) => console.error(toastError))
})
}

/**
Expand All @@ -438,7 +432,7 @@ const showExtensionConnectedAlert = async (): Promise<void> => {
* Show a "channel closed" alert for 1.5 seconds
*/
const showChannelClosedAlert = async (): Promise<void> => {
// await openAlert({
// openAlert({
// title: 'Channel closed',
// body: `Your peer has closed the connection.`,
// buttons: [{ text: 'Done', style: 'outline' }],
Expand All @@ -458,7 +452,7 @@ const showInternalErrorAlert = async (
body: data.text,
buttons
}
await openAlert(alertConfig)
openAlert(alertConfig)
}

/**
Expand All @@ -483,7 +477,7 @@ const showPairAlert = async (data: BeaconEventType[BeaconEvent.PAIR_INIT]): Prom
analytics: data.analytics,
featuredWallets: data.featuredWallets
}
await openAlert(alertConfig)
openAlert(alertConfig)
}

/**
Expand All @@ -496,7 +490,7 @@ const showPermissionSuccessAlert = async (
): Promise<void> => {
const { output } = data

await openToast({
openToast({
body: `{{wallet}}\u00A0 has granted permission`,
timer: SUCCESS_TIMER,
walletInfo: data.walletInfo,
Expand Down Expand Up @@ -524,29 +518,29 @@ const showProofOfEventChallengeSuccessAlert = async (
): Promise<void> => {
const { output } = data

await openToast({
openToast({
body: `{{wallet}}\u00A0 has ${output.isAccepted ? 'accepted' : 'refused'} the challenge`,
timer: SUCCESS_TIMER,
walletInfo: data.walletInfo,
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)
}
)
closeToast()
}
}
}
]
]
: []
})
}
Expand All @@ -556,7 +550,7 @@ const showSimulatedProofOfEventChallengeSuccessAlert = async (
): Promise<void> => {
const { output } = data

await openToast({
openToast({
body: !output.errorMessage
? `{{wallet}}\u00A0 has returned the list of operation`
: `{{wallet}}\u00A0 has returned an error`,
Expand All @@ -565,22 +559,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)
}
)
closeToast()
}
}
}
]
]
: [{ text: 'Error message', actionText: output.errorMessage }]
})
}
Expand All @@ -595,7 +589,7 @@ const showOperationSuccessAlert = async (
): Promise<void> => {
const { account, output, blockExplorer } = data

await openToast({
openToast({
body: `{{wallet}}\u00A0 successfully submitted operation`,
timer: SUCCESS_TIMER,
state: 'finished',
Expand All @@ -612,7 +606,7 @@ const showOperationSuccessAlert = async (
account.network
)
window.open(link, '_blank', 'noopener')
await closeToast()
closeToast()
}
}
]
Expand All @@ -628,7 +622,7 @@ const showSignSuccessAlert = async (
data: BeaconEventType[BeaconEvent.SIGN_REQUEST_SUCCESS]
): Promise<void> => {
const output = data.output
await openToast({
openToast({
body: `{{wallet}}\u00A0 successfully signed payload`,
timer: SUCCESS_TIMER,
state: 'finished',
Expand All @@ -646,7 +640,7 @@ const showSignSuccessAlert = async (
logger.error('showSignSuccessAlert', 'Could not copy text to clipboard: ', err)
}
)
await closeToast()
closeToast()
}
}
]
Expand All @@ -663,7 +657,7 @@ const showSignSuccessAlert = async (
// data: BeaconEventType[BeaconEvent.ENCRYPT_REQUEST_SUCCESS]
// ): Promise<void> => {
// const output = data.output
// await openToast({
// openToast({
// body: `{{wallet}}\u00A0 successfully ${
// data.output.cryptoOperation === EncryptionOperation.ENCRYPT ? 'encrypted' : 'decrypted'
// } payload`,
Expand All @@ -683,7 +677,7 @@ const showSignSuccessAlert = async (
// logger.error('showSignSuccessAlert', 'Could not copy text to clipboard: ', err)
// }
// )
// await closeToast()
// closeToast()
// }
// }
// ]
Expand All @@ -700,7 +694,7 @@ const showBroadcastSuccessAlert = async (
): Promise<void> => {
const { network, output, blockExplorer } = data

await openToast({
openToast({
body: `{{wallet}}\u00A0 successfully injected operation`,
timer: SUCCESS_TIMER,
state: 'finished',
Expand All @@ -717,7 +711,7 @@ const showBroadcastSuccessAlert = async (
network
)
window.open(link, '_blank', 'noopener')
await closeToast()
closeToast()
}
}
]
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-ui/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Loading
Loading