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

Submit transactions in bulk #219

Merged
merged 63 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
383718f
Add bulkTx proto
ThibautBremand Jul 18, 2023
9a9a9af
Bulk submit once, at the end of the stepper
ThibautBremand Jul 19, 2023
2e984dc
Revamp RecapView for bulk transactions
ThibautBremand Jul 19, 2023
1a71862
Revamp StepperView for bulk transactions
ThibautBremand Jul 19, 2023
a70c91b
Add progress bar
ThibautBremand Jul 19, 2023
f746730
Fix API response
ThibautBremand Jul 20, 2023
8c4181d
Change API response type
ThibautBremand Jul 20, 2023
a630605
Use Pagination instead of Stepper
ThibautBremand Jul 20, 2023
a21a6c6
Fix StepperView UI
ThibautBremand Jul 20, 2023
0ef7029
Refactor bulkTx input type
ThibautBremand Jul 20, 2023
e73206d
Improve error handling
ThibautBremand Jul 20, 2023
28b1810
Rework messaging for submitTransactionsBulk
ThibautBremand Jul 24, 2023
5641f60
Add demo for submitTransactionsBulk
ThibautBremand Jul 24, 2023
8bee46a
Rework storageInMemory
ThibautBremand Jul 24, 2023
b9d4f0b
Use Record for passing transactions to submitTransactionsBulk view
ThibautBremand Jul 26, 2023
cc2106d
Fix UI issues
ThibautBremand Jul 30, 2023
85d662f
Populate handleSubmitTransactionsBulk in index.html demo
ThibautBremand Jul 30, 2023
77ff60d
Add opt-in step to SubmitTransactionsBulk view
ThibautBremand Jul 30, 2023
40436bf
Refactor SubmitTransactionsBulk view
ThibautBremand Jul 30, 2023
334ea9a
Update network fees tooltip in submitTransactionsBulk view
ThibautBremand Jul 31, 2023
fb056c6
Improve StepperView UI
ThibautBremand Aug 1, 2023
8ed1a2e
Do not display steps in StepperView if there is only one step
ThibautBremand Aug 1, 2023
2488083
Temp
ThibautBremand Aug 1, 2023
3688f8c
fix resolver
ThibautBremand Aug 3, 2023
74ac943
Display NFT images in submitTransactionsBulk view
ThibautBremand Aug 1, 2023
cf732e6
Display NFT names in submitTransactionsBulk view
ThibautBremand Aug 3, 2023
2c824ee
Update StepperView styling
ThibautBremand Aug 3, 2023
05909b2
Display Amounts in StepperView
ThibautBremand Aug 4, 2023
ec07e77
Temp
ThibautBremand Aug 5, 2023
6d62ced
Fix build post rebase
ThibautBremand Aug 10, 2023
9933b4b
Throttle between batches
ThibautBremand Aug 10, 2023
92157eb
Force sequential handling of bulk transactions
ThibautBremand Aug 10, 2023
ffdd9d6
Rename noWait param
ThibautBremand Aug 10, 2023
a48f171
Simplify code
ThibautBremand Aug 10, 2023
378d7a2
Fix post rebase
ThibautBremand Aug 12, 2023
a4687a8
Fix error handling in SubmitTransactionsBulk
ThibautBremand Aug 12, 2023
efc9e3b
Fix misc code parts
ThibautBremand Aug 12, 2023
7ffd244
Add missing Permissions view
ThibautBremand Aug 13, 2023
3424851
Rename SubmitTransactionsBulkWithKeysRequest type
ThibautBremand Aug 13, 2023
7e85668
Add a MAX_TRANSACTIONS limit
ThibautBremand Aug 13, 2023
3d1e64f
Export API types
ThibautBremand Aug 13, 2023
a6b84ed
Delete from chrome storage once read
ThibautBremand Aug 13, 2023
a49a1af
Fix post rebase
ThibautBremand Aug 13, 2023
5ccf7b4
Change resolveNFTData signature
ThibautBremand Aug 17, 2023
4a0cc5a
Add comments
ThibautBremand Aug 17, 2023
4ffbb0b
Refactor storage management
ThibautBremand Aug 17, 2023
5652297
Fix cypress tests
ThibautBremand Aug 17, 2023
3cb1f29
Fix post rebase
ThibautBremand Aug 17, 2023
1851066
Refactor NFTDataResolver calls post rebase
ThibautBremand Aug 20, 2023
942e28a
Isolate connectToLedger logic
ThibautBremand Aug 20, 2023
f94901f
Update code post review
ThibautBremand Aug 20, 2023
1ff76bc
Fix post rebase
ThibautBremand Aug 20, 2023
25d021a
Fix post rebase
ThibautBremand Aug 30, 2023
123ed50
Throttle between each network fees estimation in useFees hook
ThibautBremand Aug 31, 2023
7a68728
Add cypress test
ThibautBremand Aug 31, 2023
cb53a15
Fix cypress tests
ThibautBremand Aug 31, 2023
0e534ad
Fix long strings display for raw transactions
ThibautBremand Aug 31, 2023
e431509
Rename noWait param into waitForHashes
ThibautBremand Aug 31, 2023
660c1f3
Cleanup index.html
FlorianBouron Aug 31, 2023
583b806
Rename submitTxBulk to submitBulkTx
FlorianBouron Aug 31, 2023
9c5a2c6
Replace ID by id
FlorianBouron Aug 31, 2023
9a6a8b9
Rename types for the bulk tx
FlorianBouron Aug 31, 2023
546ff07
Cleanup the code
FlorianBouron Sep 1, 2023
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"cSpell.words": ["gemwallet"],
"cSpell.words": ["gemwallet", "xrpl"],
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
Expand Down
7 changes: 5 additions & 2 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './setTrustline';
export * from './signMessage';
export * from './signTransaction';
export * from './submitTransaction';
export * from './submitBulkTransactions';

