Skip to content

Commit

Permalink
Add updateInfoPayload implementation to
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Jul 9, 2024
1 parent 42a32de commit fb532fb
Show file tree
Hide file tree
Showing 87 changed files with 861 additions and 240 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: Implemented common `updateInfoPayload` method for all plugins

## 4.11.1 (2024-07-08)

changed: Upgrade @polkadot/api to v12.1.1
Expand Down
14 changes: 13 additions & 1 deletion src/algorand/AlgorandTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import {
import { PluginEnvironment } from '../common/innerPlugin'
import { validateToken } from '../common/tokenHelpers'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { getLegacyDenomination } from '../common/utils'
import { getLegacyDenomination, mergeDeeply } from '../common/utils'
import {
AlgorandInfoPayload,
AlgorandNetworkInfo,
asAlgorandPrivateKeys,
asMaybeContractAddressLocation,
Expand Down Expand Up @@ -155,4 +156,15 @@ export async function makeCurrencyTools(
return new AlgorandTools(env)
}

export async function updateInfoPayload(
env: PluginEnvironment<AlgorandNetworkInfo>,
infoPayload: AlgorandInfoPayload
): Promise<void> {
// In the future, other fields might not be "network info" fields
const { ...networkInfo } = infoPayload

// Update plugin NetworkInfo:
env.networkInfo = mergeDeeply(env.networkInfo, networkInfo)
}

export { makeCurrencyEngine } from './AlgorandEngine'
12 changes: 10 additions & 2 deletions src/algorand/algorandInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types'
import { makeOuterPlugin } from '../common/innerPlugin'
import { makeMetaTokens } from '../common/tokenHelpers'
import type { AlgorandTools } from './AlgorandTools'
import { AlgorandNetworkInfo, asAlgorandInfoPayload } from './algorandTypes'
import {
AlgorandInfoPayload,
AlgorandNetworkInfo,
asAlgorandInfoPayload
} from './algorandTypes'

const builtinTokens: EdgeTokenMap = {
'31566704': {
Expand Down Expand Up @@ -72,7 +76,11 @@ const currencyInfo: EdgeCurrencyInfo = {
metaTokens: makeMetaTokens(builtinTokens)
}

export const algorand = makeOuterPlugin<AlgorandNetworkInfo, AlgorandTools>({
export const algorand = makeOuterPlugin<
AlgorandNetworkInfo,
AlgorandTools,
AlgorandInfoPayload
>({
builtinTokens,
currencyInfo,
asInfoPayload: asAlgorandInfoPayload,
Expand Down
9 changes: 7 additions & 2 deletions src/algorand/algorandTestnetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types'
import { makeOuterPlugin } from '../common/innerPlugin'
import { makeMetaTokens } from '../common/tokenHelpers'
import type { AlgorandTools } from './AlgorandTools'
import { AlgorandNetworkInfo, asAlgorandInfoPayload } from './algorandTypes'
import {
AlgorandInfoPayload,
AlgorandNetworkInfo,
asAlgorandInfoPayload
} from './algorandTypes'

const builtinTokens: EdgeTokenMap = {
'10458941': {
Expand Down Expand Up @@ -67,7 +71,8 @@ const currencyInfo: EdgeCurrencyInfo = {

export const algorandtestnet = makeOuterPlugin<
AlgorandNetworkInfo,
AlgorandTools
AlgorandTools,
AlgorandInfoPayload
>({
builtinTokens,
currencyInfo,
Expand Down
15 changes: 10 additions & 5 deletions src/algorand/algorandTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export interface AlgorandNetworkInfo {
minimumAddressBalance: string
}

export const asAlgorandInfoPayload = asObject({
algodServers: asOptional(asArray(asString)),
indexerServers: asOptional(asArray(asString))
})

export const asAccountInformation = asObject({
// address: asString,
amount: asNumber,
Expand Down Expand Up @@ -257,3 +252,13 @@ export const asAlgorandWalletConnectPayload = asObject({
)
)
}).withRest

//
// Info Payload
//

export const asAlgorandInfoPayload = asObject({
algodServers: asOptional(asArray(asString)),
indexerServers: asOptional(asArray(asString))
})
export type AlgorandInfoPayload = ReturnType<typeof asAlgorandInfoPayload>
14 changes: 13 additions & 1 deletion src/binance/BinanceTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {

import { PluginEnvironment } from '../common/innerPlugin'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { getLegacyDenomination } from '../common/utils'
import { getLegacyDenomination, mergeDeeply } from '../common/utils'
import {
asBnbPrivateKey,
asSafeBnbWalletInfo,
BinanceInfoPayload,
BinanceNetworkInfo
} from './binanceTypes'

Expand Down Expand Up @@ -152,4 +153,15 @@ export async function makeCurrencyTools(
return new BinanceTools(env)
}

export async function updateInfoPayload(
env: PluginEnvironment<BinanceNetworkInfo>,
infoPayload: BinanceInfoPayload
): Promise<void> {
// In the future, other fields might not be "network info" fields
const { ...networkInfo } = infoPayload

// Update plugin NetworkInfo:
env.networkInfo = mergeDeeply(env.networkInfo, networkInfo)
}

export { makeCurrencyEngine } from './BinanceEngine'
12 changes: 10 additions & 2 deletions src/binance/binanceInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { makeOuterPlugin } from '../common/innerPlugin'
import type { BinanceTools } from './BinanceTools'
import { asBinanceInfoPayload, BinanceNetworkInfo } from './binanceTypes'
import {
asBinanceInfoPayload,
BinanceInfoPayload,
BinanceNetworkInfo
} from './binanceTypes'

const networkInfo: BinanceNetworkInfo = {
binanceApiServers: [
Expand Down Expand Up @@ -37,7 +41,11 @@ const currencyInfo: EdgeCurrencyInfo = {
memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 128 }]
}

export const binance = makeOuterPlugin<BinanceNetworkInfo, BinanceTools>({
export const binance = makeOuterPlugin<
BinanceNetworkInfo,
BinanceTools,
BinanceInfoPayload
>({
currencyInfo,
asInfoPayload: asBinanceInfoPayload,
networkInfo,
Expand Down
15 changes: 10 additions & 5 deletions src/binance/binanceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ export interface BinanceNetworkInfo {
beaconChainApiServers: string[]
}

export const asBinanceInfoPayload = asObject({
binanceApiServers: asOptional(asArray(asString)),
beaconChainApiServers: asOptional(asArray(asString))
})

export const asBinanceApiNodeInfo = asObject({
sync_info: asObject({
latest_block_height: asNumber
Expand Down Expand Up @@ -89,3 +84,13 @@ export const asBnbPrivateKey = asObject({
binanceKey: asString,
binanceMnemonic: asString
})

//
// Info Payload
//

export const asBinanceInfoPayload = asObject({
binanceApiServers: asOptional(asArray(asString)),
beaconChainApiServers: asOptional(asArray(asString))
})
export type BinanceInfoPayload = ReturnType<typeof asBinanceInfoPayload>
14 changes: 13 additions & 1 deletion src/cardano/CardanoTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import { base16 } from 'rfc4648'

import { PluginEnvironment } from '../common/innerPlugin'
import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers'
import { getLegacyDenomination } from '../common/utils'
import { getLegacyDenomination, mergeDeeply } from '../common/utils'
import {
asCardanoPrivateKeys,
asSafeCardanoWalletInfo,
CardanoInfoPayload,
CardanoNetworkInfo,
EpochParams,
SafeCardanoWalletInfo
Expand Down Expand Up @@ -193,3 +194,14 @@ export async function makeCurrencyTools(
}

export { makeCurrencyEngine } from './CardanoEngine'

export async function updateInfoPayload(
env: PluginEnvironment<CardanoNetworkInfo>,
infoPayload: CardanoInfoPayload
): Promise<void> {
// In the future, other fields might not be "network info" fields
const { ...networkInfo } = infoPayload

// Update plugin NetworkInfo:
env.networkInfo = mergeDeeply(env.networkInfo, networkInfo)
}
12 changes: 10 additions & 2 deletions src/cardano/cardanoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { makeOuterPlugin } from '../common/innerPlugin'
import type { CardanoTools } from './CardanoTools'
import { asCardanoInfoPayload, CardanoNetworkInfo } from './cardanoTypes'
import {
asCardanoInfoPayload,
CardanoInfoPayload,
CardanoNetworkInfo
} from './cardanoTypes'

const networkInfo: CardanoNetworkInfo = {
networkId: 1,
Expand All @@ -29,7 +33,11 @@ const currencyInfo: EdgeCurrencyInfo = {
]
}

export const cardano = makeOuterPlugin<CardanoNetworkInfo, CardanoTools>({
export const cardano = makeOuterPlugin<
CardanoNetworkInfo,
CardanoTools,
CardanoInfoPayload
>({
currencyInfo,
asInfoPayload: asCardanoInfoPayload,
networkInfo,
Expand Down
38 changes: 22 additions & 16 deletions src/cardano/cardanoTestnetInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types'

import { makeOuterPlugin } from '../common/innerPlugin'
import type { CardanoTools } from './CardanoTools'
import { asCardanoInfoPayload, CardanoNetworkInfo } from './cardanoTypes'
import {
asCardanoInfoPayload,
CardanoInfoPayload,
CardanoNetworkInfo
} from './cardanoTypes'

const networkInfo: CardanoNetworkInfo = {
networkId: 0,
Expand All @@ -29,20 +33,22 @@ const currencyInfo: EdgeCurrencyInfo = {
]
}

export const cardanotestnet = makeOuterPlugin<CardanoNetworkInfo, CardanoTools>(
{
currencyInfo,
asInfoPayload: asCardanoInfoPayload,
networkInfo,

checkEnvironment: () => {
if (global.BigInt == null) {
throw new Error('Cardano Testnet requires bigint support')
}
},

async getInnerPlugin() {
return await import('./CardanoTools')
export const cardanotestnet = makeOuterPlugin<
CardanoNetworkInfo,
CardanoTools,
CardanoInfoPayload
>({
currencyInfo,
asInfoPayload: asCardanoInfoPayload,
networkInfo,

checkEnvironment: () => {
if (global.BigInt == null) {
throw new Error('Cardano Testnet requires bigint support')
}
},

async getInnerPlugin() {
return await import('./CardanoTools')
}
)
})
17 changes: 11 additions & 6 deletions src/cardano/cardanoTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export interface CardanoNetworkInfo {
maestroServer: string
}

export const asCardanoInfoPayload = asObject({
koiosServer: asOptional(asString),
blockfrostServer: asOptional(asString),
maestroServer: asOptional(asString)
})

export type SafeCardanoWalletInfo = ReturnType<typeof asSafeCardanoWalletInfo>
export const asSafeCardanoWalletInfo = asWalletInfo(
asObject({
Expand Down Expand Up @@ -266,3 +260,14 @@ export const asCardanoInitOptions = asObject({
maestroApiKey: asOptional(asString)
})
export type CardanoInitOptions = ReturnType<typeof asCardanoInitOptions>

//
// Info Payload
//

export const asCardanoInfoPayload = asObject({
koiosServer: asOptional(asString),
blockfrostServer: asOptional(asString),
maestroServer: asOptional(asString)
})
export type CardanoInfoPayload = ReturnType<typeof asCardanoInfoPayload>
Loading

0 comments on commit fb532fb

Please sign in to comment.