diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/package.json b/package.json index 47d6099..3a1b421 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ ], "main": "src/index.js", "dependencies": { - "@magic-ext/icon": "^0.1.11", + "@magic-ext/icon": "^14.0.0", "icon-sdk-js": "0.0.18", - "magic-sdk": "2.0.0", + "magic-sdk": "^19.0.0", "react": "16.12.0", "react-dom": "16.12.0", "react-scripts": "3.0.1" diff --git a/src/App.js b/src/App.js index b107f5c..808658c 100644 --- a/src/App.js +++ b/src/App.js @@ -3,14 +3,14 @@ import "./styles.css"; import { content } from "./data/contract"; import { Magic } from "magic-sdk"; import { IconExtension } from "@magic-ext/icon"; -import IconService from "icon-sdk-js"; +import IconService, { HttpProvider } from "icon-sdk-js"; const { IconBuilder, IconAmount, IconConverter } = IconService; -const magic = new Magic("pk_live_FC06C7D601338A6E", { +const magic = new Magic("pk_live_8D40A7E251F283ED", { extensions: { icon: new IconExtension({ - rpcUrl: "https://bicon.net.solidwallet.io/api/v3", + rpcUrl: "https://lisbon.net.solidwallet.io/api/v3", }), }, }); @@ -18,6 +18,7 @@ const magic = new Magic("pk_live_FC06C7D601338A6E", { export default function App() { const [email, setEmail] = useState(""); const [publicAddress, setPublicAddress] = useState(""); + const [balance, setBalance] = useState('0'); const [destinationAddress, setDestinationAddress] = useState(""); const [sendICXAmount, setSendICXAmount] = useState(0); const [contractTxHash, setContractTxHash] = useState(""); @@ -34,14 +35,28 @@ export default function App() { setIsLoggedIn(magicIsLoggedIn); if (magicIsLoggedIn) { const publicAddress = await magic.icon.getAccount(); + getBalance(publicAddress); setPublicAddress(publicAddress); setUserMetadata(await magic.user.getMetadata()); } }); }, [isLoggedIn]); + const getBalance = async (address) => { + const iconService = getIconService(); + const bal = await iconService.getBalance(address).execute(); + const formattedBalance = bal.toString() / 1000000000000000000; + console.log(formattedBalance); + setBalance(formattedBalance); + } + + const getIconService = () => { + const httpProvider = new HttpProvider('https://lisbon.net.solidwallet.io/api/v3'); + return new IconService(httpProvider); + } + const login = async () => { - await magic.auth.loginWithMagicLink({ email }); + await magic.auth.loginWithEmailOTP({ email }); setIsLoggedIn(true); }; @@ -58,7 +73,7 @@ export default function App() { .to(destinationAddress) .value(IconAmount.of(sendICXAmount, IconAmount.Unit.ICX).toLoop()) .stepLimit(IconConverter.toBigNumber(100000)) - .nid(IconConverter.toBigNumber(3)) + .nid(IconConverter.toBigNumber(2)) .nonce(IconConverter.toBigNumber(1)) .version(IconConverter.toBigNumber(3)) .timestamp(new Date().getTime() * 1000) @@ -77,7 +92,7 @@ export default function App() { .from(metadata.publicAddress) .to(massageDestinationAddress) .stepLimit(IconConverter.toBigNumber(1000000).toString()) - .nid(IconConverter.toBigNumber(3).toString()) + .nid(IconConverter.toBigNumber(2).toString()) .nonce(IconConverter.toBigNumber(1).toString()) .version(IconConverter.toBigNumber(3).toString()) .timestamp(new Date().getTime() * 1000) @@ -102,7 +117,7 @@ export default function App() { .from(metadata.publicAddress) .to("cx0000000000000000000000000000000000000000") .stepLimit(IconConverter.toBigNumber(2100000000).toString()) - .nid(IconConverter.toBigNumber(3).toString()) + .nid(IconConverter.toBigNumber(2).toString()) .nonce(IconConverter.toBigNumber(1).toString()) .version(IconConverter.toBigNumber(3).toString()) .timestamp(new Date().getTime() * 1000) @@ -130,7 +145,7 @@ export default function App() { .from(metadata.publicAddress) .to("cx568bb567298fbc60091c24080be20c1ce7751529") .stepLimit(IconConverter.toBigNumber("2000000").toString()) - .nid(IconConverter.toBigNumber("3").toString()) + .nid(IconConverter.toBigNumber("2").toString()) .nonce(IconConverter.toBigNumber("1").toString()) .version(IconConverter.toBigNumber("3").toString()) .timestamp(new Date().getTime() * 1000) @@ -143,7 +158,7 @@ export default function App() { const txhash = await magic.icon.sendTransaction(txObj); console.log("transaction result", txhash); - window.open(`https://bicon.tracker.solidwallet.io/transaction/${txhash}`); + window.open(`https://lisbon.tracker.solidwallet.io/transaction/${txhash}`); }; return ( @@ -172,13 +187,29 @@ export default function App() {