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

Feat: blacklist whitelist contacts #1814

Merged
merged 23 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions __mocks__/AddressBookMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AddressBook, IContact } from 'symbol-address-book';

export const addressBookMock: AddressBook = new AddressBook();
const contact1: IContact = {
id: '5c9093c7-2da2-476e-bc28-87f24a83cd0c',
address: 'TAVVVJBBCTYJDWC7TQPSVNHK2IPNY6URKK4DTHY',
name: 'Alice',
phone: '+34 000000000',
isBlackListed: true,
};
addressBookMock.addContact(contact1);
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ import TransactionListFilters from '@/components/TransactionList/TransactionList
import { getComponent } from '@MOCKS/Components';
import AccountStore from '@/store/Account';
import TransactionStore from '@/store/Transaction';
import AddressBookStore from '@/store/AddressBook';
import { AddressBook, IContact } from 'symbol-address-book';
import { getTestAccount } from '@MOCKS/Accounts';
let wrapper;
let vm;
import { addressBookMock } from '@MOCKS/AddressBookMock';
const currentSigner = getTestAccount('remoteTestnet');
const isBlackListFilterActivated = false;

beforeEach(() => {
wrapper = getComponent(
TransactionListFilters,
{ account: AccountStore, transaction: TransactionStore },
{ currentAccount: null, currentAccountSigner: {}, signers: [] },
{ account: AccountStore, transaction: TransactionStore, addressBook: AddressBookStore },
{
currentAccount: null,
currentAccountSigner: currentSigner,
addressBook: addressBookMock,
isBlackListFilterActivated: isBlackListFilterActivated,
signers: [],
},
{},
{},
);
Expand All @@ -25,8 +38,21 @@ describe('TransactionListFilters', () => {
vm.onSignerSelectorChange('TAD5BAHLOIXCRRB6GU2H72HPXMBBVAEUQRYPHBY');
expect(vm.$store.dispatch).toBeCalledWith('account/SET_CURRENT_SIGNER', { address: addr, reset: true, unsubscribeWS: false });
});

test("should not call the 'account/SET_CURRENT_SIGNER' without address", () => {
vm.onSignerSelectorChange();
expect(vm.$store.dispatch).not.toBeCalled();
});

test("should call 'transaction/filterTransactions' with blacklisted contacts", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add a test when isBlackListFilterActivated == true to cover else branch too

vm.onSelectBlackListed();
expect(vm.$store.commit).toBeCalledWith('transaction/filterTransactions', {
filterOption: null,
currentSignerAddress: currentSigner.address.plain(),
multisigAddresses: [],
shouldFilterOptionChange: true,
BlackListedContacts: addressBookMock.getBlackListedContacts(),
});
expect(vm.$store.commit).toBeCalledWith('transaction/isBlackListFilterActivated', !isBlackListFilterActivated);
});
});
23 changes: 23 additions & 0 deletions __tests__/services/TransactionFilterService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { TransactionFilterOptionsState, TransactionState } from '@/store/Transac
import { TransactionFilterService } from '@/services/TransactionFilterService';
import { getTestAccount } from '@MOCKS/Accounts';
import { TransferTransaction } from 'symbol-sdk';
import { addressBookMock } from '@MOCKS/AddressBookMock';
import { IContact } from 'symbol-address-book';

const currentSigner = getTestAccount('remoteTestnet');
const recepient = getTestAccount('remoteTestnetRecipient');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. not something you need to fix as part of this PR, but it's a bit confusing to use currentSigner as recipient address
  2. recepient is spelled wrong

Expand Down Expand Up @@ -108,6 +110,27 @@ describe('services/TransactionFilterService', () => {
done();
});

test('should return transactions only received from blacklisted contacts', async (done) => {
const addressBook = addressBookMock;
const contact1: IContact = {
id: '5c9093c7-2da2-476e-bc28-87f24a83cd23',
address: recepient.address.plain(),
name: 'BlackListed',
phone: '+34 000000000',
isBlackListed: true,
};
addressBook.addContact(contact1);
transactionState.filterOptions = new TransactionFilterOptionsState();
transactionState.filterOptions.isReceivedSelected = true;
const result = TransactionFilterService.filter(
transactionState,
currentSigner.address.plain(),
addressBook.getBlackListedContacts(),
);
expect(result.length).toBe(1);
done();
});

test('should return correct transactions on multiple criterias', async (done) => {
transactionState.filterOptions = new TransactionFilterOptionsState();
transactionState.filterOptions.isConfirmedSelected = true;
Expand Down
11 changes: 11 additions & 0 deletions __tests__/utils/CommonHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ describe('utils/CommonHelpers', () => {
expect(addresses.length).toBe(2);
});
});

describe('truncate(address)', () => {
test('returns truncated string', () => {
const address = Address.createFromRawAddress('TAD5BAHLOIXCRRB6GU2H72HPXMBBVAEUQRYPHBY');
const truncatedAddress = CommonHelpers.truncate(address.plain());
const string = 'string';
expect(truncatedAddress.length).toBe(15);
expect(truncatedAddress.substring(truncatedAddress.length - 6)).toEqual('...HBY');
expect(CommonHelpers.truncate(string).length).toBe(6);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. it's probably better to rename string to something more descriptive like shortString
  2. in future, generally would try to group Arrange / Act / Assert [see https://hackmd.io/WrKdAaohRXKgCbzd_4ZMxA]

});
});
});
2 changes: 1 addition & 1 deletion src/components/ContactDetailPanel/ContactDetailPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
? $t('black_list_contact_confirmation_message', { contactName: selectedContact.name })
: $t('white_list_contact_confirmation_message', { contactName: selectedContact.name })
"
@confirmed="BlackListWhiteListContact"
@confirmed="ToggleBlackListContact"
/>
</div>
</template>
Expand Down
4 changes: 3 additions & 1 deletion src/components/ContactDetailPanel/ContactDetailPanelTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class ContactDetailPanelTs extends Vue {
public get showBlackWhiteListModal() {
return this.showBlackWhiteListConfirmModal;
}

public set showBlackWhiteListModal(val: boolean) {
Jaguar0625 marked this conversation as resolved.
Show resolved Hide resolved
this.showBlackWhiteListConfirmModal = val;
}
Expand All @@ -98,11 +99,12 @@ export class ContactDetailPanelTs extends Vue {
this.showDeleteConfirmModal = false;
}

public BlackListWhiteListContact() {
public ToggleBlackListContact() {
this.selectedContact.isBlackListed = !this.selectedContact?.isBlackListed;
this.$store.dispatch('addressBook/UPDATE_CONTACT', { id: this.selectedContact.id, contact: this.selectedContact });
this.showBlackWhiteListModal = false;
}
Jaguar0625 marked this conversation as resolved.
Show resolved Hide resolved

@Watch('addressBook', { immediate: true })
onContactListChange() {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ export class TransactionListFiltersTs extends Vue {
public downloadTransactions() {
this.$emit('downloadTransactions');
}
onSelectBlackListed() {
const blackListed = this.addressBook.getBlackListedContacts();

/**
* Hook called when user want to filter transactions with blacklisted addresses
* @protected
*/
protected onSelectBlackListed() {
if (!this.isBlackListFilterActivated) {
const blackListed = this.addressBook.getBlackListedContacts();
this.$store.commit('transaction/filterTransactions', {
filterOption: null,
currentSignerAddress: this.currentAccountSigner.address.plain(),
Expand Down