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: collection of small fixes #1322

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 18 additions & 1 deletion src/components/wallet-selector/WalletSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,24 @@ export class Wallet {

signAndSendTransactions = async ({ transactions }: { transactions: any[] }) => {
const selectedWallet = await (await this.selector).wallet();
return selectedWallet.signAndSendTransactions({ transactions });
const result = await selectedWallet.signAndSendTransactions({ transactions });

if (!result) {
throw new Error('Transaction failed');
} else {
return Promise.all(result.map(async (o) => providers.getTransactionLastResult(o)));
}
};

signAndSendTransaction = async (transaction: any) => {
const selectedWallet = await (await this.selector).wallet();
const result = await selectedWallet.signAndSendTransaction(transaction);

if (!result) {
throw new Error(`Transaction ${JSON.stringify(transaction)} failed`);
} else {
return providers.getTransactionLastResult(result);
}
};

getAccessKeys = async (accountId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallet-utilities/ExportFastAuthAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const ExportFastAuthAccount = () => {
],
};

await wallet.signAndSendTransactions({ transactions: [addKeyTransaction] });
await wallet.signAndSendTransaction(addKeyTransaction);

setSecretKey(keyPair.toString());

Expand Down
6 changes: 4 additions & 2 deletions src/pages/[accountId]/widget/[componentName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const ViewComponentPage: NextPageWithLayout = () => {
}, [signedAccountId, componentProps, requestAuthentication]);

useEffect(() => {
setComponentProps(router.query);
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
setComponentProps(params);
}, [router.query]);

return (
Expand All @@ -37,7 +39,7 @@ const ViewComponentPage: NextPageWithLayout = () => {
key={components.wrapper}
src={components.wrapper}
props={{
emitGatewayEvent: shouldPassGatewayEventProps(router.query.componentAccountId as string)
emitGatewayEvent: shouldPassGatewayEventProps(router.query.accountId as string)
? emitGatewayEvent
: undefined,
logOut: wallet?.signOut,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/embed/[accountId]/widget/[componentName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const EmbedComponentPage: NextPageWithLayout = () => {
const { emitGatewayEvent, shouldPassGatewayEventProps } = useGatewayEvents();

useEffect(() => {
setComponentProps(router.query);
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
setComponentProps(params);
}, [router.query]);

return (
Expand Down
5 changes: 3 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const StyledCard = ({ href, title, description }: { href: string; title: string;
const HomePage: NextPageWithLayout = () => {
const [selectedTab, setTab] = useState('contracts');
const [avgBlockTime, setAvgBlockTime] = useState('1.30');
const [avgTxPrice, setAvgTxPrice] = useState('< $0.01');
const [avgTxPrice, setAvgTxPrice] = useState('0.01');
const [totalTx, setTotalTx] = useState('2,33');
const [nearStats, setNearStats] = useState<NearBlocks>();
const deviceType = useDeviceType();
Expand All @@ -49,6 +49,7 @@ const HomePage: NextPageWithLayout = () => {
fetch('https://api.nearblocks.io/v1/stats')
.then((response) => response.json())
.then((data) => {
if (!data.stats) return;
data = data.stats[0];
setNearStats(data);
setTotalTx((Number(data.total_txns) / 1_000_000_000).toFixed(2));
Expand All @@ -63,7 +64,7 @@ const HomePage: NextPageWithLayout = () => {
const feesResponse = await fetch('https://pikespeak.ai/api/live/last-txs-fees');
const feesData = await feesResponse.json();

const averageFee = (feesData * Number(nearStats.near_price)).toFixed(4);
const averageFee = (feesData * Number(nearStats.near_price)).toFixed(3);
setAvgTxPrice(averageFee);
};
getAvrTx();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/algoliaSearchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const fetchSearchHits = async (facet: Facet, query: string, page = 0) =>
});

if (!response.ok) {
throw new Error(`Failed to fetch search hits: ${response.statusText}`);
throw new Error(`Failed to fetch search hits: ${response.statusText}, please try again`);
}

return await response.json();
Expand Down
9 changes: 7 additions & 2 deletions src/utils/catalogSearchApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const fetchCatalog = async (query: string) => {
const response = await fetch(`https://indexer.nearcatalog.xyz/wp-json/nearcatalog/v1/search?kw=${query}`);
return await response.json();
try {
const response = await fetch(`https://indexer.nearcatalog.xyz/wp-json/nearcatalog/v1/search?kw=${query}`);
return await response.json();
} catch (error) {
console.error(error);
return [];
}
};
Loading