Skip to content

Commit

Permalink
Update the currency types. Add the union of the specific types
Browse files Browse the repository at this point in the history
  • Loading branch information
skubarenko committed Aug 12, 2022
1 parent 715a6eb commit 82e8344
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 26 deletions.
9 changes: 4 additions & 5 deletions src/ethereum/config/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AtomexBlockchainNetworkOptions } from '../../atomex/models/atomexOptions';
import type { EthereumCurrency } from '../models/currency';
import type { EthereumCurrency, NativeEthereumCurrency } from '../models/currency';

const ethereumNativeCurrency: EthereumCurrency = {
const nativeEthereumCurrency: NativeEthereumCurrency = {
id: 'ETH',
name: 'Ethereum',
symbol: 'ETH',
Expand All @@ -11,9 +10,9 @@ const ethereumNativeCurrency: EthereumCurrency = {
};

export const ethereumMainnetCurrencies: EthereumCurrency[] = [
ethereumNativeCurrency
nativeEthereumCurrency
];

export const ethereumTestnetCurrencies: EthereumCurrency[] = [
ethereumNativeCurrency
nativeEthereumCurrency
];
6 changes: 5 additions & 1 deletion src/ethereum/models/currency.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Currency } from '../../common/index';

export interface EthereumCurrency extends Currency {
export interface NativeEthereumCurrency extends Currency {
readonly name: 'Ethereum';
readonly symbol: 'ETH';
readonly blockchain: 'ethereum';
Expand All @@ -13,3 +13,7 @@ export interface ERC20EthereumCurrency extends Currency {
readonly type: 'erc-20';
readonly contractAddress: string;
}

export type EthereumCurrency =
| NativeEthereumCurrency
| ERC20EthereumCurrency;
2 changes: 1 addition & 1 deletion src/ethereum/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type { EthereumCurrency, ERC20EthereumCurrency } from './currency';
export type { EthereumCurrency, NativeEthereumCurrency, ERC20EthereumCurrency } from './currency';
export type { EthereumWeb3AtomexProtocolV1Options, ERC20EthereumWeb3AtomexProtocolV1Options } from './atomexProtocolOptions';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export type { AtomexClient } from './clients/index';
export type { AtomexNetwork, Currency, Side, CurrenciesProvider, CollectionSelector } from './common/index';
export type { AtomexStore, AuthorizationManagerStore } from './stores/index';
export type { Swap, SwapParticipant, SwapParticipantRequisites, SwapParticipantStatus } from './swaps/index';
export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './tezos/index';
export type { TezosCurrency, NativeTezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from './tezos/index';

export * as legacy from './legacy/index';
21 changes: 10 additions & 11 deletions src/tezos/config/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AtomexBlockchainNetworkOptions } from '../../atomex/models/atomexOptions';
import type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from '../models/index';
import type { NativeTezosCurrency, TezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from '../models/index';

const tezosNativeCurrency: TezosCurrency = {
const nativeTezosCurrency: NativeTezosCurrency = {
id: 'XTZ',
name: 'Tezos',
symbol: 'XTZ',
Expand All @@ -10,7 +9,7 @@ const tezosNativeCurrency: TezosCurrency = {
type: 'native'
};

const tzBtcCurrency: TezosFA12Currency = {
const tzBtcCurrency: FA12TezosCurrency = {
id: 'TZBTC',
name: 'tzBTC',
symbol: 'tzBTC',
Expand All @@ -20,7 +19,7 @@ const tzBtcCurrency: TezosFA12Currency = {
decimals: 8,
};

const usdtCurrency: TezosFA2Currency = {
const usdtCurrency: FA2TezosCurrency = {
id: 'USDT_XTZ',
name: 'Tether USD',
symbol: 'USDt',
Expand All @@ -31,14 +30,14 @@ const usdtCurrency: TezosFA2Currency = {
decimals: 6,
};

export const tezosMainnetCurrencies: AtomexBlockchainNetworkOptions['currencies'] = [
tezosNativeCurrency,
export const tezosMainnetCurrencies: TezosCurrency[] = [
nativeTezosCurrency,
tzBtcCurrency,
usdtCurrency
];

export const tezosTestnetCurrencies: AtomexBlockchainNetworkOptions['currencies'] = [
tezosNativeCurrency,
({ ...tzBtcCurrency, contractAddress: 'KT1DM4k79uSx5diQnwqDiF4XeA86aCBxBD35' } as TezosFA12Currency),
({ ...usdtCurrency, contractAddress: 'KT1BWvRQnVVowZZLGkct9A7sdj5YEe8CdUhR' } as TezosFA2Currency)
export const tezosTestnetCurrencies: TezosCurrency[] = [
nativeTezosCurrency,
({ ...tzBtcCurrency, contractAddress: 'KT1DM4k79uSx5diQnwqDiF4XeA86aCBxBD35' } as FA12TezosCurrency),
({ ...usdtCurrency, contractAddress: 'KT1BWvRQnVVowZZLGkct9A7sdj5YEe8CdUhR' } as FA2TezosCurrency)
];
2 changes: 1 addition & 1 deletion src/tezos/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { TaquitoBlockchainWallet } from './wallets/index';
export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './models/index';
export type { TezosCurrency, NativeTezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from './models/index';
export { tezosMainnetCurrencies, tezosTestnetCurrencies, createDefaultTezosBlockchainOptions } from './config/index';
export { TezosBalancesProvider } from './balancesProviders';
export { TezosSwapTransactionsProvider } from './swapTransactionsProviders';
Expand Down
11 changes: 8 additions & 3 deletions src/tezos/models/currency.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import type { Currency } from '../../common/index';

export interface TezosCurrency extends Currency {
export interface NativeTezosCurrency extends Currency {
readonly name: 'Tezos';
readonly symbol: 'XTZ';
readonly blockchain: 'tezos';
readonly type: 'native';
readonly decimals: 6;
}

export interface TezosFA12Currency extends Currency {
export interface FA12TezosCurrency extends Currency {
readonly blockchain: 'tezos';
readonly type: 'fa1.2';
readonly contractAddress: string;
}

export interface TezosFA2Currency extends Currency {
export interface FA2TezosCurrency extends Currency {
readonly blockchain: 'tezos';
readonly type: 'fa2';
readonly contractAddress: string;
readonly tokenId: number;
}

export type TezosCurrency =
| NativeTezosCurrency
| FA12TezosCurrency
| FA2TezosCurrency;
2 changes: 1 addition & 1 deletion src/tezos/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { TezosAtomexSigningDataType } from './tezosAtomexSigningDataType';

export type { SigPrefix } from './sigPrefix';
export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './currency';
export type { TezosCurrency, NativeTezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from './currency';
4 changes: 2 additions & 2 deletions tests/testHelpers/testCurrenciesProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InMemoryCurrenciesProvider } from '../../src/common/index';
import { ethereumMainnetCurrencies } from '../../src/ethereum/index';
import type { ERC20EthereumCurrency } from '../../src/ethereum/models/index';
import type { Currency, TezosFA12Currency } from '../../src/index';
import type { Currency, FA12TezosCurrency } from '../../src/index';
import { tezosMainnetCurrencies } from '../../src/tezos/index';

const btcCurrency: Currency = {
Expand All @@ -22,7 +22,7 @@ const ltcCurrency: Currency = {
decimals: 8,
};

const kusdCurrency: TezosFA12Currency = {
const kusdCurrency: FA12TezosCurrency = {
id: 'KUSD',
name: 'Kolibri USD',
blockchain: 'tezos',
Expand Down

0 comments on commit 82e8344

Please sign in to comment.