Skip to content

Commit

Permalink
chore: merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
N3TC4T committed Sep 24, 2024
2 parents 11d2446 + e6b13d8 commit 0bcadd3
Show file tree
Hide file tree
Showing 35 changed files with 1,737 additions and 4 deletions.
88 changes: 88 additions & 0 deletions src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { flatMap, get, isUndefined } from 'lodash';

import NetworkService from '@services/NetworkService';

import { Amount } from '@common/libs/ledger/parser/common';

Check failure on line 5 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Module '"@common/libs/ledger/parser/common"' has no exported member 'Amount'.

import BaseTransaction from '@common/libs/ledger/transactions/genuine/BaseTransaction';

Check failure on line 7 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Cannot find module '@common/libs/ledger/transactions/genuine/BaseTransaction' or its corresponding type declarations.

/* Types ==================================================================== */
import { AmountType, AuthAccount, IssueType } from '@common/libs/ledger/parser/types';
import { TransactionJson, TransactionMetadata } from '@common/libs/ledger/types/transaction';
import { TransactionTypes } from '@common/libs/ledger/types/enums';

/* Class ==================================================================== */
class AMMBid extends BaseTransaction {
public static Type = TransactionTypes.AMMBid as const;
public readonly Type = AMMBid.Type;

constructor(tx?: TransactionJson, meta?: TransactionMetadata) {
super(tx, meta);

// set transaction type if not set
if (isUndefined(this.TransactionType)) {

Check failure on line 23 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'TransactionType' does not exist on type 'AMMBid'.
this.TransactionType = AMMBid.Type;

Check failure on line 24 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'TransactionType' does not exist on type 'AMMBid'.
}

this.fields = this.fields.concat(['Asset', 'Asset2', 'BidMin', 'BidMax', 'AuthAccounts']);

Check failure on line 27 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'fields' does not exist on type 'AMMBid'.

Check failure on line 27 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'fields' does not exist on type 'AMMBid'.
}

get Asset(): IssueType {
return get(this, ['tx', 'Asset']);
}

get Asset2(): IssueType {
return get(this, ['tx', 'Asset2']);
}

get BidMin(): AmountType {
const bidMin = get(this, ['tx', 'BidMin']);

if (isUndefined(bidMin)) return undefined;

Check failure on line 41 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Type 'undefined' is not assignable to type 'AmountType'.

if (typeof bidMin === 'string') {
return {
currency: NetworkService.getNativeAsset(),
value: new Amount(bidMin).dropsToNative(),
};
}

return {
currency: bidMin.currency,
value: bidMin.value,
issuer: bidMin.issuer,
};
}

get BidMax(): AmountType {
const bidMax = get(this, ['tx', 'BidMax']);

if (isUndefined(bidMax)) return undefined;

Check failure on line 60 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts

View workflow job for this annotation

GitHub Actions / lint

Type 'undefined' is not assignable to type 'AmountType'.

if (typeof bidMax === 'string') {
return {
currency: NetworkService.getNativeAsset(),
value: new Amount(bidMax).dropsToNative(),
};
}

return {
currency: bidMax.currency,
value: bidMax.value,
issuer: bidMax.issuer,
};
}

get AuthAccounts(): Array<AuthAccount> {
const accounts = get(this, ['tx', 'AuthAccounts']);

return flatMap(accounts, (entry) => {
return {
account: entry.AuthAccount.Account,
};
});
}
}

/* Export ==================================================================== */
export default AMMBid;
34 changes: 34 additions & 0 deletions src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AccountModel } from '@store/models';

import Localize from '@locale';

import AMMBid from './AMMBidClass';
import Meta from '@common/libs/ledger/parser/meta';

/* Descriptor ==================================================================== */
const AMMBidInfo = {
getLabel: (): string => {
return Localize.t('events.ammBid');
},

getDescription: (tx: AMMBid): string => {
return `This is an ${tx.Type} transaction, please check the explorer for more information.`;
},

getRecipient: (tx: AMMBid, account: AccountModel): { address: string; tag?: number } => {
if (tx.Account.address === account.address) {

Check failure on line 19 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidInfo.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'Account' does not exist on type 'AMMBid'.
const ammAccountId = new Meta(tx.MetaData).parseAMMAccountID();

Check failure on line 20 in src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidInfo.ts

View workflow job for this annotation

GitHub Actions / lint

Property 'MetaData' does not exist on type 'AMMBid'.

if (ammAccountId) {
return { address: ammAccountId };
}
} else {
return tx.Account;
}

return undefined;
},
};

/* Export ==================================================================== */
export default AMMBidInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// import AMMBid from './AMMBidClass';

/* Validator ==================================================================== */
const AMMBidValidation = (): Promise<void> => {
// TODO: add validation
return new Promise((resolve) => {
resolve();
});
};

/* Export ==================================================================== */
export default AMMBidValidation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { get, isUndefined } from 'lodash';

import NetworkService from '@services/NetworkService';

import { Amount } from '@common/libs/ledger/parser/common';

