-
Notifications
You must be signed in to change notification settings - Fork 142
Permission Delegation support #1315
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9fad955
inital commit
cybele-ripple ca28cc1
added new definitions to all translation files
cybele-ripple ca076ad
linter fix
cybele-ripple beb5a3b
fix test error
cybele-ripple ea371bb
Refactor PermissionDelegation and unify collapsible sections
cybele-ripple 5e01781
Switch PermissionDelegation test to MemoryRouter from react-router
cybele-ripple fe5e0ab
Fix lint and deflake PermissionDelegation tests
cybele-ripple f38c14d
Restore translation keys removed from branch
cybele-ripple 3090e55
test: assert permission-delegation renders in static parts test
cybele-ripple 0c4ec6e
Merge branch 'main' into explorer-permission-delegation
cybele-ripple fa880a2
Merge remote-tracking branch 'ripple/main' into explorer-permission-d…
cybele-ripple 00bb7d0
Merge origin/explorer-permission-delegation to reconcile diverged loc…
cybele-ripple 1b844a1
Merge branch 'main' into explorer-permission-delegation
cybele-ripple File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -757,6 +757,13 @@ | |
| "account_page_asset_table_no_lptoken": null, | ||
| "account_page_asset_table_no_mpt": null, | ||
| "account_page_asset_table_no_nft": null, | ||
| "account_page_permission_delegation": null, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works like it should |
||
| "account_page_permission_delegation_column_permission": null, | ||
| "account_page_permission_delegation_column_granted_to": null, | ||
| "account_page_permission_delegation_column_status": null, | ||
| "account_page_permission_delegation_status_active": null, | ||
| "account_page_permission_delegation_status_expired": null, | ||
| "account_page_permission_delegation_no_delegations": null, | ||
| "tx_hash": null, | ||
| "timestamp": null, | ||
| "amount_in": null, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import { useState, useContext } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { useQuery } from 'react-query' | ||
| import ArrowIcon from '../../shared/images/down_arrow.svg' | ||
| import { Account } from '../../shared/components/Account' | ||
| import { Loader } from '../../shared/components/Loader' | ||
| import { EmptyMessageTableRow } from '../../shared/EmptyMessageTableRow' | ||
| import { getAccountObjects } from '../../../rippled/lib/rippled' | ||
| import SocketContext from '../../shared/SocketContext' | ||
| import { shortenAccount } from '../../shared/utils' | ||
| import '../AccountAsset/styles.scss' | ||
| import './styles.scss' | ||
|
|
||
| interface DelegateObject { | ||
| Account: string | ||
| Authorize: string | ||
| Permissions: Array<{ | ||
| Permission: { | ||
| PermissionValue: string | ||
| } | ||
| }> | ||
| LedgerEntryType: string | ||
| } | ||
|
|
||
| interface PermissionDelegationProps { | ||
| accountId: string | ||
| } | ||
|
|
||
| export const PermissionDelegation = ({ | ||
| accountId, | ||
| }: PermissionDelegationProps) => { | ||
| const { t } = useTranslation() | ||
| const rippledSocket = useContext(SocketContext) | ||
| const [isOpen, setIsOpen] = useState(true) | ||
|
|
||
| const { data, isLoading } = useQuery( | ||
| ['accountDelegates', accountId], | ||
| () => getAccountObjects(rippledSocket, accountId, 'delegate'), | ||
| { enabled: !!accountId }, | ||
| ) | ||
|
|
||
| const delegates: DelegateObject[] = data?.account_objects ?? [] | ||
|
|
||
| // Don't render the section if there are no delegations and we're done loading | ||
| if (!isLoading && delegates.length === 0) { | ||
| return null | ||
|
kuan121 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return ( | ||
| <section className="account-asset permission-delegation"> | ||
| <div className="asset-section-header"> | ||
| <h3 className="account-asset-title"> | ||
| {t('account_page_permission_delegation')} | ||
| </h3> | ||
| <button | ||
| type="button" | ||
| className="asset-section-toggle" | ||
| onClick={() => setIsOpen((s) => !s)} | ||
| aria-expanded={isOpen} | ||
| aria-label="Toggle permission delegation" | ||
| > | ||
| <ArrowIcon | ||
| className={`asset-section-arrow ${isOpen ? 'open' : ''}`} | ||
| /> | ||
| </button> | ||
| </div> | ||
|
kuan121 marked this conversation as resolved.
Outdated
|
||
| {isOpen && ( | ||
| <div className="permission-delegation-table-wrapper"> | ||
| {isLoading ? ( | ||
| <Loader /> | ||
| ) : ( | ||
| <div className="account-asset-table"> | ||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th> | ||
| {t( | ||
| 'account_page_permission_delegation_column_permission', | ||
| )} | ||
| </th> | ||
| <th> | ||
| {t( | ||
| 'account_page_permission_delegation_column_granted_to', | ||
| )} | ||
| </th> | ||
| <th> | ||
| {t('account_page_permission_delegation_column_status')} | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
|
kuan121 marked this conversation as resolved.
Outdated
|
||
| {delegates.length === 0 ? ( | ||
| <EmptyMessageTableRow colSpan={3}> | ||
| {t('account_page_permission_delegation_no_delegations')} | ||
| </EmptyMessageTableRow> | ||
| ) : ( | ||
|
kuan121 marked this conversation as resolved.
Outdated
|
||
| delegates.flatMap((delegate) => | ||
| delegate.Permissions.map((perm) => ( | ||
| <tr | ||
| key={`${delegate.Authorize}-${perm.Permission.PermissionValue}`} | ||
| > | ||
| <td>{perm.Permission.PermissionValue}</td> | ||
| <td> | ||
| <Account | ||
| account={delegate.Authorize} | ||
| displayText={shortenAccount(delegate.Authorize)} | ||
| /> | ||
| </td> | ||
| <td> | ||
| {t( | ||
| 'account_page_permission_delegation_status_active', | ||
|
kuan121 marked this conversation as resolved.
Outdated
|
||
| )} | ||
| </td> | ||
| </tr> | ||
| )), | ||
| ) | ||
| )} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| )} | ||
| </div> | ||
| )} | ||
| </section> | ||
| ) | ||
| } | ||
|
|
||
| export default PermissionDelegation | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* PermissionDelegation-specific overrides. | ||
| Layout, header, toggle, arrow, and table base styles are reused | ||
| from AccountAsset via the shared .account-asset / .asset-section-header / | ||
| .account-asset-table classes. */ | ||
|
|
||
| .permission-delegation .permission-delegation-table-wrapper { | ||
|
kuan121 marked this conversation as resolved.
Outdated
|
||
| .loader { | ||
| min-height: 50px; | ||
| } | ||
|
|
||
| /* Override the large min-width from account-asset-table since we only have 3 columns */ | ||
| .account-asset-table table { | ||
| min-width: 0; | ||
| } | ||
|
kuan121 marked this conversation as resolved.
Outdated
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.