All files / app/utils get-stx-transfer-direction.ts

44.44% Statements 8/18
100% Branches 1/1
33.33% Functions 1/3
33.33% Lines 5/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  1x       1x       3x         1x                 1x                  
import { Transaction, MempoolTransaction } from '@stacks/stacks-blockchain-api-types';
import { c32addressDecode } from 'c32check';
 
export type StxTxDirection = 'sent' | 'received';
 
export function getStxTxDirection(
  address: string,
  tx: Transaction | MempoolTransaction
): StxTxDirection {
  if (tx.sender_address === address) return 'sent';
  return 'received';
}
 
// TODO: remove when in tx lib
export const validateStacksAddress = (stacksAddress: string): boolean => {
  try {
    c32addressDecode(stacksAddress);
    return true;
  } catch (e) {
    return false;
  }
};
 
export const validateStacksPrincipal = (contractId: string): boolean => {
  try {
    const [stacksAddress] = contractId.split('.');
    c32addressDecode(stacksAddress);
    return true;
  } catch (e) {
    return false;
  }
};