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: add TX ignore #218

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const RequestStatus = {
success: 'success',
fail: 'fail',
cancelled: 'cancelled',
ignored: 'ignored',
} as const

export const RequestItemType = {
Expand Down
4 changes: 1 addition & 3 deletions packages/connect-button/.storybook/preview.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/connect-button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type ConnectButtonEvents = {
onConnect: () => void
onDisconnect: () => void
onCancelRequestItem: (event: CustomEvent<{ id: string }>) => void
onIgnoreTransactionItem: (event: CustomEvent<{ id: string }>) => void
onDestroy: () => void
onShowPopover: () => void
onUpdateSharedData: () => void
Expand All @@ -110,7 +111,8 @@ type ConnectButtonEvents = {

- onConnect - triggers when user clicks connect now button
- onDisconnect - triggers when user clicks disconnect wallet button
- onCancelRequestItem - triggers when user cancels connect request
- onCancelRequestItem - triggers when user cancels data or login request
- onIgnoreTransactionItem - triggers when user ignores transaction output
- onDestroy - triggers when button is removed from the DOM. Useful for cleaning up registered event listeners and subscriptions.
- onShowPopover - triggers when users clicks on radix button and popover is being shown
- onUpdateSharedData - triggers when users clicks on "Update Shared Data" button
Expand Down
3 changes: 2 additions & 1 deletion packages/connect-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/radixdlt/connect-button.git"
"url": "git+https://github.com/radixdlt/radix-dapp-toolkit.git",
"directory": "packages/connect-button"
}
}
10 changes: 10 additions & 0 deletions packages/connect-button/src/assets/icon-ignored.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions packages/connect-button/src/components/card/card.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meta, StoryObj } from '@storybook/web-components'
import './card'

