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

core2.0 - Require EdgeTokenId instead of currencyCode throughout API #577

Merged
merged 14 commits into from
Jan 4, 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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

## Unreleased

- added: `EdgeCurrencyWallet.saveTxAction` to add/edit `EdgeTransaction.savedAction`
- added: `EdgeTransaction.assetAction` & `EdgeSpendInfo.assetAction` for action info that is saved per token in a transaction.
- added: `EdgeTransaction.savedAction` & `EdgeSpendInfo.savedAction` as editable version of `chainAction`
- added: `EdgeTxActionFiat` action type for fiat buy/sells
- added: `EdgeTxActionTokenApproval` action type for token approval transactions
- changed: Extend `EdgeTxActionSwap` to fully replace `EdgeSwapData`
- changed: Make `EdgeCurrencyInfo.defaultSettings` and `EdgeCurrencyInfo.metaTokens` optional.
- changed: Rename `EdgeTransaction.action` to `chainAction`
- changed: Require `tokenId` to be null or string and eliminate `currencyCode` in `EdgeCurrencyWallet.getTransactions/getReceiveAddress`, `EdgeSpendInfo`, `EdgeSwapRequest`, `EdgeTxAction.EdgeAssetAmount`, `saveTxMetadata`
- removed: `EdgeAccount.rateCache` and related types, as well as the rate plugin concept.
- removed: `EdgeContext.deleteLocalAccount`
- removed: `EdgeContext.listUsernames`
- removed: `EdgeContext.pinLoginEnabled`
- removed: `EdgeCurrencyInfo.symbolImage` and `symbolImageDarkMono`.
- removed: `EdgeLoginRequest.displayImageUrl`
- removed: `listRecoveryQuestionChoices` and related types.
- removed: `validateMemo` methods and related types.

## 1.14.0 (2024-01-04)

- added: `EdgeCurrencyCodeOptions.tokenId`. This upgrades `getBalance`, `getNumTransactions`, and `getReceiveAddress`.
Expand Down
4 changes: 2 additions & 2 deletions src/client-side.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface InternalWalletStream {

export interface InternalWalletMethods {
$internalStreamTransactions: (
opts: EdgeStreamTransactionOptions & { unfilteredStart?: number }
opts: EdgeStreamTransactionOptions
) => Promise<InternalWalletStream>
}

Expand Down Expand Up @@ -107,7 +107,7 @@ shareData({ fixUsername })
*/
export function streamTransactions(
this: InternalWalletMethods,
opts: EdgeStreamTransactionOptions = {}
opts: EdgeStreamTransactionOptions
): AsyncIterableIterator<EdgeTransaction[]> {
let stream: InternalWalletStream | undefined
let streamClosed = false
Expand Down
33 changes: 17 additions & 16 deletions src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
EdgeLobby,
EdgePendingVoucher,
EdgePluginMap,
EdgeRateCache,
EdgeResult,
EdgeSwapConfig,
EdgeSwapQuote,
Expand All @@ -30,7 +29,6 @@ import {
} from '../../types/types'
import { base58 } from '../../util/encoding'
import { getPublicWalletInfo } from '../currency/wallet/currency-wallet-pixie'
import { makeExchangeCache } from '../exchange/exchange-api'
import {
finishWalletCreation,
makeCurrencyWalletKeys,
Expand Down Expand Up @@ -91,7 +89,6 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
}

// Specialty API's:
const rateCache = makeExchangeCache(ai)
const dataStore = makeDataStoreApi(ai, accountId)
const storageWalletApi = makeStorageWalletApi(ai, accountWalletInfo)

Expand Down Expand Up @@ -187,10 +184,6 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
return swapConfigs
},

get rateCache(): EdgeRateCache {
return rateCache
},

get dataStore(): EdgeDataStore {
return dataStore
},
Expand Down Expand Up @@ -609,16 +602,13 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
})
},

