Skip to content

Commit

Permalink
Merge pull request #3423 from superhero-com/feature/get-correct-token…
Browse files Browse the repository at this point in the history
…-address-from-sale-transaction

fix: get correct token address for token sale transaction
  • Loading branch information
CedrikNikita authored Nov 22, 2024
2 parents 20d4f02 + e619c24 commit 69412c4
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/protocols/aeternity/helpers/transactionTokenInfoResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,14 @@ const withdraw: TransactionResolver = (transaction, tokens = null) => ({
* Token Sale Buy
*/
const buy: TransactionResolver = (transaction, tokens = null, tokenAddressMapper = undefined) => {
const isConfirm = !transaction.tx.return;
const tokenAddress: string = isConfirm && tokenAddressMapper
? tokenAddressMapper(transaction.tx.contractId)
: transaction.tx.log?.slice(-1)[0]?.address;
const tokenAddress: string | undefined = tokenAddressMapper?.(transaction.tx.contractId);

const [amount] = transaction.tx.arguments!;
const token = {
amount: amount?.value,
...defaultToken,
symbol: tokens?.[tokenAddress]?.symbol,
contractId: tokenAddress,
...tokens?.[tokenAddress],
symbol: tokenAddress && tokens?.[tokenAddress]?.symbol,
...(tokenAddress ? tokens?.[tokenAddress] : {}),
isReceived: true,
};
const aeToken = {
Expand All @@ -396,17 +392,15 @@ const buy: TransactionResolver = (transaction, tokens = null, tokenAddressMapper
*/
const sell: TransactionResolver = (transaction, tokens = null, tokenAddressMapper = undefined) => {
const isConfirm = !transaction.tx.return;
const tokenAddress: string = isConfirm && tokenAddressMapper
? tokenAddressMapper(transaction.tx.contractId)
: transaction.tx.log?.slice(-1)[0]?.address;
const tokenAddress: string | undefined = tokenAddressMapper?.(transaction.tx.contractId);

const amount = isConfirm ? transaction.tx.arguments?.[0]?.value : transaction.tx.arguments?.[0]!;
const aeAmount = isConfirm ? transaction.tx.arguments?.[1]?.value : transaction.tx.return?.value;
const token = {
amount: amount?.value,
...defaultToken,
symbol: tokens?.[tokenAddress]?.symbol,
...tokens?.[tokenAddress],
symbol: tokenAddress && tokens?.[tokenAddress]?.symbol,
...(tokenAddress ? tokens?.[tokenAddress] : {}),
isReceived: false,
};
const aeToken = {
Expand Down

0 comments on commit 69412c4

Please sign in to comment.