import './persona-card'
import './request-card'
import '../popover/popover'
Expand Down Expand Up @@ -89,8 +90,11 @@ export const Requests: Story = {
status="${args.status}"
type="${args.type}"
timestamp=${args.timestamp}
@onCancel=${(event: any) => {
console.log(event)
@onCancelRequestItem=${(event: any) => {
console.log('onCancelRequestItem', event)
}}
@onIgnoreTransactionItem=${(event: any) => {
console.log('onIgnoreTransactionItem', event)
}}
?showCancel="${args.showCancel}"
transactionIntentHash="${args.transactionIntentHash}"
Expand All @@ -103,7 +107,7 @@ export const Requests: Story = {
control: 'select',
},
status: {
options: ['pending', 'success', 'fail', 'cancelled'],
options: ['pending', 'success', 'fail', 'cancelled', 'ignored'],
control: 'select',
},
timestamp: {
Expand Down
10 changes: 9 additions & 1 deletion packages/connect-button/src/components/card/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UncheckedIcon from '../../assets/unchecked.svg'
import CheckedIcon from '../../assets/checked.svg'
import IconLoading from '../../assets/icon-loading.svg'
import IconFailed from '../../assets/icon-failed.svg'
import IconIgnored from '../../assets/icon-ignored.svg'
import { formatTimestamp } from '../../helpers/format-timestamp'

@customElement('radix-card')
Expand All @@ -13,7 +14,7 @@ export class RadixCard extends LitElement {
type: String,
reflect: true,
})
icon?: 'unchecked' | 'checked' | 'pending' | 'success' | 'error'
icon?: 'unchecked' | 'checked' | 'pending' | 'success' | 'error' | 'ignored'

@property({
type: String,
Expand Down Expand Up @@ -120,6 +121,13 @@ export class RadixCard extends LitElement {
height: 24px;
}

:host([icon='ignored']) i::before {
-webkit-mask-image: url(${unsafeCSS(IconIgnored)});
mask-image: url(${unsafeCSS(IconIgnored)});
width: 24px;
height: 24px;
}

:host([icon='checked']) i::before {
-webkit-mask-image: url(${unsafeCSS(CheckedIcon)});
mask-image: url(${unsafeCSS(CheckedIcon)});
Expand Down
70 changes: 58 additions & 12 deletions packages/connect-button/src/components/card/request-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ import '../account/account'
import '../link/link'
import { shortenAddress } from '../../helpers/shorten-address'
import { classMap } from 'lit/directives/class-map.js'
import { RequestItemType, RequestStatus } from 'radix-connect-common'
import {
RequestItemTypes,
RequestStatusTypes,
RequestStatus,
} from 'radix-connect-common'
@customElement('radix-request-card')
export class RadixRequestCard extends LitElement {
@property({
type: String,
})
type: keyof typeof RequestItemType = 'dataRequest'
type: RequestItemTypes = 'dataRequest'

@property({
type: String,
})
status: keyof typeof RequestStatus = 'pending'
status: RequestStatusTypes = 'pending'

@property({
type: Boolean,
})
showCancel: boolean = false

@property({
type: Boolean,
})
showIgnore: boolean = false

@property({
type: String,
})
Expand All @@ -46,18 +55,29 @@ export class RadixRequestCard extends LitElement {
pending: 'Pending Transaction',
fail: 'Transaction Failed',
cancelled: 'Transaction Cancelled',
ignored: 'Transaction Ignored',
success: 'Send transaction',
content: html`
${this.renderTxIntentHash()}
${this.getRequestContentTemplate(
'Open your Radix Wallet app to review the transaction',
)}
${this.status === 'pending'
? html`<div class="request-content">
Open your Radix Wallet app to review the transaction
${this.showCancel
? html`<div class="cancel" @click=${this.onCancel}>
Cancel
</div>`
: html`<div class="cancel" @click=${this.onIgnore}>
Ignore
</div>`}
</div>`
: ''}
`,
},
dataRequest: {
pending: 'Data Request Pending',
fail: 'Data Request Rejected',
cancelled: 'Data Request Rejected',
ignored: '',
success: 'Data Request',
content: this.getRequestContentTemplate(
'Open Your Radix Wallet App to complete the request',
Expand All @@ -68,6 +88,7 @@ export class RadixRequestCard extends LitElement {
fail: 'Login Request Rejected',
cancelled: 'Login Request Rejected',
success: 'Login Request',
ignored: '',
content: this.getRequestContentTemplate(
'Open Your Radix Wallet App to complete the request',
),
Expand All @@ -85,7 +106,7 @@ export class RadixRequestCard extends LitElement {
}

private getRequestContentTemplate(text: string) {
return this.status === 'pending'
return this.status === RequestStatus.pending
? html`<div class="request-content">
${text}
${this.showCancel
Expand All @@ -95,17 +116,29 @@ export class RadixRequestCard extends LitElement {
: ''
}

private isErrorStatus(status: RequestStatusTypes) {
return (
[
RequestStatus.cancelled,
RequestStatus.fail,
RequestStatus.ignored,
] as string[]
).includes(status)
}

private getIconFromStatus() {
return this.status === 'pending'
return this.status === RequestStatus.pending
? 'pending'
: this.status === 'cancelled' || this.status === 'fail'
? 'error'
: 'checked'
: this.status === RequestStatus.ignored
? 'ignored'
: this.isErrorStatus(this.status)
? 'error'
: 'checked'
}

private getStylingFromStatus() {
return classMap({
dimmed: this.status === 'fail' || this.status === 'cancelled',
dimmed: this.isErrorStatus(this.status),
inverted: this.status === 'pending',
})
}
Expand All @@ -123,6 +156,19 @@ export class RadixRequestCard extends LitElement {
)
}

private onIgnore(event: MouseEvent) {
this.dispatchEvent(
new CustomEvent('onIgnoreTransactionItem', {
detail: {
...event,
id: this.id,
},
bubbles: true,
composed: true,
}),
)
}

private renderTxIntentHash() {
return this.transactionIntentHash
? html`<div class="transaction">
Expand Down
9 changes: 0 additions & 9 deletions packages/connect-button/src/components/card/request-cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ export class RadixRequestCards extends LitElement {
status="${requestItem.status}"
id="${requestItem.interactionId}"
?showCancel="${requestItem.showCancel}"
@onCancel=${(event: any) => {
this.dispatchEvent(
new CustomEvent('onCancel', {
detail: event.detail,
bubbles: true,
composed: true,
}),
)
}}
timestamp=${requestItem.createdAt}
></radix-request-card>`,
)
Expand Down
9 changes: 0 additions & 9 deletions packages/connect-button/src/components/pages/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ export class RadixRequestsPage extends LitElement {
id="${requestItem.interactionId}"
transactionIntentHash="${requestItem.transactionIntentHash || ''}"
?showCancel="${requestItem.showCancel}"
@onCancel=${(event: any) => {
this.dispatchEvent(
new CustomEvent('onCancel', {
detail: event.detail,
bubbles: true,
composed: true,
}),
)
}}
timestamp=${requestItem.createdAt}
></radix-request-card>`,
)}
Expand Down
5 changes: 3 additions & 2 deletions packages/dapp-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/radixdlt/radix-dapp-toolkit.git"
"url": "git+https://github.com/radixdlt/radix-dapp-toolkit.git",
"directory": "packages/dapp-toolkit"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}
}
Loading
Loading