Skip to content

Commit

Permalink
Merge pull request #1323 from near/develop
Browse files Browse the repository at this point in the history
Minor Fixes - Promote develop to main
  • Loading branch information
gagdiez authored Oct 10, 2024
2 parents 1048456 + 67d2db2 commit 6ce1729
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 452 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"lodash": "^4.17.21",
"moment": "^2.30.1",
"near-api-js": "^4.0.3",
"near-fastauth-wallet": "2.0.1",
"near-fastauth-wallet": "2.0.4",
"near-social-vm": "github:calebjacob/VM#dev",
"next": "^13.5.6",
"next-pwa": "^5.6.0",
Expand Down
50 changes: 35 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions src/components/wallet-selector/WalletSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { setupFastAuthWallet } from 'near-fastauth-wallet';
import type { Context } from 'react';
import { createContext } from 'react';

import { networkId as defaultNetwork, signInContractId } from '@/config';
import { networkId as defaultNetwork } from '@/config';
import { KEYPOM_OPTIONS } from '@/utils/keypom-options';
import type { NetworkId } from '@/utils/types';

Expand Down Expand Up @@ -52,6 +52,8 @@ export class Wallet {
setupMeteorWallet(),
setupBitteWallet(),
setupHereWallet(),
setupLedger(),
setupNearMobileWallet(),
setupMyNearWallet(),
setupSender(),
setupMintbaseWallet(),
Expand Down Expand Up @@ -86,10 +88,8 @@ export class Wallet {
: 'https://dev.near.org/#instant-url/ACCOUNT_ID/SECRET_KEY/MODULE_ID',
},
networkId: this.networkId,
signInContractId,
signInContractId: this.createAccessKeyFor || '',
}) as any, // TODO: Refactor setupKeypom() to TS
setupLedger(),
setupNearMobileWallet(),
],
});

Expand Down Expand Up @@ -189,7 +189,14 @@ 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) 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) return providers.getTransactionLastResult(result);
};

getAccessKeys = async (accountId: string) => {
Expand Down
40 changes: 34 additions & 6 deletions src/components/wallet-utilities/ExportFastAuthAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ export const ExportFastAuthAccount = () => {
const [secretKey, setSecretKey] = useState('');
const [fastAuthAccountSignedIn, setFastAuthAccountSignedIn] = useState(false);
const [privateKeyVisible, setPrivateKeyVisible] = useState(false);
const [enoughBalance, setEnoughBalance] = useState(false);
const { wallet, signedAccountId } = useContext(NearContext);

useEffect(() => {
const balanceCheck = async () => {
if (!wallet || !signedAccountId) return;

const balance = await wallet.getBalance(signedAccountId);
setEnoughBalance(balance >= 0.001);
};

balanceCheck();
}, [wallet, signedAccountId]);

useEffect(() => {
const checkFastAuthAccount = async () => {
const selector = await wallet?.selector;
Expand All @@ -40,9 +52,7 @@ export const ExportFastAuthAccount = () => {

const generateKey = async () => {
try {
if (!signedAccountId || !wallet) {
throw new Error('Wallet has not initialized');
}
if (!wallet) throw new Error('Wallet has not initialized');

setGeneratingKey(true);

Expand All @@ -65,6 +75,24 @@ export const ExportFastAuthAccount = () => {

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

openToast({
type: 'info',
title: 'Checking for key',
description: 'We are checking if the key was added to your account, this can take up to 10 seconds',
duration: 5000,
});

let hasKey = false;

for (let i = 0; i < 5; i++) {
await new Promise((resolve) => setTimeout(resolve, 2000));
const accessKeys = await wallet.getAccessKeys(signedAccountId);
hasKey = accessKeys.some((key: any) => key.public_key === publicKey);
if (hasKey) break;
}

if (!hasKey) throw new Error('Failed to add access key');

setSecretKey(keyPair.toString());

openToast({
Expand All @@ -80,7 +108,7 @@ export const ExportFastAuthAccount = () => {
};

if (!fastAuthAccountSignedIn) {
return <Text>The export feature is only for FastAuth accounts. You are currently signed in with a wallet.</Text>;
return <Text>This tool allows to export accounts created with an email (also known as FastAuth accounts)</Text>;
}

return (
Expand Down Expand Up @@ -148,10 +176,10 @@ export const ExportFastAuthAccount = () => {
</Card>
) : (
<Button
disabled={!signedAccountId}
disabled={!signedAccountId || !enoughBalance}
loading={generatingKey}
onClick={generateKey}
label="Create Full Access Key"
label={enoughBalance ? 'Create Full Access Key' : 'Not enough balance (0.001 Ⓝ required)'}
variant="affirmative"
/>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/wallet-utilities/ReceiveNear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { NearContext } from '../wallet-selector/WalletSelector';
export const ReceiveNear = () => {
const { signedAccountId } = useContext(NearContext);

if (!signedAccountId) return <Text> Sign in to see your NEAR account name </Text>;

return (
<Flex stack>
<Text size="text-s">Copy and share your account ID to receive NEAR:</Text>
Expand Down
4 changes: 3 additions & 1 deletion src/components/wallet-utilities/SendNear.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Flex, Form, handleClientError, Input, openToast } from '@near-pagoda/ui';
import { Button, Flex, Form, handleClientError, Input, openToast, Text } from '@near-pagoda/ui';
import { utils } from 'near-api-js';
import { useEffect, useState } from 'react';
import { useContext } from 'react';
Expand Down Expand Up @@ -95,6 +95,8 @@ export const SendNear = () => {
}
};

if (!signedAccountId) return <Text> Sign in to send NEAR </Text>;

return (
<Form onSubmit={form.handleSubmit(validSubmitHandler)}>
<Flex stack gap="l">
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
Loading

0 comments on commit 6ce1729

Please sign in to comment.