Closed wildwilliam2 closed 1 year ago
Once that is done, create a card that returns and formats the response neatly in a notification.
Probably should have an array in the snap _state that holds transaction objects
Will need to record transactions made in: createSend createMultiSend delegation redelegation undelegation ...
Here is how I would implement: i - make a card for the front-end to view transactions. (index.tsx) "View Recent Transactions" Take as input the number of transactions to print out. The methodName will be transactionHistory. ii - in the backend, add a method handler for 'transactionHistory' (in the giant rpc switch statement) (index.ts) call the function like so:
case 'transactionHistory': {
return await getTransactionHistory(request.params[0].amount);
}
implement the getTransaction history as an async fcuntion that takes the number of recent transactions to return. It should return UP to that amount; if the amount is greater than return all that their is. i.e. - min(transActionHIstory.length, amount)
iii. initialize the transaactionHistory in the pluginState by setting it to an empty array in clearConfigData() (index.ts)
iv - define a Transaction type at the top of the file, that will hold on the properties of a transaction something like:
interface Transaction {
memo : string,
amount : any,
sendingAddress : string,
fromAddress :string
denom: string,
fee: StdFee,
typeURL: string,
}
v - in the backend create a generalized function to add transactions to the transactionHistory like so
async function addTransaction(newTransaction : Transaction) {
let currentState : any = await getPluginState();
currentState.transactionHistory.add(newTransaction);
await updatePluginState(currentState);
return {transactionAdded : true};
}
Call this in the functions that already use transactions: multi-send, send.
vi - Finally, print out the transaction neatly in the notifcation created in snap.ts.
Completed by Manu
Create an array of addresses/transactions we have used and store it in the local state.
Something like