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

fix(wallet): remove redundant sort on getChangeAddres #1472

Merged
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
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
Loading