MythicLegendary / SP10_FALL_2022

2 stars 0 forks source link

Create a transaction History #47

Closed wildwilliam2 closed 1 year ago

wildwilliam2 commented 1 year ago

Create an array of addresses/transactions we have used and store it in the local state.

Something like

{

      transaction: {
            memo : string
             amount : any
             address : string
             denom: string
             fee: StdFee,
             typeURL: string,
             ...
            }
}
wildwilliam2 commented 1 year ago

Once that is done, create a card that returns and formats the response neatly in a notification.

wildwilliam2 commented 1 year ago

Probably should have an array in the snap _state that holds transaction objects

wildwilliam2 commented 1 year ago

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.

wildwilliam2 commented 1 year ago

Completed by Manu