Skip to content

Commit

Permalink
Merge pull request #12 from Once-Upon/benguyen0214/ou-1121-nft-purcha…
Browse files Browse the repository at this point in the history
…se-bulk-not-detected

Nft purchase bulk not detected
  • Loading branch information
pcowgill authored Nov 30, 2023
2 parents 1674261 + 54dd145 commit 0da2099
Show file tree
Hide file tree
Showing 3 changed files with 1,381 additions and 19 deletions.
17 changes: 16 additions & 1 deletion src/heuristics/erc721Purchase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Transaction } from '../types';
import { detectERC721Purchase } from './erc721Purchase';
import {
detectERC721Purchase,
generateERC21PurchaseContext,
} from './erc721Purchase';
import erc721Purchase0x2558f104 from '../test/transactions/erc721Purchase-0x2558f104.json';
import erc721Purchase0x05b8cee6 from '../test/transactions/erc721Purchase-0x05b8cee6.json';
import erc721Purchase0xdeba4248 from '../test/transactions/erc721Purchase-0xdeba4248.json';

describe('ERC721 Purchase', () => {
it('Should detect ERC721 Purchase transaction', () => {
Expand All @@ -14,5 +18,16 @@ describe('ERC721 Purchase', () => {
erc721Purchase0x05b8cee6 as Transaction,
);
expect(isERC721Purchase2).toBe(true);
const isERC721Purchase3 = detectERC721Purchase(
erc721Purchase0xdeba4248 as Transaction,
);
expect(isERC721Purchase3).toBe(true);
});

it('Should create ERC721 Purchase context', () => {
const result1 = generateERC21PurchaseContext(
erc721Purchase0xdeba4248 as Transaction,
);
expect(result1.context.summaries.en.title).toBe('NFT Purchase');
});
});
38 changes: 20 additions & 18 deletions src/heuristics/erc721Purchase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export function detectERC721Purchase(transaction: Transaction): boolean {
return false;
}

function generateERC21PurchaseContext(transaction: Transaction): Transaction {
export function generateERC21PurchaseContext(
transaction: Transaction,
): Transaction {
const receivingAddresses: string[] = [];
const receivedNfts: Asset[] = [];
const sentPayments: { type: string; asset: string; value: string }[] = [];
Expand Down Expand Up @@ -106,30 +108,30 @@ function generateERC21PurchaseContext(transaction: Transaction): Transaction {
tokenId: receivedNfts[0].tokenId,
}
: receivedNftContracts.length === 1
? {
type: 'address',
value: receivedNftContracts[0],
}
: {
type: 'emphasis',
value: `${receivedNfts.length} NFTs`,
},
? {
type: 'address',
value: receivedNftContracts[0],
}
: {
type: 'emphasis',
value: `${receivedNfts.length} NFTs`,
},
price:
totalPayments.length > 1
? {
type: 'emphasis',
value: `${totalPayments.length} Assets`,
}
: totalPayments[0].type === 'eth'
? {
type: 'eth',
value: totalPayments[0].value,
}
: {
type: 'erc20',
token: totalPayments[0].asset,
value: totalPayments[0].value,
},
? {
type: 'eth',
value: totalPayments[0].value,
}
: {
type: 'erc20',
token: totalPayments[0].asset,
value: totalPayments[0].value,
},
},
summaries: {
category: 'NFT',
Expand Down
Loading

0 comments on commit 0da2099

Please sign in to comment.