async activateWallet({
activateWalletId,
activateTokenIds,
paymentWalletId,
paymentTokenId
}: EdgeActivationOptions): Promise<EdgeActivationQuote> {
async activateWallet(
opts: EdgeActivationOptions
): Promise<EdgeActivationQuote> {
const { activateWalletId, activateTokenIds, paymentInfo } = opts
const { currencyWallets } = ai.props.output.accounts[accountId]
const walletOutput = ai.props.output.currency.wallets[activateWalletId]
const { engine } = walletOutput
const paymentWallet = currencyWallets[paymentWalletId ?? '']

if (engine == null)
throw new Error(`Invalid wallet: ${activateWalletId} not found`)
Expand All @@ -627,11 +617,22 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
throw new Error(
`activateWallet unsupported by walletId ${activateWalletId}`
)
const walletId = paymentInfo?.walletId
const wallet = currencyWallets[walletId ?? '']

if (wallet == null) {
throw new Error(`No wallet for walletId ${walletId}`)
}

const out = await engine.engineActivateWallet({
activateTokenIds,
paymentTokenId,
paymentWallet
paymentInfo:
paymentInfo != null
? {
wallet,
tokenId: paymentInfo.tokenId
}
: undefined
})
return bridgifyObject(out)
},
Expand Down
13 changes: 1 addition & 12 deletions src/core/account/account-pixie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
stopUpdates,
TamePixie
} from 'redux-pixies'
import { close, emit, update } from 'yaob'
import { close, update } from 'yaob'

