diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/cardano-wallet.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/cardano-wallet.ts index 0e9e0d62d6..49ca98b309 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/cardano-wallet.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/cardano-wallet.ts @@ -84,7 +84,7 @@ export const makeCardanoWallet = ( const appApi = AppApi.appApiMaker({baseUrl: networkManager.legacyApiBaseUrl}) // legacy - const {NETWORK_CONFIG, PRIMARY_TOKEN} = constants + const {PRIMARY_TOKEN} = constants return class CardanoWallet implements YoroiWallet { readonly id: string @@ -433,7 +433,7 @@ export const makeCardanoWallet = ( }, ) - return yoroiUnsignedTx({unsignedTx, networkConfig: NETWORK_CONFIG, addressedUtxos, primaryTokenId}) + return yoroiUnsignedTx({unsignedTx, networkManager, addressedUtxos, primaryTokenId, keyDeposit}) } throwLoggedError('createDelegationTx staking not supported') @@ -520,10 +520,11 @@ export const makeCardanoWallet = ( return { votingRegTx: await yoroiUnsignedTx({ unsignedTx, - networkConfig: NETWORK_CONFIG, + networkManager: this.networkManager, votingRegistration, addressedUtxos, primaryTokenId, + keyDeposit, }), } } catch (e) { @@ -587,9 +588,10 @@ export const makeCardanoWallet = ( return yoroiUnsignedTx({ unsignedTx: withdrawalTx, - networkConfig: NETWORK_CONFIG, + networkManager: this.networkManager, addressedUtxos, primaryTokenId, + keyDeposit, }) } @@ -634,11 +636,12 @@ export const makeCardanoWallet = ( return yoroiUnsignedTx({ unsignedTx, - networkConfig: NETWORK_CONFIG, + networkManager: this.networkManager, addressedUtxos, entries: [], governance: true, primaryTokenId, + keyDeposit, }) } catch (e) { if (e instanceof NotEnoughMoneyToSendError || e instanceof NoOutputsError) throw e @@ -820,7 +823,14 @@ export const makeCardanoWallet = ( {metadata}, ) - return yoroiUnsignedTx({unsignedTx, networkConfig: NETWORK_CONFIG, addressedUtxos, entries, primaryTokenId}) + return yoroiUnsignedTx({ + unsignedTx, + networkManager: this.networkManager, + addressedUtxos, + entries, + primaryTokenId, + keyDeposit, + }) } catch (e) { if (e instanceof NotEnoughMoneyToSendError || e instanceof NoOutputsError) throw e throwLoggedError(new App.Errors.LibraryError((e as Error).message)) diff --git a/apps/wallet-mobile/src/yoroi-wallets/cardano/unsignedTx/unsignedTx.ts b/apps/wallet-mobile/src/yoroi-wallets/cardano/unsignedTx/unsignedTx.ts index 11a0dd4ae7..c42cc796ca 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/cardano/unsignedTx/unsignedTx.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/cardano/unsignedTx/unsignedTx.ts @@ -1,28 +1,29 @@ import {Change, Datum, MultiTokenValue} from '@emurgo/yoroi-lib/dist/internals/models' -import {Balance} from '@yoroi/types' +import {Balance, Network} from '@yoroi/types' import {YoroiEntry, YoroiMetadata, YoroiUnsignedTx, YoroiVoting} from '../../types' import {Amounts, asQuantity, Entries, Quantities} from '../../utils' import {Cardano, CardanoMobile} from '../../wallets' -import {CardanoHaskellShelleyNetwork} from '../networks' import {CardanoTypes} from '../types' export const yoroiUnsignedTx = async ({ unsignedTx, - networkConfig, + networkManager, votingRegistration, addressedUtxos, entries, primaryTokenId, governance, + keyDeposit, }: { unsignedTx: CardanoTypes.UnsignedTx - networkConfig: CardanoHaskellShelleyNetwork + networkManager: Network.Manager votingRegistration?: VotingRegistration addressedUtxos: CardanoTypes.CardanoAddressedUtxo[] entries?: YoroiEntry[] primaryTokenId: string governance?: boolean + keyDeposit: string }) => { const fee = toAmounts(unsignedTx.fee.values) const change = await toEntriesFromChange(unsignedTx.change) @@ -43,14 +44,20 @@ export const yoroiUnsignedTx = async ({ : undefined, registrations: unsignedTx.registrations.length > 0 - ? await Staking.toRegistrations({registrations: unsignedTx.registrations, networkConfig, primaryTokenId}) + ? await Staking.toRegistrations({ + registrations: unsignedTx.registrations, + networkManager, + primaryTokenId, + keyDeposit, + }) : undefined, deregistrations: unsignedTx.deregistrations.length > 0 ? await Staking.toDeregistrations({ deregistrations: unsignedTx.deregistrations, - networkConfig, + networkManager, primaryTokenId, + keyDeposit, }) : undefined, delegations: @@ -145,56 +152,50 @@ const Staking = { return result }, - toDeregistrations: ({ + toDeregistrations: async ({ deregistrations, - networkConfig: {CHAIN_NETWORK_ID, KEY_DEPOSIT}, + networkManager, primaryTokenId, + keyDeposit, }: { deregistrations: CardanoTypes.UnsignedTx['deregistrations'] - networkConfig: CardanoHaskellShelleyNetwork + networkManager: Network.Manager primaryTokenId: string + keyDeposit: string }): Promise => Promise.all( deregistrations.map(async (deregistration) => { const address = await deregistration .stakeCredential() - .then((stakeCredential) => - CardanoMobile.RewardAddress.new( - Number(CHAIN_NETWORK_ID) /* API NETWORK_ID is equivalent to CHAIN_NETWORK_ID here */, - stakeCredential, - ), - ) + .then((stakeCredential) => CardanoMobile.RewardAddress.new(networkManager.chainId, stakeCredential)) .then((rewardAddress) => rewardAddress.toAddress()) .then((address) => address.toBytes()) .then((bytes) => Buffer.from(bytes).toString('hex')) - return {address, amounts: {[primaryTokenId]: asQuantity(KEY_DEPOSIT)}} + return {address, amounts: {[primaryTokenId]: asQuantity(keyDeposit)}} }), ), toRegistrations: async ({ registrations, - networkConfig: {CHAIN_NETWORK_ID, KEY_DEPOSIT}, + networkManager, primaryTokenId, + keyDeposit, }: { registrations: CardanoTypes.UnsignedTx['registrations'] - networkConfig: CardanoHaskellShelleyNetwork + networkManager: Network.Manager primaryTokenId: string + keyDeposit: string }): Promise => { return Promise.all( registrations.map(async (registration) => { const address: string = await registration .stakeCredential() - .then((stakeCredential) => - CardanoMobile.RewardAddress.new( - Number(CHAIN_NETWORK_ID) /* API NETWORK_ID is equivalent to CHAIN_NETWORK_ID here */, - stakeCredential, - ), - ) + .then((stakeCredential) => CardanoMobile.RewardAddress.new(networkManager.chainId, stakeCredential)) .then((rewardAddress) => rewardAddress.toAddress()) .then((address) => address.toBytes()) .then((bytes) => Buffer.from(bytes).toString('hex')) - return {address, amounts: {[primaryTokenId]: asQuantity(KEY_DEPOSIT)}} + return {address, amounts: {[primaryTokenId]: asQuantity(keyDeposit)}} }), ) },