Skip to content

Commit

Permalink
feat: automatically navigate to single search results
Browse files Browse the repository at this point in the history
fix: transaction search results
  • Loading branch information
donnyquixotic committed Feb 8, 2024
1 parent 05bd3dc commit 638b39e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/HeaderSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineComponent, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { OptionsObj, TableByScope } from 'src/types';
import { api } from 'src/api';
import { isValidTransactionHex } from 'src/utils/string-utils';
import { ACCOUNT_LENGTH, TRANSACTION_HASH_LENGTH, isValidTransactionHex } from 'src/utils/string-utils';
import { useQuasar } from 'quasar';
import { systemAccounts } from 'src/utils/systemAccount';
import { debounce } from 'src/utils/time';
Expand Down Expand Up @@ -32,7 +32,14 @@ export default defineComponent({
searchProposals(queryValue),
searchTransactions(queryValue),
]).then((results) => {
// flatten search results
options.value = ([] as OptionsObj[]).concat.apply([], results);
// trigger navigation on single result
const filteredResults = options.value.filter(result => !result.isHeader);
if (filteredResults.length === 1){
void handleGoTo(filteredResults[0].to);
}
});
isLoading.value = false;
Expand All @@ -45,6 +52,9 @@ export default defineComponent({
async function searchAccounts(value: string): Promise<OptionsObj[]> {
try {
const results = [] as OptionsObj[];
if (value.length > ACCOUNT_LENGTH){
return results;
}
const request = {
code: 'eosio',
limit: 5,
Expand All @@ -66,6 +76,7 @@ export default defineComponent({
}
if (accounts.length > 0) {
results.push({
label: 'Accounts',
to: '',
Expand Down Expand Up @@ -123,14 +134,14 @@ export default defineComponent({
async function searchTransactions(value: string): Promise<OptionsObj[]> {
const results = [] as OptionsObj[];
if (value.length !== 64) {
if (value.length !== TRANSACTION_HASH_LENGTH) {
return results;
}
try {
const transactions = await api.getTransaction(value);
if (transactions?.actions) {
if (transactions?.trx_id) {
results.push({
label: 'Transactions',
to: '',
Expand Down
1 change: 1 addition & 0 deletions src/types/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ActionData {
value: number;
relation: string;
};
trx_id?: string;
}

export interface GetActionsResponse {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/string-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export function isValidTransactionHex(hexString: string): boolean {
return regEx.exec(hexString) !== null;
}

export const ACCOUNT_LENGTH = 12;
export const TRANSACTION_HASH_LENGTH = 64;

/**
* Given an amount of currency (e.g. `"1.0700"` or `3.4`), returns a pretty-printed string. Hidden-zero fractions
* such as `.2` are not accepted.
Expand Down

0 comments on commit 638b39e

Please sign in to comment.