import {
asMaybeOtpError,
Expand All @@ -17,7 +17,6 @@ import {
} from '../../types/types'
import { makePeriodicTask } from '../../util/periodic-task'
import { snooze } from '../../util/snooze'
import { ExchangeState } from '../exchange/exchange-reducer'
import { syncLogin } from '../login/login'
import { waitForPlugins } from '../plugins/plugins-selectors'
import { RootProps, toApiInput } from '../root-pixie'
Expand Down Expand Up @@ -61,7 +60,6 @@ const accountPixie: TamePixie<AccountProps> = combinePixies({
update(accountApi)
close(accountApi)
close(accountApi.dataStore)
close(accountApi.rateCache)
const { currencyConfig, swapConfig } = accountApi
for (const pluginId of Object.keys(currencyConfig)) {
close(currencyConfig[pluginId])
Expand Down Expand Up @@ -202,7 +200,6 @@ const accountPixie: TamePixie<AccountProps> = combinePixies({
watcher(input: AccountInput) {
let lastState: AccountState | undefined
// let lastWallets
let lastExchangeState: ExchangeState | undefined

return () => {
const { accountState, accountOutput } = input.props
Expand Down Expand Up @@ -234,14 +231,6 @@ const accountPixie: TamePixie<AccountProps> = combinePixies({
// lastWallets = input.props.output.currency.wallets
// if (accountOutput.accountApi != null) update(accountOutput.accountApi)
// }

// Exchange:
if (lastExchangeState !== input.props.state.exchangeCache) {
lastExchangeState = input.props.state.exchangeCache
if (accountApi != null) {
emit(accountApi.rateCache, 'update', undefined)
}
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/core/account/custom-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function loadBuiltinTokens(
const plugin = state.plugins.currency[pluginId]
const tokens: EdgeTokenMap =
plugin.getBuiltinTokens == null
? upgradeMetaTokens(plugin.currencyInfo.metaTokens)
? upgradeMetaTokens(plugin.currencyInfo.metaTokens ?? [])
: await plugin.getBuiltinTokens()
dispatch({
type: 'ACCOUNT_BUILTIN_TOKENS_LOADED',
Expand Down
5 changes: 1 addition & 4 deletions src/core/account/lobby-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ async function unpackLoginRequest(

async close(): Promise<void> {
close(out)
},

// Deprecated:
displayImageUrl: info.lightImageUrl
}
}
bridgifyObject(out)
return out
Expand Down
13 changes: 0 additions & 13 deletions src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EdgeCurrencyTools,
EdgeLogSettings,
EdgePluginMap,
EdgeRateHint,
EdgeStakingStatus,
EdgeToken,
EdgeTokenId,
Expand All @@ -20,7 +19,6 @@ import {
TxFileNames,
TxidHashes
} from './currency/wallet/currency-wallet-reducer'
import { ExchangePair } from './exchange/exchange-reducer'
import { LoginStash } from './login/login-stash'
import { LoginType } from './login/login-types'
import {
Expand Down Expand Up @@ -328,11 +326,6 @@ export type RootAction =
walletInfo: EdgeWalletInfo
}
}
| {
// Fired when we fetch exchange pairs from some server.
type: 'EXCHANGE_PAIRS_FETCHED'
payload: ExchangePair[]
}
| {
// Initializes the redux store on context creation.
type: 'INIT'
Expand All @@ -346,7 +339,6 @@ export type RootAction =
deviceDescription: string | null
hideKeys: boolean
logSettings: EdgeLogSettings
rateHintCache: EdgeRateHint[]
pluginsInit: EdgeCorePluginsInit
skipBlockHeight: boolean
stashes: LoginStash[]
Expand Down Expand Up @@ -405,10 +397,5 @@ export type RootAction =
// Dummy action to propagate `next` changes.
type: 'UPDATE_NEXT'
}
| {
// Fires when there are new rate hints to add to the cache
type: 'UPDATE_RATE_HINT_CACHE'
payload: { rateHintCache: EdgeRateHint[] }
}

export type Dispatch = (action: RootAction) => RootAction
46 changes: 1 addition & 45 deletions src/core/context/context-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
EdgeLoginMessage,
EdgeLogSettings,
EdgePendingEdgeLogin,
EdgeRecoveryQuestionChoice,
EdgeUserInfo
} from '../../types/types'
import { verifyData } from '../../util/crypto/verify'
Expand All @@ -28,11 +27,7 @@ import { removeStash, saveStash } from '../login/login-stash'
import { resetOtp } from '../login/otp'
import { loginPassword } from '../login/password'
import { loginPin2 } from '../login/pin2'
import {
getQuestions2,
listRecoveryQuestionChoices,
loginRecovery2
} from '../login/recovery2'
import { getQuestions2, loginRecovery2 } from '../login/recovery2'
import { ApiInput } from '../root-pixie'
import { EdgeInternalStuff } from './internal-api'

Expand Down Expand Up @@ -61,30 +56,6 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
return ai.props.state.login.localUsers
},

async listUsernames(): Promise<string[]> {
const { stashes } = ai.props.state.login
return stashes
.map(stash => stash.username)
.filter((username): username is string => username != null)
},

async deleteLocalAccount(username: string): Promise<void> {
username = fixUsername(username)
const stashTree = getStashByUsername(ai, username)
if (stashTree == null) return
const { loginId } = stashTree

// Safety check:
for (const accountId of ai.props.state.accountIds) {
const accountState = ai.props.state.accounts[accountId]
if (verifyData(accountState.stashTree.loginId, loginId)) {
throw new Error('Cannot remove logged-in user')
}
}

await removeStash(ai, loginId)
},

async forgetAccount(rootLoginId: string): Promise<void> {
const loginId = base58.parse(rootLoginId)

Expand Down Expand Up @@ -158,16 +129,6 @@ export function makeContextApi(ai: ApiInput): EdgeContext {

checkPasswordRules,

async pinLoginEnabled(username: string): Promise<boolean> {
username = fixUsername(username)
for (const userInfo of ai.props.state.login.localUsers) {
if (userInfo.username === username) {
return userInfo.pinLoginEnabled
}
}
return false
},

async loginWithPIN(
usernameOrLoginId: string,
pin: string,
Expand Down Expand Up @@ -267,11 +228,6 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
async changeLogSettings(settings: Partial<EdgeLogSettings>): Promise<void> {
const newSettings = { ...ai.props.state.logSettings, ...settings }
ai.props.dispatch({ type: 'CHANGE_LOG_SETTINGS', payload: newSettings })
},

/** @deprecated The GUI provides its own localized strings now. */
async listRecoveryQuestionChoices(): Promise<EdgeRecoveryQuestionChoice[]> {
return await listRecoveryQuestionChoices(ai)
}
}
bridgifyObject(out)
Expand Down
Loading
Loading