Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #121 from magiclabs/fix/deprecated_package
Browse files Browse the repository at this point in the history
Removed deprecated package. Updated magic-sdk package to latest version
  • Loading branch information
jamesrp13 authored Jan 19, 2024
2 parents 54b64e5 + e26bf24 commit f8f79bd
Show file tree
Hide file tree
Showing 29 changed files with 126 additions and 354 deletions.
3 changes: 0 additions & 3 deletions scaffolds/nextjs-dedicated-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ export default class DedicatedScaffold extends BaseScaffold {
if (authType.replaceAll(' ', '') === 'EmailOTP') {
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdateEmail.tsx');
}
if (authType.replaceAll(' ', '') === 'SMSOTP') {
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdatePhone.tsx');
}
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions scaffolds/nextjs-dedicated-wallet/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
"lint": "next lint --fix"
},
"dependencies": {
"@magic-ext/auth": "^4.0.0",
"@magic-ext/oauth": "^15.0.0",
"@types/node": "20.3.3",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"classnames": "^2.3.2",
"magic-sdk": "^21.0.0",
"magic-sdk": "^21.5.0",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getChainId, getNetworkUrl } from '@/utils/network';
import { OAuthExtension } from '@magic-ext/oauth';
import { AuthExtension } from '@magic-ext/auth';
import { Magic as MagicBase } from 'magic-sdk';
import { ReactNode, createContext, useContext, useEffect, useMemo, useState } from 'react';
const { Web3 } = require('web3');

export type Magic = MagicBase<AuthExtension & OAuthExtension[]>;
export type Magic = MagicBase<OAuthExtension[]>;

type MagicContextType = {
magic: Magic | null;
Expand All @@ -30,7 +29,7 @@ const MagicProvider = ({ children }: { children: ReactNode }) => {
rpcUrl: getNetworkUrl(),
chainId: getChainId(),
},
extensions: [new AuthExtension(), new OAuthExtension()],
extensions: [new OAuthExtension()],
});

