diff --git a/.env.example b/.env.example index fdca766dc..f9dc085cd 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ +NEXT_PUBLIC_LOCAL_ENVIRONMENT=true NEXT_PUBLIC_NETWORK_ID=mainnet NEXT_PUBLIC_HOSTNAME=https://near.org # endpoint to fetch TOS and Privacy Policy from IPFS @@ -9,3 +10,6 @@ NEXT_PUBLIC_PRIVACY_CID= NEXT_PUBLIC_NOTIFICATIONS_HOSTNAME= NEXT_PUBLIC_NOTIFICATIONS_APPLICATION_SERVER_KEY= NEXT_PUBLIC_NOTIFICATIONS_GATEWAY_URL= +# commit modal bypass +NEXT_PUBLIC_COMMIT_MODAL_BYPASS_AUTHOR_IDS=near,discom.testnet,discom-dev.testnet +NEXT_PUBLIC_COMMIT_MODAL_BYPASS_SOURCES= \ No newline at end of file diff --git a/package.json b/package.json index ebb9fe978..60fe27049 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "local-storage": "^2.0.0", "lodash": "^4.17.21", "near-fastauth-wallet": "^0.0.10", - "near-social-vm": "github:NearSocial/VM#0285e7ca7126ebb865492bd6c8523338d09f99f1", + "near-social-vm": "github:NearSocial/VM#1344e8650e8f9a1b5781271183536bcfc815493f", "next": "^13.5.6", "react": "^18.2.0", "react-bootstrap": "^2.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fbca47347..0a154ffdb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -110,8 +110,8 @@ dependencies: specifier: ^0.0.10 version: 0.0.10 near-social-vm: - specifier: github:NearSocial/VM#0285e7ca7126ebb865492bd6c8523338d09f99f1 - version: github.com/NearSocial/VM/0285e7ca7126ebb865492bd6c8523338d09f99f1(@babel/core@7.23.3)(@popperjs/core@2.11.8)(@types/react-dom@18.2.10)(@types/react@18.2.25)(near-api-js@2.1.3)(prop-types@15.8.1)(react-dom@18.2.0)(react-is@18.2.0)(react@18.2.0) + specifier: github:NearSocial/VM#1344e8650e8f9a1b5781271183536bcfc815493f + version: github.com/NearSocial/VM/1344e8650e8f9a1b5781271183536bcfc815493f(@babel/core@7.23.3)(@popperjs/core@2.11.8)(@types/react-dom@18.2.10)(@types/react@18.2.25)(near-api-js@2.1.3)(prop-types@15.8.1)(react-dom@18.2.0)(react-is@18.2.0)(react@18.2.0) next: specifier: ^13.5.6 version: 13.5.6(@babel/core@7.23.3)(react-dom@18.2.0)(react@18.2.0) @@ -13463,7 +13463,7 @@ packages: /unist-util-stringify-position@3.0.3: resolution: {integrity: sha512-k5GzIBZ/QatR8N5X2y+drfpWG8IDBzdnVj6OInRNWm1oXrzydiaAT2OQiA8DPRRZyAKb9b6I2a6PxYklZD0gKg==} dependencies: - '@types/unist': 2.0.8 + '@types/unist': 2.0.10 dev: false /unist-util-visit-parents@5.1.3: @@ -13606,7 +13606,7 @@ packages: /vfile-message@3.1.4: resolution: {integrity: sha512-fa0Z6P8HUrQN4BZaX05SIVXic+7kE3b05PWAtPuYP9QLHsLKYR7/AlLW3NtOrpXRLeawpDLMsVkmk5DG0NXgWw==} dependencies: - '@types/unist': 2.0.8 + '@types/unist': 2.0.10 unist-util-stringify-position: 3.0.3 dev: false @@ -13980,11 +13980,11 @@ packages: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} dev: false - github.com/NearSocial/VM/0285e7ca7126ebb865492bd6c8523338d09f99f1(@babel/core@7.23.3)(@popperjs/core@2.11.8)(@types/react-dom@18.2.10)(@types/react@18.2.25)(near-api-js@2.1.3)(prop-types@15.8.1)(react-dom@18.2.0)(react-is@18.2.0)(react@18.2.0): - resolution: {tarball: https://codeload.github.com/NearSocial/VM/tar.gz/0285e7ca7126ebb865492bd6c8523338d09f99f1} - id: github.com/NearSocial/VM/0285e7ca7126ebb865492bd6c8523338d09f99f1 + github.com/NearSocial/VM/1344e8650e8f9a1b5781271183536bcfc815493f(@babel/core@7.23.3)(@popperjs/core@2.11.8)(@types/react-dom@18.2.10)(@types/react@18.2.25)(near-api-js@2.1.3)(prop-types@15.8.1)(react-dom@18.2.0)(react-is@18.2.0)(react@18.2.0): + resolution: {tarball: https://codeload.github.com/NearSocial/VM/tar.gz/1344e8650e8f9a1b5781271183536bcfc815493f} + id: github.com/NearSocial/VM/1344e8650e8f9a1b5781271183536bcfc815493f name: near-social-vm - version: 2.5.3 + version: 2.5.4 peerDependencies: near-api-js: 2.1.3 react: ^18.2.0 diff --git a/src/components/sandbox/Sandbox.js b/src/components/sandbox/Sandbox.js index ea5b365f6..cd99d641d 100644 --- a/src/components/sandbox/Sandbox.js +++ b/src/components/sandbox/Sandbox.js @@ -275,11 +275,15 @@ export const Sandbox = ({ onboarding = false }) => { const pathNew = nameToPath(path.type, newName); const jpathNew = fileToJpath(pathNew); + const onboardingId = onboarding && 'near'; + const src = getSrcByNameOrPath(pathNew.name, onboardingId || accountId, pathNew.type); + setFilesObject((state) => { const newState = { ...state, [jpathNew]: { ...state[jpath], + src, name: newName, }, }; @@ -410,10 +414,18 @@ export const Sandbox = ({ onboarding = false }) => { name: file.name, })); + const newName = generateNewName(type, files).name; + + const onboardingId = onboarding && 'near'; + const src = getSrcByNameOrPath(newName, onboardingId || accountId, type); + const path = toPath(type, newName); + const newFile = { ...fileObjectDefault, + ...path, + src, type, - name: generateNewName(type, files).name, + name: newName, codeMain: '', codeDraft: '', codeLocalStorage: newCode, diff --git a/src/components/vm/VmInitializer.tsx b/src/components/vm/VmInitializer.tsx index 3e5af138c..0125edf23 100644 --- a/src/components/vm/VmInitializer.tsx +++ b/src/components/vm/VmInitializer.tsx @@ -1,4 +1,3 @@ -import { isValidAttribute } from 'dompurify'; import { setupKeypom } from '@keypom/selector'; import type { WalletSelector } from '@near-wallet-selector/core'; import { setupWalletSelector } from '@near-wallet-selector/core'; @@ -15,6 +14,8 @@ import { setupNightly } from '@near-wallet-selector/nightly'; import { setupSender } from '@near-wallet-selector/sender'; import { setupWelldoneWallet } from '@near-wallet-selector/welldone-wallet'; import Big from 'big.js'; +import { isValidAttribute } from 'dompurify'; +import { mapValues } from 'lodash'; import { setupFastAuthWallet } from 'near-fastauth-wallet'; import { CommitButton, @@ -36,9 +37,14 @@ import { useAuthStore } from '@/stores/auth'; import { useIdosStore } from '@/stores/idosStore'; import { useVmStore } from '@/stores/vm'; import { recordWalletConnect, reset as resetAnalytics } from '@/utils/analytics'; -import { networkId, signInContractId } from '@/utils/config'; +import { + commitModalBypassAuthorIds, + commitModalBypassSources, + isLocalEnvironment, + networkId, + signInContractId, +} from '@/utils/config'; import { KEYPOM_OPTIONS } from '@/utils/keypom-options'; -import { mapValues } from 'lodash'; export default function VmInitializer() { const [signedIn, setSignedIn] = useState(false); @@ -113,7 +119,14 @@ export default function VmInitializer() { return ; }, }, - features: { enableComponentSrcDataKey: true }, + features: { + commitModalBypass: { + authorIds: commitModalBypassAuthorIds, + sources: commitModalBypassSources, + }, + enableComponentSrcDataKey: true, + enableWidgetSrcWithCodeOverride: isLocalEnvironment, + }, }); }, [initNear]); diff --git a/src/pages/signin.tsx b/src/pages/signin.tsx index 427ad7043..2f121bf70 100644 --- a/src/pages/signin.tsx +++ b/src/pages/signin.tsx @@ -1,11 +1,9 @@ -import { getKeys, isPassKeyAvailable } from '@near-js/biometric-ed25519'; -import { useRouter } from 'next/router'; +import { useSearchParams } from 'next/navigation'; import { useEffect } from 'react'; import { useForm } from 'react-hook-form'; import styled from 'styled-components'; import { Button } from '@/components/lib/Button'; -import { openToast } from '@/components/lib/Toast'; import { useClearCurrentComponent } from '@/hooks/useClearCurrentComponent'; import { useDefaultLayout } from '@/hooks/useLayout'; import { useSignInRedirect } from '@/hooks/useSignInRedirect'; @@ -17,10 +15,10 @@ import { isValidEmail } from '../utils/form-validation'; const SignInPage: NextPageWithLayout = () => { const { register, handleSubmit, setValue } = useForm(); - const router = useRouter(); const requestSignInWithWallet = useAuthStore((store) => store.requestSignInWithWallet); const signedIn = useAuthStore((store) => store.signedIn); const vmNear = useAuthStore((store) => store.vmNear); + const searchParams = useSearchParams(); const { redirect } = useSignInRedirect(); useEffect(() => { @@ -29,6 +27,18 @@ const SignInPage: NextPageWithLayout = () => { } }, [redirect, signedIn]); + useEffect(() => { + if (vmNear?.selector && searchParams.get('account_id') && searchParams.get('public_key')) { + vmNear.selector + .then((selector: any) => selector.wallet('fast-auth-wallet')) + .then((fastAuthWallet: any) => + fastAuthWallet.signIn({ + contractId: vmNear.config.contractName, + }), + ); + } + }, [searchParams, vmNear]); + useClearCurrentComponent(); const onSubmit = handleSubmit(async (data) => { diff --git a/src/utils/config.ts b/src/utils/config.ts index a5f6dc7c6..4cb663c2a 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -63,3 +63,11 @@ export const notificationsHostName = process.env.NEXT_PUBLIC_NOTIFICATIONS_HOSTN export const notificationsGatewayUrl = process.env.NEXT_PUBLIC_NOTIFICATIONS_GATEWAY_URL ?? 'https://near.org'; export const notificationsLocalStorageKey = 'push-notifications-v0'; export const localStorageAccountIdKey = 'near-social-vm:v01::accountId:'; +export const isLocalEnvironment = process.env.NEXT_PUBLIC_LOCAL_ENVIRONMENT === 'true'; + +export const commitModalBypassAuthorIds = (process.env.NEXT_PUBLIC_COMMIT_MODAL_BYPASS_AUTHOR_IDS ?? '') + .split(',') + .filter((item) => !!item); +export const commitModalBypassSources = (process.env.NEXT_PUBLIC_COMMIT_MODAL_BYPASS_SOURCES ?? '') + .split(',') + .filter((item) => !!item);