Skip to content

Commit

Permalink
Merge pull request #1472 from input-output-hk/fix/remove-redundant-so…
Browse files Browse the repository at this point in the history
…rt-on-cip-30-get-change-address

fix(wallet): remove redundant sort on getChangeAddres
  • Loading branch information
AngelCastilloB authored Sep 12, 2024
2 parents 0e6cc27 + c5b430a commit 19c4087
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
15 changes: 1 addition & 14 deletions packages/wallet/src/cip30.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { InputSelectionError, InputSelectionFailure } from '@cardano-sdk/input-s
import { Logger } from 'ts-log';
import { MessageSender } from '@cardano-sdk/key-management';
import { Observable, firstValueFrom, from, map, mergeMap, race, throwError } from 'rxjs';
import { ObservableWallet, isKeyHashAddress, isScriptAddress } from './types';
import { ObservableWallet } from './types';
import { requiresForeignSignatures } from './services';
import uniq from 'lodash/uniq.js';

Expand Down Expand Up @@ -279,19 +279,6 @@ const baseCip30WalletApi = (
try {
const wallet = await firstValueFrom(wallet$);
const addresses = await firstValueFrom(wallet.addresses$);

const isScriptWallet = addresses.some(isScriptAddress);

if (!isScriptWallet) {
addresses.sort((a, b) => {
if (isKeyHashAddress(a) && isKeyHashAddress(b)) {
return a.index - b.index;
}

return 0; // Cant happen, but in any case do not sort.
});
}

const address = addresses[0].address;

if (!address) {
Expand Down
14 changes: 7 additions & 7 deletions packages/wallet/test/integration/cip30mapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,27 +504,27 @@ describe('cip30', () => {
const addresses = [
{
accountIndex: 0,
address: address_1_0,
index: 1,
address: address_0_0,
index: 0,
networkId: Cardano.NetworkId.Testnet,
rewardAccount: rewardAccount_1,
rewardAccount: rewardAccount_0,
stakeKeyDerivationPath: { index: 0, role: KeyRole.Stake },
type: AddressType.External
},
{
accountIndex: 0,
address: address_0_0,
index: 0,
address: address_1_0,
index: 1,
networkId: Cardano.NetworkId.Testnet,
rewardAccount: rewardAccount_0,
rewardAccount: rewardAccount_1,
stakeKeyDerivationPath: { index: 0, role: KeyRole.Stake },
type: AddressType.External
}
];

const newApi = cip30.createWalletApi(
of({
addresses$: of(addresses),
addresses$: of(addresses), // these are guaranteed to be sorted
getNextUnusedAddress: () => [addresses[1]]
} as unknown as ObservableWallet),
confirmationCallback,
Expand Down

0 comments on commit 19c4087

Please sign in to comment.