setMagic(magic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const EmailOTP = ({ token, setToken }: LoginProps) => {
try {
setLoginInProgress(true);
setEmailError(false);
const account = await magic?.auth.loginWithEmailOTP({ email });
if (account) {
saveToken(account, setToken, 'EMAIL');
const token = await magic?.auth.loginWithEmailOTP({ email });
if (token) {
saveToken(token, setToken, 'EMAIL');
setEmail('');
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const SMSOTP = ({ token, setToken }: LoginProps) => {
try {
setLoginInProgress(true);
setPhoneError(false);
const account = await magic?.auth.loginWithSMS({
const token = await magic?.auth.loginWithSMS({
phoneNumber: phone,
});
if (account) {
saveToken(account, setToken, 'SMS');
if (token) {
saveToken(token, setToken, 'SMS');
setPhone('');
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { LoginMethod } from '@/utils/common';
<% if(loginMethods.map(authType => authType.replaceAll(" ", "")).includes("EmailOTP")){%>
<%-`import UpdateEmail from '../wallet-methods/UpdateEmail'`-%>
<% }%>
<% if(loginMethods.map(authType => authType.replaceAll(" ", "")).includes("SMSOTP")){%>
<%-`import UpdatePhone from '../wallet-methods/UpdatePhone'`-%>
<% }%>

const WalletMethods = ({ token, setToken }: LoginProps) => {
const [loginMethod, setLoginMethod] = useState<LoginMethod | null>(
Expand All @@ -29,14 +26,6 @@ const WalletMethods = ({ token, setToken }: LoginProps) => {
</>
)}`-%>
<% }%>
<% if(loginMethods.map(authType => authType.replaceAll(" ", "")).includes("SMSOTP")){%>
<%-`{loginMethod && loginMethod == 'SMS' && (
<>
<UpdatePhone />
<Divider />
</>
)}`-%>
<% }%>
<GetIdToken />
<Divider />
<GetMetadata />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ul {
}

.home-page {
@apply flex flex-col justify-center items-center min-h-screen relative bg-[length:100vw_320px] bg-no-repeat bg-[url('/main.svg')];
@apply flex flex-col justify-center items-center min-h-screen relative bg-[length:100vw_320px] bg-no-repeat;
}

.login-page {
Expand Down
3 changes: 0 additions & 3 deletions scaffolds/nextjs-flow-dedicated-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ export default class FlowDedicatedScaffold extends BaseScaffold {
if (authType.replaceAll(' ', '') === 'EmailOTP') {
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdateEmail.tsx');
}
if (authType.replaceAll(' ', '') === 'SMSOTP') {
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdatePhone.tsx');
}
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions scaffolds/nextjs-flow-dedicated-wallet/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"lint": "next lint --fix"
},
"dependencies": {
"@magic-ext/auth": "^4.0.0",
"@magic-ext/flow": "^16.0.0",
"@magic-ext/oauth": "^15.0.0",
"@onflow/fcl": "^1.6.0",
Expand All @@ -18,7 +17,7 @@
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"classnames": "^2.3.2",
"magic-sdk": "^21.0.0",
"magic-sdk": "^21.5.0",
"next": "13.4.7",
"postcss": "8.4.24",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,48 @@
import {getNetwork, getNetworkUrl} from '@/utils/network'
import {OAuthExtension} from '@magic-ext/oauth'
import {AuthExtension} from '@magic-ext/auth'
import {Magic as MagicBase} from 'magic-sdk'
import {
ReactNode,
createContext,
useContext,
useEffect,
useMemo,
useState,
} from 'react'
import {FlowExtension} from '@magic-ext/flow'
import * as fcl from '@onflow/fcl'
import { getNetwork, getNetworkUrl } from '@/utils/network';
import { OAuthExtension } from '@magic-ext/oauth';
import { Magic as MagicBase } from 'magic-sdk';
import { ReactNode, createContext, useContext, useEffect, useMemo, useState } from 'react';
import { FlowExtension } from '@magic-ext/flow';
import * as fcl from '@onflow/fcl';

export type Magic = MagicBase<
AuthExtension & OAuthExtension[] & FlowExtension[]
>
export type Magic = MagicBase<OAuthExtension[] & FlowExtension[]>;

type MagicContextType = {
magic: Magic | null
}
magic: Magic | null;
};

const MagicContext = createContext<MagicContextType>({
magic: null,
})

export const useMagic = () => useContext(MagicContext)

const MagicProvider = ({children}: {children: ReactNode}) => {
const [magic, setMagic] = useState<Magic | null>(null)

useEffect(() => {
if (process.env.NEXT_PUBLIC_MAGIC_API_KEY) {
const magic = new MagicBase(
process.env.NEXT_PUBLIC_MAGIC_API_KEY as string,
{
extensions: [
new AuthExtension(),
new OAuthExtension(),
new FlowExtension({
rpcUrl: getNetworkUrl(),
network: getNetwork() as string,
}),
],
}
)
setMagic(magic)
fcl.config().put('accessNode.api', getNetworkUrl())
}
}, [])

const value = useMemo(() => {
return {
magic,
}
}, [magic])

return (
<MagicContext.Provider value={value}>{children}</MagicContext.Provider>
)
}

export default MagicProvider
magic: null,
});

export const useMagic = () => useContext(MagicContext);

const MagicProvider = ({ children }: { children: ReactNode }) => {
const [magic, setMagic] = useState<Magic | null>(null);

useEffect(() => {
if (process.env.NEXT_PUBLIC_MAGIC_API_KEY) {
const magic = new MagicBase(process.env.NEXT_PUBLIC_MAGIC_API_KEY as string, {
extensions: [
new OAuthExtension(),
new FlowExtension({
rpcUrl: getNetworkUrl(),
network: getNetwork() as string,
}),
],
});
setMagic(magic);
fcl.config().put('accessNode.api', getNetworkUrl());
}
}, []);

const value = useMemo(() => {
return {
magic,
};
}, [magic]);

return <MagicContext.Provider value={value}>{children}</MagicContext.Provider>;
};

export default MagicProvider;
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const EmailOTP = ({ token, setToken }: LoginProps) => {
try {
setLoginInProgress(true);
setEmailError(false);
const account = await magic?.auth.loginWithEmailOTP({ email });
if (account) {
saveToken(account, setToken, 'EMAIL');
const token = await magic?.auth.loginWithEmailOTP({ email });
if (token) {
saveToken(token, setToken, 'EMAIL');
setEmail('');
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const SMSOTP = ({ token, setToken }: LoginProps) => {
try {
setLoginInProgress(true);
setPhoneError(false);
const account = await magic?.auth.loginWithSMS({
const token = await magic?.auth.loginWithSMS({
phoneNumber: phone,
});
if (account) {
saveToken(account, setToken, 'SMS');
if (token) {
saveToken(token, setToken, 'SMS');
setPhone('');
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import GetMetadata from '../wallet-methods/GetMetadata'
<% if(loginMethods.map(authType => authType.replaceAll(" ", "")).includes("EmailOTP")){%>
<%-`import UpdateEmail from '../wallet-methods/UpdateEmail'`-%>
<% }%>
<% if(loginMethods.map(authType => authType.replaceAll(" ", "")).includes("SMSOTP")){%>
<%-`import UpdatePhone from '../wallet-methods/UpdatePhone'`-%>
<% }%>

const WalletMethods = ({token, setToken}: LoginProps) => {
const [loginMethod, setLoginMethod] = useState<LoginMethod | null>(
Expand All @@ -29,14 +26,6 @@ const WalletMethods = ({token, setToken}: LoginProps) => {
</>
)}`-%>
<% }%>
<% if(loginMethods.map(authType => authType.replaceAll(" ", "")).includes("SMSOTP")){%>
<%-`{loginMethod && loginMethod == 'SMS' && (
<>
<UpdatePhone />
<Divider />
</>
)}`-%>
<% }%>
<GetIdToken />
<Divider />
<GetMetadata />
Expand Down

This file was deleted.

Loading

0 comments on commit f8f79bd

Please sign in to comment.