export type { Amount } from 'xrpl/dist/npm/models/common';
export type {
Expand All @@ -43,7 +44,8 @@ export type {
SetTrustlineRequest,
SignMessageRequest,
SignTransactionRequest,
SubmitTransactionRequest
SubmitTransactionRequest,
SubmitBulkTransactionsRequest
} from '@gemwallet/constants';

// API response types
Expand All @@ -65,5 +67,6 @@ export type {
SetTrustlineResponse,
SignMessageResponse,
SignTransactionResponse,
SubmitTransactionResponse
SubmitTransactionResponse,
SubmitBulkTransactionsResponse
} from '@gemwallet/constants';
1 change: 1 addition & 0 deletions packages/api/src/submitBulkTransactions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './submitBulkTransactions';
55 changes: 55 additions & 0 deletions packages/api/src/submitBulkTransactions/submitBulkTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
SubmitBulkTransactionsResponse,
GEM_WALLET,
ResponseType,
RequestSubmitBulkTransactionsMessage,
TransactionWithID,
SubmitBulkTransactionsRequest
} from '@gemwallet/constants';

import { deserializeError } from '../helpers/errors';
import { sendMessageToContentScript } from '../helpers/extensionMessaging';

const MAX_TRANSACTIONS = 50;

export const submitBulkTransactions = async (
payload: SubmitBulkTransactionsRequest
): Promise<SubmitBulkTransactionsResponse> => {
let response: SubmitBulkTransactionsResponse = {
type: ResponseType.Reject,
result: undefined
};

if (payload.transactions.length === 0 || payload.transactions.length > MAX_TRANSACTIONS) {
throw new Error(`Invalid number of transactions (must be between 1 and ${MAX_TRANSACTIONS})`);
}

try {
const message: RequestSubmitBulkTransactionsMessage = {
app: GEM_WALLET,
type: 'REQUEST_SUBMIT_BULK_TRANSACTIONS/V3',
payload: {
...payload,
// Add an index to each transaction so that we can process them in order
transactions: payload.transactions.reduce((acc, transaction, index) => {
acc[index] = transaction;
return acc;
}, {} as Record<number, TransactionWithID>)
}
};

const { result, error } = await sendMessageToContentScript(message);
const parsedError = error ? deserializeError(error) : undefined;
if (parsedError) {
throw parsedError;
}

if (result) {
response.type = ResponseType.Response;
response.result = result;
}
} catch (e) {
throw e;
}
return response;
};
66 changes: 66 additions & 0 deletions packages/api/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<button onclick="handleCancelOffer()">Cancel Offer (check the console)</button>
<button onclick="handleSubmitTransaction()">Submit transaction (check the console)</button>
<button onclick="handleSignTransaction()">Sign transaction (check the console)</button>
<button onclick="handlesubmitBulkTransactions()">
Submit transactions (Bulk) (check the console)
</button>
<button onclick="handleEvents()">Activate events (check the console)</button>
<div id="address"></div>
</div>
Expand Down Expand Up @@ -547,6 +550,69 @@
console.error('GemWallet is not connected: ', e);
});
}
function handlesubmitBulkTransactions() {
GemWalletApi.isInstalled()
.then(({ result }) => {
if (result.isInstalled) {
const transactions = [
...[
{
ID: '001',
TransactionType: 'TrustSet',
LimitAmount: {
currency: 'ETH',
issuer: 'rnm76Qgz4G9G4gZBJVuXVvkbt7gVD7szey',
value: '10000000'
},
Memos: [
{
Memo: {
MemoType: '4465736372697074696f6e',
MemoData: '54657374206d656d6f'
}
}
],
Fee: '199'
},
{
ID: '002',
TransactionType: 'NFTokenMint',
URI: '516D6654463665756E47726A57597642666A72614B486D765572354444566D525351424373513252564D71764A72',
NFTokenTaxon: 0
}
],
...Array.from({ length: 48 }, (_, index) => ({
ID: String(index + 1).padStart(3, '3'),
TransactionType: 'Payment',
Destination: 'rhikRdkFw28csKw9z7fVoBjWncz1HSoQij',
Amount: '100000',
Memos: [
{
Memo: {
MemoData: '54657374206D656D6F',
MemoType: '4465736372697074696F6E'
}
}
]
}))
];
GemWalletApi.submitBulkTransactions({
transactions,
onError: 'abort',
waitForHashes: false
})
.then((res) => {
console.log('Received response: ', res);
})
.catch((e) => {
console.error('Something went wrong: ', e);
});
}
})
.catch((e) => {
console.error('GemWallet is not connected: ', e);
});
}
function handleEvents() {
GemWalletApi.isInstalled()
.then(({ result }) => {
Expand Down
15 changes: 14 additions & 1 deletion packages/constants/src/event/event.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SignMessageRequest,
SignTransactionRequest,
SubmitTransactionRequest,
SubmitBulkTransactionsWithKeysRequest,
WebsiteRequest
} from '../payload/payload.types';

Expand All @@ -45,6 +46,7 @@ interface MessageEventData {
| SetTrustlineRequestDeprecated
| SignMessageRequest
| SubmitTransactionRequest
| SubmitBulkTransactionsWithKeysRequest
| WebsiteRequest;
}

Expand Down Expand Up @@ -256,6 +258,16 @@ export interface SignTransactionEventListener extends MessageEvent<MessageEventD
};
}

