-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,737 additions
and
4 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidClass.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
import BaseTransaction from '@common/libs/ledger/transactions/genuine/BaseTransaction'; | ||
|
||
/* 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)) { | ||
this.TransactionType = AMMBid.Type; | ||
} | ||
|
||
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 GitHub Actions / lint
|
||
} | ||
|
||
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; | ||
|
||
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; | ||
|
||
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
34
src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
const ammAccountId = new Meta(tx.MetaData).parseAMMAccountID(); | ||
|
||
if (ammAccountId) { | ||
return { address: ammAccountId }; | ||
} | ||
} else { | ||
return tx.Account; | ||
} | ||
|
||
return undefined; | ||
}, | ||
}; | ||
|
||
/* Export ==================================================================== */ | ||
export default AMMBidInfo; |
12 changes: 12 additions & 0 deletions
12
src/common/libs/ledger/transactions/genuine/AMMBid/AMMBidValidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
79 changes: 79 additions & 0 deletions
79
src/common/libs/ledger/transactions/genuine/AMMCreate/AMMCreateClass.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
26 changes: 26 additions & 0 deletions
26
src/common/libs/ledger/transactions/genuine/AMMCreate/AMMCreateInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
12 changes: 12 additions & 0 deletions
12
src/common/libs/ledger/transactions/genuine/AMMCreate/AMMCreateValidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
36 changes: 36 additions & 0 deletions
36
src/common/libs/ledger/transactions/genuine/AMMDelete/AMMDeleteClass.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
26 changes: 26 additions & 0 deletions
26
src/common/libs/ledger/transactions/genuine/AMMDelete/AMMDeleteInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
12 changes: 12 additions & 0 deletions
12
src/common/libs/ledger/transactions/genuine/AMMDelete/AMMDeleteValidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.