How to use the @requestnetwork/utils.uniqueByProperty function in @requestnetwork/utils

To help you get started, we’ve selected a few @requestnetwork/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / request-logic / src / request-logic.ts View on Github external
public async getRequestFromId(
    requestId: string,
  ): Promise {
    const resultGetTx = await this.transactionManager.getTransactionsByChannelId(requestId);
    const actions = resultGetTx.result.transactions
      // filter the actions ignored by the previous layers
      .filter(action => action !== null);
    let ignoredTransactions: any[] = [];

    // array of transaction without duplicates to avoid replay attack
    const actionsConfirmedWithoutDuplicates = Utils.uniqueByProperty(
      actions
        .map((t: any) => {
          try {
            return { action: JSON.parse(t.transaction.data), timestamp: t.timestamp };
          } catch (e) {
            // We ignore the transaction.data that cannot be parsed
            ignoredTransactions.push({
              reason: 'JSON parsing error',
              transaction: t,
            });
            return;
          }
        })
        .filter((elem: any) => elem !== undefined),
      'action',
    );
github RequestNetwork / requestNetwork / packages / request-logic / src / request-logic.ts View on Github external
async channelId => {
        let ignoredTransactions: any[] = [];

        const actionsConfirmedWithoutDuplicates = Utils.uniqueByProperty(
          transactionsByChannel[channelId]
            // filter the actions ignored by the previous layers
            .filter(action => action !== null)
            .map((t: any) => {
              try {
                return { action: JSON.parse(t.transaction.data), timestamp: t.timestamp };
              } catch (e) {
                // We ignore the transaction.data that cannot be parsed
                ignoredTransactions.push({
                  reason: 'JSON parsing error',
                  transaction: t,
                });
                return;
              }
            })
            .filter((elem: any) => elem !== undefined),