export interface SubmitBulkTransactionsEventListener extends MessageEvent<MessageEventData> {
data: {
app: typeof GEM_WALLET;
type: 'REQUEST_SUBMIT_BULK_TRANSACTIONS/V3';
source: 'GEM_WALLET_MSG_REQUEST';
messageId: number;
payload: SubmitBulkTransactionsWithKeysRequest;
};
}

export interface SetAccountEventListener extends MessageEvent<MessageEventData> {
data: {
app: typeof GEM_WALLET;
Expand Down Expand Up @@ -310,7 +322,8 @@ export type EventListener =
| SignMessageListener
| SignMessageListenerDeprecated
| SignTransactionEventListener
| SubmitTransactionEventListener;
| SubmitTransactionEventListener
| SubmitBulkTransactionsEventListener;

// Events
interface EventEventData {
Expand Down
28 changes: 26 additions & 2 deletions packages/constants/src/message/message.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import {
SignTransactionRequest,
SubmitTransactionResponse,
SubmitTransactionRequest,
SubmitBulkTransactionsWithKeysRequest,
SubmitBulkTransactionsResponse,
WebsiteRequest
} from '../payload/payload.types';
import {
Expand Down Expand Up @@ -79,6 +81,7 @@ export type RequestMessage =
| 'REQUEST_SIGN_MESSAGE/V3'
| 'REQUEST_SIGN_TRANSACTION/V3'
| 'REQUEST_SUBMIT_TRANSACTION/V3'
| 'REQUEST_SUBMIT_BULK_TRANSACTIONS/V3'
| 'SEND_PAYMENT';

export type ReceiveMessage =
Expand All @@ -105,7 +108,8 @@ export type ReceiveMessage =
| 'RECEIVE_SIGN_MESSAGE'
| 'RECEIVE_SIGN_MESSAGE/V3'
| 'RECEIVE_SIGN_TRANSACTION/V3'
| 'RECEIVE_SUBMIT_TRANSACTION/V3';
| 'RECEIVE_SUBMIT_TRANSACTION/V3'
| 'RECEIVE_SUBMIT_BULK_TRANSACTIONS/V3';

export type EventMessage =
| 'EVENT_NETWORK_CHANGED'
Expand Down Expand Up @@ -260,6 +264,12 @@ export interface RequestSignTransactionMessage {
payload: SignTransactionRequest;
}

export interface RequestSubmitBulkTransactionsMessage {
app: typeof GEM_WALLET;
type: 'REQUEST_SUBMIT_BULK_TRANSACTIONS/V3';
payload: SubmitBulkTransactionsWithKeysRequest;
}

// Internal
export interface InternalRequestPasswordMessage {
app: typeof GEM_WALLET;
Expand Down Expand Up @@ -312,6 +322,8 @@ export type SignMessageMessagingResponseDeprecated = MessagingResponse &
SignMessageResponseDeprecated;
export type SignTransactionMessagingResponse = MessagingResponse & SignTransactionResponse;
export type SubmitTransactionMessagingResponse = MessagingResponse & SubmitTransactionResponse;
export type SubmitBulkTransactionsMessagingResponse = MessagingResponse &
SubmitBulkTransactionsResponse;
export type IsInstalledMessagingResponse = MessagingResponse & IsInstalledResponse;
export type SendPaymentMessagingResponse = MessagingResponse & SendPaymentResponse;
export type SendPaymentMessagingResponseDeprecated = MessagingResponse &
Expand Down Expand Up @@ -478,6 +490,12 @@ export interface ReceiveSignTransactionContentMessage {
payload: SignTransactionMessagingResponse;
}

export interface ReceiveSubmitBulkTransactionsContentMessage {
app: typeof GEM_WALLET;
type: 'RECEIVE_SUBMIT_BULK_TRANSACTIONS/V3';
payload: SubmitBulkTransactionsMessagingResponse;
}

// Internal
export interface InternalReceivePasswordContentMessage {
app: typeof GEM_WALLET;
Expand Down Expand Up @@ -605,6 +623,9 @@ export type ReceiveSignTransactionBackgroundMessage = ReceiveSignTransactionCont
export type ReceiveSubmitTransactionBackgroundMessage = ReceiveSubmitTransactionContentMessage &
BackgroundMessagePayload;

export type ReceiveSubmitBulkTransactionsBackgroundMessage =
ReceiveSubmitBulkTransactionsContentMessage & BackgroundMessagePayload;

export type InternalReceivePasswordBackgroundMessage = InternalReceivePasswordContentMessage &
BackgroundMessagePayload;

Expand Down Expand Up @@ -650,6 +671,7 @@ export type BackgroundMessage =
| RequestSignMessageMessageDeprecated
| RequestSignTransactionMessage
| RequestSubmitTransactionMessage
| RequestSubmitBulkTransactionsMessage
// Outputted Messages - DO contain ID within the payloads
| EventLoginBackgroundMessage
| EventLogoutBackgroundMessage
Expand Down Expand Up @@ -679,6 +701,7 @@ export type BackgroundMessage =
| ReceiveSignMessageBackgroundMessageDeprecated
| ReceiveSignTransactionBackgroundMessage
| ReceiveSubmitTransactionBackgroundMessage
| ReceiveSubmitBulkTransactionsBackgroundMessage
//
// Internal message - Messages between the extension and the background script
//
Expand Down Expand Up @@ -712,4 +735,5 @@ export type APIMessages =
| RequestSetTrustlineMessage
| RequestSignMessageMessage
| RequestSignTransactionMessage
| RequestSubmitTransactionMessage;
| RequestSubmitTransactionMessage
| RequestSubmitBulkTransactionsMessage;
4 changes: 3 additions & 1 deletion packages/constants/src/network/network.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export enum NetworkServer {
MAINNET = 'wss://xrplcluster.com',
TESTNET = 'wss://s.altnet.rippletest.net:51233',
DEVNET = 'wss://s.devnet.rippletest.net:51233',
AMM_DEVNET = 'wss://amm.devnet.rippletest.net:51233'
AMM_DEVNET = 'wss://amm.devnet.rippletest.net:51233',
MAINNET_S1 = 'wss://s1.ripple.com', // Clio
MAINNET_S2 = 'wss://s2.ripple.com' // Clio
}

export const NETWORK = {
Expand Down
Loading