Skip to content

Commit

Permalink
Merge branch 'develop' into yushi/yoroi-lib-coin-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
vsubhuman authored Sep 9, 2023
2 parents 5fe4610 + 1b65a3a commit 8135b20
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
8 changes: 6 additions & 2 deletions packages/yoroi-connector/src/cardanoApiInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@

// DEPRECATED
getCollateralUtxos(requiredAmount) {
return CardanoAPI._cardano_rpc_call("get_collateral_utxos", [requiredAmount]);
const amount = typeof requiredAmount === 'object' ? requiredAmount.amount : requiredAmount;
const strAmount = amount == null || amount === '' ? null : String(amount);
return CardanoAPI._cardano_rpc_call("get_collateral_utxos", [strAmount]);
}

getCollateral(requiredAmount) {
return CardanoAPI._cardano_rpc_call("get_collateral_utxos", [requiredAmount]);
const amount = typeof requiredAmount === 'object' ? requiredAmount.amount : requiredAmount;
const strAmount = amount == null || amount === '' ? null : String(amount);
return CardanoAPI._cardano_rpc_call("get_collateral_utxos", [strAmount]);
}
}
window.CardanoAPI = CardanoAPI;
Expand Down
28 changes: 7 additions & 21 deletions packages/yoroi-extension/app/stores/ada/TrezorConnectStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ export default class TrezorConnectStore
this._onTrezorUIEvent,
);

if (this.trezorEventDevice == null) {
throw new Error(`${nameof(this._checkAndStoreHWDeviceInfo)} no ${nameof(this.trezorEventDevice)}`);
}
const trezorEventDevice = this.trezorEventDevice;

/** Converts a valid hardware wallet response to a common storable format
Expand Down Expand Up @@ -231,29 +228,25 @@ export default class TrezorConnectStore

const { trezorResp, trezorEventDevice } = resp;

/** This check already done in _validateHWResponse but flow needs this */
const device = trezorEventDevice.payload;
const { features } = device;
if (features == null) {
throw new Error('Trezor device hardware info not valid');
}
const device = trezorEventDevice?.payload;
const features = device?.features;

return {
publicMasterKey: trezorResp.payload.publicKey,
hwFeatures: {
Vendor: features.vendor ?? Config.wallets.hardwareWallet.trezorT.VENDOR,
Model: features.model,
DeviceId: features.device_id || '',
Vendor: features?.vendor ?? Config.wallets.hardwareWallet.trezorT.VENDOR,
Model: features?.model ?? Config.wallets.hardwareWallet.trezorT.MODEL,
DeviceId: features?.device_id || '',
},
defaultName: device.label || '',
defaultName: device?.label || '',
};
}

/** Validates the compatibility of data which we have received from Trezor device */
_validateHWResponse: TrezorConnectionResponse => boolean = (
resp,
) => {
const { trezorResp, trezorEventDevice } = resp;
const { trezorResp } = resp;

if (trezorResp && !trezorResp.success) {
switch (trezorResp.payload.error) {
Expand All @@ -276,13 +269,6 @@ export default class TrezorConnectStore
throw new Error('Invalid public key received from Trezor device');
}

if (trezorEventDevice == null
|| trezorEventDevice.payload == null
|| trezorEventDevice.payload.type !== 'acquired'
|| trezorEventDevice.payload.features == null) {
throw new Error('Invalid trezor device event');
}

return true;
};

Expand Down
3 changes: 2 additions & 1 deletion packages/yoroi-extension/chrome/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
connectorSignData,
connectorGetAssets,
getTokenMetadataFromIds,
MAX_COLLATERAL,
} from './connector/api';
import { updateTransactions as ergoUpdateTransactions } from '../../app/api/ergo/lib/storage/bridge/updateTransactions';
import {
Expand Down Expand Up @@ -1783,7 +1784,7 @@ async function handleInjectorMessage(message, sender) {
try {
checkParamCount(1);
await RustModule.load();
let requiredAmount: string = message.params[0];
let requiredAmount: string = message.params[0] || String(MAX_COLLATERAL);
if (!/^\d+$/.test(requiredAmount)) {
try {
requiredAmount = RustModule.WalletV4.Value.from_bytes(
Expand Down
2 changes: 1 addition & 1 deletion packages/yoroi-extension/chrome/extension/connector/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export async function connectorGetUtxosCardano(
}));
}

const MAX_COLLATERAL = new BigNumber('5000000');
export const MAX_COLLATERAL: BigNumber = new BigNumber('5000000');
// only consider UTXO value <= (${requiredAmount} + 1 ADA)
const MAX_PER_UTXO_SURPLUS = new BigNumber('2000000');

Expand Down
2 changes: 1 addition & 1 deletion packages/yoroi-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/yoroi-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yoroi",
"version": "4.22.404",
"version": "4.22.500",
"description": "Cardano ADA wallet",
"scripts": {
"dev-mv2": "rimraf dev/ && babel-node scripts-mv2/build --type=debug --env 'mainnet'",
Expand Down

0 comments on commit 8135b20

Please sign in to comment.