import BaseTransaction from '@common/libs/ledger/transactions/genuine/BaseTransaction';

/* Types ==================================================================== */
import { AmountType } from '@common/libs/ledger/parser/types';
import { TransactionJson, TransactionMetadata } from '@common/libs/ledger/types/transaction';
import { TransactionTypes } from '@common/libs/ledger/types/enums';
import BigNumber from 'bignumber.js';

/* Class ==================================================================== */
class AMMCreate extends BaseTransaction {
public static Type = TransactionTypes.AMMCreate as const;
public readonly Type = AMMCreate.Type;

constructor(tx?: TransactionJson, meta?: TransactionMetadata) {
super(tx, meta);

// set transaction type if not set
if (isUndefined(this.TransactionType)) {
this.TransactionType = AMMCreate.Type;
}

this.fields = this.fields.concat(['Amount', 'Amount2', 'TradingFee']);
}

get Amount(): AmountType {
const amount = get(this, ['tx', 'Amount']);

if (isUndefined(amount)) return undefined;

if (typeof amount === 'string') {
return {
currency: NetworkService.getNativeAsset(),
value: new Amount(amount).dropsToNative(),
};
}

return {
currency: amount.currency,
value: amount.value,
issuer: amount.issuer,
};
}

get Amount2(): AmountType {
const amount2 = get(this, ['tx', 'Amount2']);

if (isUndefined(amount2)) return undefined;

if (typeof amount2 === 'string') {
return {
currency: NetworkService.getNativeAsset(),
value: new Amount(amount2).dropsToNative(),
};
}

return {
currency: amount2.currency,
value: amount2.value,
issuer: amount2.issuer,
};
}

get TradingFee(): number {
const tradingFee = get(this, ['tx', 'TradingFee'], undefined);

if (isUndefined(tradingFee)) return undefined;

return new BigNumber(tradingFee).dividedBy(1000).toNumber();
}
}

/* Export ==================================================================== */
export default AMMCreate;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AccountModel } from '@store/models';

import Localize from '@locale';

import AMMCreate from './AMMCreateClass';

/* Descriptor ==================================================================== */
const AMMCreateInfo = {
getLabel: (): string => {
return Localize.t('events.ammCreate');
},

getDescription: (tx: AMMCreate): string => {
return `This is an ${tx.Type} transaction, please check the explorer for more information.`;
},

getRecipient: (tx: AMMCreate, account: AccountModel): { address: string; tag?: number } => {
if (tx.Account.address !== account.address) {
return tx.Account;
}
return undefined;
},
};

/* Export ==================================================================== */
export default AMMCreateInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// import AMMCreate from './AMMCreateClass';

/* Validator ==================================================================== */
const AMMCreateValidation = (): Promise<void> => {
// TODO: add validation
return new Promise((resolve) => {
resolve();
});
};

/* Export ==================================================================== */
export default AMMCreateValidation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { get, isUndefined } from 'lodash';

import BaseTransaction from '@common/libs/ledger/transactions/genuine/BaseTransaction';

/* Types ==================================================================== */
import { IssueType } from '@common/libs/ledger/parser/types';
import { TransactionJson, TransactionMetadata } from '@common/libs/ledger/types/transaction';
import { TransactionTypes } from '@common/libs/ledger/types/enums';

/* Class ==================================================================== */
class AMMDelete extends BaseTransaction {
public static Type = TransactionTypes.AMMDelete as const;
public readonly Type = AMMDelete.Type;

constructor(tx?: TransactionJson, meta?: TransactionMetadata) {
super(tx, meta);

// set transaction type if not set
if (isUndefined(this.TransactionType)) {
this.TransactionType = AMMDelete.Type;
}

this.fields = this.fields.concat(['Asset', 'Asset2']);
}

get Asset(): IssueType {
return get(this, ['tx', 'Asset']);
}

get Asset2(): IssueType {
return get(this, ['tx', 'Asset2']);
}
}

/* Export ==================================================================== */
export default AMMDelete;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AccountModel } from '@store/models';

import Localize from '@locale';

import AMMCreate from './AMMDeleteClass';

/* Descriptor ==================================================================== */
const AMMDeleteInfo = {
getLabel: (): string => {
return Localize.t('events.ammDelete');
},

getDescription: (tx: AMMCreate): string => {
return `This is an ${tx.Type} transaction, please check the explorer for more information.`;
},

getRecipient: (tx: AMMCreate, account: AccountModel): { address: string; tag?: number } => {
if (tx.Account.address !== account.address) {
return tx.Account;
}
return undefined;
},
};

/* Export ==================================================================== */
export default AMMDeleteInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// import AMMDelete from './AMMDeleteeClass';

/* Validator ==================================================================== */
const AMMDeleteValidation = (): Promise<void> => {
// TODO: add validation
return new Promise((resolve) => {
resolve();
});
};

/* Export ==================================================================== */
export default AMMDeleteValidation;
Loading

0 comments on commit 0bcadd3

Please sign in to comment.