Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updateInfoPayload implementation #795

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- added: Implemented common `updateInfoPayload` method for all plugins
- changed: (Ethereum) Include network fee info for core info payload

## 4.11.1 (2024-07-08)

changed: Upgrade @polkadot/api to v12.1.1
Expand All @@ -20,7 +23,7 @@ changed: Upgrade @polkadot/api to v12.1.1

- added: (Ethereum/Solana) Add BOBBY
- added: (zkSync) Add ZK
- changed: (Piratechain) Allow `derivePublicKey` to fail in case native code isn't present
- changed: (Piratechain) Allow `derivePublicKey` to fail in case native code isn't present
- removed: (Zcash/Piratechain) Remove `defaultBirthdayHeight`

## 4.8.0 (2024-06-10)
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'
14 changes: 11 additions & 3 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,10 +76,14 @@ const currencyInfo: EdgeCurrencyInfo = {
metaTokens: makeMetaTokens(builtinTokens)
}

export const algorand = makeOuterPlugin<AlgorandNetworkInfo, AlgorandTools>({
export const algorand = makeOuterPlugin<
AlgorandNetworkInfo,
AlgorandTools,
AlgorandInfoPayload
>({
builtinTokens,
currencyInfo,
infoPayloadCleaner: asAlgorandInfoPayload,
asInfoPayload: asAlgorandInfoPayload,
networkInfo,

checkEnvironment: () => {
Expand Down
11 changes: 8 additions & 3 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,11 +71,12 @@ const currencyInfo: EdgeCurrencyInfo = {

export const algorandtestnet = makeOuterPlugin<
AlgorandNetworkInfo,
AlgorandTools
AlgorandTools,
AlgorandInfoPayload
>({
builtinTokens,
currencyInfo,
infoPayloadCleaner: asAlgorandInfoPayload,
asInfoPayload: asAlgorandInfoPayload,
networkInfo,

checkEnvironment: () => {
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'
14 changes: 11 additions & 3 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,9 +41,13 @@ const currencyInfo: EdgeCurrencyInfo = {
memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 128 }]
}

export const binance = makeOuterPlugin<BinanceNetworkInfo, BinanceTools>({
export const binance = makeOuterPlugin<
BinanceNetworkInfo,
BinanceTools,
BinanceInfoPayload
>({
currencyInfo,
infoPayloadCleaner: asBinanceInfoPayload,
asInfoPayload: asBinanceInfoPayload,
networkInfo,

async getInnerPlugin() {
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)
}
14 changes: 11 additions & 3 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,9 +33,13 @@ const currencyInfo: EdgeCurrencyInfo = {
]
}

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

checkEnvironment: () => {
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,
infoPayloadCleaner: 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
Loading