-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON Transaction submitter (#339)
* Add Advanced Mode permission * Add BuildTransaction view * Improve JSON editor UI * Add Beautify button * Add cypress tests * Handle offline mode * Fix error display * Rename into 'Submit Raw Transaction'
- Loading branch information
1 parent
a463286
commit 57a9933
Showing
17 changed files
with
566 additions
and
67 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
packages/extension/cypress/e2e/submit_raw_json_tx.cy.ts
This file contains 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,124 @@ | ||
import { Chain, XRPLNetwork } from '@gemwallet/constants'; | ||
|
||
import { navigate } from '../utils/navigation'; | ||
|
||
// deepcode ignore NoHardcodedPasswords: password used for testing purposes | ||
const SUBMIT_RAW_TRANSACTION_PATH = 'http://localhost:3000/build-transaction?transaction=buildRaw'; | ||
const PASSWORD = 'SECRET_PASSWORD'; | ||
|
||
beforeEach(() => { | ||
// Mock the localStorage with a wallet already loaded | ||
cy.window().then((win) => { | ||
win.localStorage.setItem( | ||
'wallets', | ||
'U2FsdGVkX19VA07d7tVhAAtUbt+YVbw0xQY7OZMykOW4YI4nRZK9iZ7LT3+xHvrj4kwlPKEcRg0S1GjbIWSFaMzg3Mw8fklZrZLL9QZvnbF821SeDB5lBBj/F9PBg8A07uZhYz1p4sTDsWAOFvrnKJjmlWIqXzN5MFFbWBb3os2xGtAGTslFVUXuTp6eM9X9' | ||
); | ||
win.localStorage.setItem( | ||
'network', | ||
JSON.stringify({ | ||
chain: Chain.XRPL, | ||
name: XRPLNetwork.TESTNET | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('JSON Transaction', () => { | ||
it('Sign JSON Transaction', () => { | ||
navigate(SUBMIT_RAW_TRANSACTION_PATH, PASSWORD); | ||
|
||
const rawTx = `{ | ||
"TransactionType": "Payment", | ||
"Destination": "rhikRdkFw28csKw9z7fVoBjWncz1HSoQij", | ||
"Amount": "100000", | ||
"Memos": [ | ||
{ | ||
"Memo": { | ||
"MemoData": "54657374206D656D6F", | ||
"MemoType": "4465736372697074696F6E" | ||
} | ||
} | ||
] | ||
}`; | ||
|
||
cy.get('.json-editor').type(rawTx); | ||
|
||
// Type extra character to trigger validation | ||
cy.get('.json-editor').type('a'); | ||
|
||
// Click on 'Sign' button | ||
cy.get('button').contains('Sign').click(); | ||
|
||
// 'Invalid JSON' error should be displayed | ||
cy.contains('Invalid JSON'); | ||
|
||
// Remove extra character | ||
cy.get('.json-editor').type('{backspace}'); | ||
|
||
// Click on 'Sign' button | ||
cy.get('button').contains('Sign').click(); | ||
|
||
// 'Sign Transaction' modal should be displayed | ||
cy.contains('Sign Transaction'); | ||
cy.contains('Amount').next().should('have.text', '0.1 XRP'); | ||
|
||
// Click on 'Sign' button | ||
cy.get('button').contains('Sign').click(); | ||
|
||
cy.get('h1[data-testid="transaction-title"]').contains('Transaction accepted', { | ||
timeout: 10000 | ||
}); | ||
}); | ||
|
||
it('Submit JSON Transaction', () => { | ||
navigate(SUBMIT_RAW_TRANSACTION_PATH, PASSWORD); | ||
|
||
const rawTx = `{ | ||
"TransactionType": "Payment", | ||
"Destination": "rhikRdkFw28csKw9z7fVoBjWncz1HSoQij", | ||
"Amount": "100000", | ||
"Memos": [ | ||
{ | ||
"Memo": { | ||
"MemoData": "54657374206D656D6F", | ||
"MemoType": "4465736372697074696F6E" | ||
} | ||
} | ||
] | ||
}`; | ||
|
||
cy.get('.json-editor').type(rawTx); | ||
|
||
// Type extra character to trigger validation | ||
cy.get('.json-editor').type('a'); | ||
|
||
// Click on 'Sign' button | ||
cy.get('button').contains('Sign').click(); | ||
|
||
// 'Invalid JSON' error should be displayed | ||
cy.contains('Invalid JSON'); | ||
|
||
// Remove extra character | ||
cy.get('.json-editor').type('{backspace}'); | ||
|
||
// Click on 'Submit' button | ||
cy.get('button').contains('Submit').click(); | ||
|
||
// 'Submit Transaction' modal should be displayed | ||
cy.contains('Submit Transaction'); | ||
cy.contains('Amount').next().should('have.text', '0.1 XRP'); | ||
|
||
// Click on 'Submit' button | ||
cy.get('button').contains('Submit').click(); | ||
|
||
cy.get('h1[data-testid="transaction-title"]').should('have.text', 'Transaction in progress'); | ||
cy.get('p[data-testid="transaction-subtitle"]').should( | ||
'have.text', | ||
'We are processing your transactionPlease wait' | ||
); | ||
|
||
cy.get('h1[data-testid="transaction-title"]').contains('Transaction accepted', { | ||
timeout: 10000 | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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
34 changes: 34 additions & 0 deletions
34
packages/extension/src/components/pages/Permissions/PermissionsSwitch.tsx
This file contains 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,34 @@ | ||
import { FC } from 'react'; | ||
|
||
import { Switch, Typography } from '@mui/material'; | ||
|
||
export interface PermissionSwitchProps { | ||
isEnabled: boolean; | ||
toggleSwitch: () => void; | ||
name: string; | ||
description: string; | ||
} | ||
|
||
export const PermissionSwitch: FC<PermissionSwitchProps> = ({ | ||
isEnabled, | ||
toggleSwitch, | ||
name, | ||
description | ||
}) => { | ||
return ( | ||
<div style={{ marginTop: '0.5rem' }}> | ||
<div style={{ display: 'flex', alignItems: 'center' }}> | ||
<Switch | ||
checked={isEnabled} | ||
onChange={toggleSwitch} | ||
color="primary" | ||
inputProps={{ 'aria-label': `Enable or disable ${name.toLowerCase()}` }} | ||
/> | ||
<Typography style={{ marginLeft: '1rem' }}>{name}</Typography> | ||
</div> | ||
<Typography variant="body2" color="textSecondary" style={{ marginLeft: '0.7rem' }}> | ||
{description} | ||
</Typography> | ||
</div> | ||
); | ||
}; |
This file contains 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
Oops, something went wrong.