From 8927d6b9e5386b14a707d7f7c5f03471977fcbd1 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Sun, 14 Jun 2020 20:24:09 -0400 Subject: [PATCH 01/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Add=20user=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 + src/ProvidersWrapper.tsx | 20 +++++++++ src/components/userBase/UserBase.tsx | 62 ++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/components/userBase/UserBase.tsx diff --git a/package.json b/package.json index 2b5e380..b19aa34 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "react-dev-utils": "10.0.0", "react-device-detect": "^1.11.14", "react-dom": "^16.12.0", + "react-modal": "^3.11.2", "react-toast-notifications": "^2.4.0", "react-tooltip": "^3.11.6", "resolve": "1.12.2", @@ -83,6 +84,7 @@ "ts-pnp": "1.1.5", "typescript": "^3.7.5", "url-loader": "2.3.0", + "userbase-js": "^1.4.1", "webpack": "4.41.2", "webpack-dev-server": "3.9.0", "webpack-manifest-plugin": "2.2.0", diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index ca4fbd9..8fd58ec 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -8,7 +8,11 @@ import * as consts from 'consts' import { DomElementsContext, EthereumContext } from 'contexts' import { EmitterProvider } from 'providers/EmitterProvider/provider' import { useWeb3Provider } from 'hooks' +import userbase from 'userbase-js' import { Activator } from './Activator' +import { UserBase as UBase } from './components/userBase/UserBase' + +console.log('userbase', userbase) export const ProvidersWrapper: React.FC = () => { // react hooks @@ -23,6 +27,21 @@ export const ProvidersWrapper: React.FC = () => { const ethereum = useWeb3Provider(consts.global.POLLING_INTERVAL) // This sets refresh speed of the whole app + // load serBase + // const [ db, setDB ] = useState(null) + useEffect(() => { + + userbase.init({ appId: '133a735a-a754-4e59-9aa9-8bfd1786c4c6' }).then((session) => { + // SDK initialized successfully + console.log('The session', session) + if (session.user) { + // there is a valid active session + console.log(session.user.username) + } + }).catch((e) => console.error(e)) + + }, []) + // load contracts effects only if not paused useEffect(() => { const getConfig = async () => { @@ -82,6 +101,7 @@ export const ProvidersWrapper: React.FC = () => { + { + let subtitle + + const [ modalIsOpen, setIsOpen ] = useState(false) + + const openModal = () => { + setIsOpen(true) + } + + const closeModal = () => { + setIsOpen(false) + } + + useEffect(() => { + if (window.dappHero) { + window.dappHero.db = db + window.dappHero.openModal = openModal + window.dappHero.closeModal = closeModal + } + }, [ window.dappHero, db ]) + + return ( +
+ + + + {/*

(subtitle = _subtitle)}>Hello

*/} + +
I am a modal
+
+ + + +
+
+
+ ) +} + From 8cc1012f97cabc0a8fc3cec22289ef065c06cb36 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Sun, 14 Jun 2020 20:26:54 -0400 Subject: [PATCH 02/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Add=20userBase?= =?UTF-8?q?=20(db)=20to=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Activator.tsx | 3 +++ src/ProvidersWrapper.tsx | 1 + src/components/userBase/UserBase.tsx | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Activator.tsx b/src/Activator.tsx index 160f3cf..70397fc 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -26,6 +26,7 @@ type ActivatorProps = { timeStamp: any; contractElements: any; domElementsFilteredForContracts: any; + db: any; } export const Activator: React.FC = ({ @@ -37,6 +38,7 @@ export const Activator: React.FC = ({ supportedNetworks, contractElements, domElementsFilteredForContracts, + db, }: ActivatorProps) => { // Ethereum @@ -66,6 +68,7 @@ export const Activator: React.FC = ({ retriggerEngine, projectId: consts.global.apiKey, provider: ethereum, + db, toggleHighlight(): void { dappHero.highlightEnabled = !dappHero.highlightEnabled highlightDomElements(dappHero.highlightEnabled, domElements) diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index 8fd58ec..a031edd 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -111,6 +111,7 @@ export const ProvidersWrapper: React.FC = () => { supportedNetworks={supportedNetworks} domElementsFilteredForContracts={smartcontractElements.domElementsFilteredForContracts} contractElements={smartcontractElements.contractElements} + db={userbase} />
diff --git a/src/components/userBase/UserBase.tsx b/src/components/userBase/UserBase.tsx index 035e2e5..12574f1 100644 --- a/src/components/userBase/UserBase.tsx +++ b/src/components/userBase/UserBase.tsx @@ -30,7 +30,7 @@ export const UserBase = ({ db }) => { useEffect(() => { if (window.dappHero) { - window.dappHero.db = db + // window.dappHero.db = db window.dappHero.openModal = openModal window.dappHero.closeModal = closeModal } From 74b197d0a44eb8c8fbdbac8fee332ab45372ee1c Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 10:02:44 -0400 Subject: [PATCH 03/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20=20Add=20Matic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/consts/provider.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/consts/provider.ts b/src/consts/provider.ts index 963cd10..21f2758 100644 --- a/src/consts/provider.ts +++ b/src/consts/provider.ts @@ -34,5 +34,9 @@ export const readProviders = { http: 'https://dai.poa.network', ws: 'wss://dai-trace-ws.blockscout.com/ws', }, + maticMumbai: { + http: `https://rpc-mumbai.matic.today`, + ws: '', + }, } From 059cd7cf1fcce8f2f0688791c776d59abccb6a1f Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 10:31:06 -0400 Subject: [PATCH 04/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Add=20Matic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/consts/provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/consts/provider.ts b/src/consts/provider.ts index 21f2758..e76c1bb 100644 --- a/src/consts/provider.ts +++ b/src/consts/provider.ts @@ -34,7 +34,7 @@ export const readProviders = { http: 'https://dai.poa.network', ws: 'wss://dai-trace-ws.blockscout.com/ws', }, - maticMumbai: { + maticMumbaiTestnet: { http: `https://rpc-mumbai.matic.today`, ws: '', }, From 499b6ad13375dc77977953e57b670066126614c6 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 11:32:01 -0400 Subject: [PATCH 05/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Fix=20Matic=20a?= =?UTF-8?q?nd=20UserBase=20Support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 1331 ++++++++++++++------------------------ src/ProvidersWrapper.tsx | 7 +- src/consts/global.ts | 1 + src/consts/provider.ts | 6 +- 4 files changed, 507 insertions(+), 838 deletions(-) diff --git a/public/index.html b/public/index.html index 8cadef0..ef895ce 100644 --- a/public/index.html +++ b/public/index.html @@ -1,845 +1,516 @@ - - - - - - DappHero: Components - - - - - -
- - -

Network Features

- - -
Network: Get ID
-

NetworkID should be here

- - - - - -
Network: Get Name
-
Network ID should be here
- - - - - - - -
Network: Get Provider
-
Network provider should be here
- - - - - - - -
Network: Transfer - (unfinished)
- - - -
- - - - - - - -
Network: Get Provider
-
Network provider should be here
- - - - - - -
Network: Enable Button (unfinished)
- - - - - -

User Features

- - -
User: Account Adddress
-

User Address Should be Here

- - -
User: Account Adddress Short
-

User Address Should be Here

- - -
User: Get Balance
-

User Address Should be Here

- - -

3Box Features

- - -
3Box: UserName
-

3box name

- -
3Box: Website
-

3box website

- - - - - - - - - - - - - - - - - - -

Custom Contract

- -
Method: "hello"
-
Payable: false - StateMutability: "view"
-
-

Inputs

-
    -
  • none
  • -
- -

Outputs

-
    -
  • no name - bytes32
  • -
-
- -
- - -
- *Return value: -* -
-
- -
- - -
Method: "sendEthWithArgs"
-
Payable: true - StateMutability: "payable"
-
No ETH Sent
-
-

Inputs

-
    -
  • message - bytes32
  • -
- -

Outputs

-
    -
  • none
  • -
-
- -
- - - - -
- *Return value: -* -
-
- -
- - - - -
Method: "sendEthWithArgs"
-
Payable: true - StateMutability: "payable"
-
ETH Value: HardCoded: .15ETH
-
-

Inputs

-
    -
  • message - bytes32
  • -
- -

Outputs

-
    -
  • none
  • -
-
- -
- - - - -
- *Return value: -* -
-
- -
- - - - - -
Method: "sendEthWithArgs"
-
Payable: true - StateMutability: "payable"
-
ETH Value: User Input
-
-

Inputs

-
    -
  • message - bytes32
  • -
- -

Outputs

-
    -
  • none
  • -
-
- -
This is the method
- - - - - - - -
- *Return value: -* -
- - -
- - - - - - - - -
Method: "viewMultipleArgsMultipleReturn"
-
Payable: false - StateMutability: "view"
-
-

Inputs

-
    -
  • from - address
  • -
  • multiplier - uint256
  • -
- -

Outputs

-
    -
  • _balanceMultiplied - uint256
  • -
  • _hello - bytes32
  • -
-
- -
- - - - - -
- *Return value: -* -
-
- - - - - -
Method: "sendVariableEthNoArgs"
-
Payable: true - StateMutability: "payable"
-
No eth is sent here.
-
-

Inputs

-
    -
  • none
  • -
- -

Outputs

-
    -
  • none
  • -
- > - -
- - -
- *Return value: -* -
-
- -
- - -
Method: "viewMultipleArgsSingleReturn"
-
Payable: false - StateMutability: "view"
-
-

Inputs

-
    -
  • fromAddress - address
  • -
  • amount - uint256
  • -
- -

Outputs

-
    -
  • longInteger - uint256 : (Should be: 8989898989)
  • -
-
- -
- - - - - - -
- *Return value: -* -
-
- -
- - -
Method: "viewNoArgsMultipleReturn"
-
Payable: false - StateMutability: "view"
-
-

Inputs

-
    -
  • none
  • -
- -

Outputs

-
    -
  • importantNumber - uint256 (should be zero)
  • -
  • hello - bytes32
  • -
-
- -
- --> - - All the args are returned in one, and in their respective output -
- A greeting here in bytes32 -
-
- A greeting here in bytes32 -
- -
Important Number here
- -
- *Return value: -* -
-
- *Return value: -* -
-
- -
- - - - - - - - - - - - - - - - - - - - -
ERC721 - Single NFT from an Owner
-
With Owner Account address and Token id
- -
-
-
- -
-

-
- $THIS_TokenID -
-
- -
- -
- - - -
ERC721 - List of specific NFTs from an Owner
-
With Owner Account address and Token ids
- -
-
- -

-
-
- -
- - - -
ERC721 - List of NFTs from an Owner
-
With Owner Account address
- -
-
- -

-
-
- -
- - -
ERC721 - List of NFTs from an Owner with Pagination
-
With Owner Account address
- -
- - - -
- -

-
-
- -
- - -
ERC721 - Single NFT from an Contract
-
With Asset contract address
- -
-
- -

-
-
- -
- - -
ERC721 - List of NFTs from an Contract
-
With Asset contract address
- -
-
- -

-
-
- -
- - -
ERC721 - List of NFTs from an Contract
-
With Asset contract address
- -
-
- -

-
-
- -
- - +

+
-
+

MaticWrappedEth

+
+
+

Public Methods

+
+
+

Method "name"

+
+ +
+
+
+ , +
+
+

Method "totalSupply"

+
+ +
+
+
+ , +
+
+

Method "decimals"

+
+ +
+
+
+ , +
+
+

Method "balanceOf"

+
+ +
+
+
+ , +
+
+

Method "symbol"

+
+ +
+
+
+ , +
+
+

Method "allowance"

+
+ +
+
+
+
+
+
+
+

Transaction Methods

+
+
+

Method "approve"

+
+ +
+
+
+ , +
+
+

Method "transferFrom"

+
+ +
+
+
+ , +
+
+

Method "withdraw"

+
+ +
+
+
+ , +
+
+

Method "transfer"

+
+ +
+
+
+ , +
+
+

Method "deposit"

+
+ +
+
+
+
+
- - - + + + - diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index a031edd..3ba7802 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -12,8 +12,6 @@ import userbase from 'userbase-js' import { Activator } from './Activator' import { UserBase as UBase } from './components/userBase/UserBase' -console.log('userbase', userbase) - export const ProvidersWrapper: React.FC = () => { // react hooks const [ configuration, setConfig ] = useState(null) @@ -31,12 +29,11 @@ export const ProvidersWrapper: React.FC = () => { // const [ db, setDB ] = useState(null) useEffect(() => { - userbase.init({ appId: '133a735a-a754-4e59-9aa9-8bfd1786c4c6' }).then((session) => { + userbase.init({ appId: process.env.REACT_APP_USERBASE_APP_ID }).then((session) => { // SDK initialized successfully - console.log('The session', session) if (session.user) { // there is a valid active session - console.log(session.user.username) + // console.log(session.user.username) } }).catch((e) => console.error(e)) diff --git a/src/consts/global.ts b/src/consts/global.ts index 07fafcf..31c8cc8 100644 --- a/src/consts/global.ts +++ b/src/consts/global.ts @@ -9,6 +9,7 @@ export const ethNetworkName = { 77: 'Sokol', 99: 'Core', 100: 'Xdai', + 80001: 'maticMumbaiTestnet', } const apiKeyElement = document.getElementById('dh-apiKey') export const apiKey = apiKeyElement.getAttribute('data-api') diff --git a/src/consts/provider.ts b/src/consts/provider.ts index e76c1bb..17dc025 100644 --- a/src/consts/provider.ts +++ b/src/consts/provider.ts @@ -30,12 +30,12 @@ export const readProviders = { http: 'https://eth-goerli.alchemyapi.io/v2/mo2KeoBlZY6CAyc2o1i4BcBNioVN_wpJ', ws: 'wss://eth-goerli.ws.alchemyapi.io/v2/mo2KeoBlZY6CAyc2o1i4BcBNioVN_wpJ', }, - xDai: { + xdai: { http: 'https://dai.poa.network', ws: 'wss://dai-trace-ws.blockscout.com/ws', }, - maticMumbaiTestnet: { - http: `https://rpc-mumbai.matic.today`, + maticmumbaitestnet: { + http: 'https://rpc-mumbai.matic.today', ws: '', }, From 76c98bce2b4a0491cf549e760f281d22720e9cd3 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 12:14:33 -0400 Subject: [PATCH 06/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20disable=20User?= =?UTF-8?q?=20base=20for=20the=20moment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Activator.tsx | 2 +- src/ProvidersWrapper.tsx | 7 ++++++- src/api/dappHero.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Activator.tsx b/src/Activator.tsx index 70397fc..87e1e80 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -68,7 +68,7 @@ export const Activator: React.FC = ({ retriggerEngine, projectId: consts.global.apiKey, provider: ethereum, - db, + // db, toggleHighlight(): void { dappHero.highlightEnabled = !dappHero.highlightEnabled highlightDomElements(dappHero.highlightEnabled, domElements) diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index 3ba7802..95f99d7 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -26,10 +26,15 @@ export const ProvidersWrapper: React.FC = () => { const ethereum = useWeb3Provider(consts.global.POLLING_INTERVAL) // This sets refresh speed of the whole app // load serBase - // const [ db, setDB ] = useState(null) + const [ db, setDB ] = useState(null) useEffect(() => { userbase.init({ appId: process.env.REACT_APP_USERBASE_APP_ID }).then((session) => { + userbase.deleteUser = null + userbase.purchaseSubscription = null + userbase.cancelSubscription = null + userbase.resumeSubscription = null + userbase.updatePaymentMethod = null // SDK initialized successfully if (session.user) { // there is a valid active session diff --git a/src/api/dappHero.ts b/src/api/dappHero.ts index 08a8fa5..99b62e1 100644 --- a/src/api/dappHero.ts +++ b/src/api/dappHero.ts @@ -117,11 +117,11 @@ export const getContractsByProjectKey = async (projectId) => { return (await getContractsByProjectKeyDappHero(projectId)) } catch (error) { // If the error fails, then try bubble - logger.log('(DH-CORE) Error in Global Cache Network, re-trying...', error) + logger.error('(DH-CORE) Error in Global Cache Network, re-trying...', error) try { return (await getContractsByProjectKeyBubble(projectId) ) } catch (error) { - logger.log('(DH-CORE) Failure in project cache backend', error) + logger.error('(DH-CORE) Failure in project cache backend', error) } } } From 03aef87a039c36feabb217d4e6de6e9974bc0ccf Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 15:47:46 -0400 Subject: [PATCH 07/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20=20working=20userba?= =?UTF-8?q?se!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Activator.tsx | 2 +- src/ProvidersWrapper.tsx | 29 ++++++++++++------------- src/api/database.ts | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 src/api/database.ts diff --git a/src/Activator.tsx b/src/Activator.tsx index 87e1e80..70397fc 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -68,7 +68,7 @@ export const Activator: React.FC = ({ retriggerEngine, projectId: consts.global.apiKey, provider: ethereum, - // db, + db, toggleHighlight(): void { dappHero.highlightEnabled = !dappHero.highlightEnabled highlightDomElements(dappHero.highlightEnabled, domElements) diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index 95f99d7..47328ba 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -8,10 +8,11 @@ import * as consts from 'consts' import { DomElementsContext, EthereumContext } from 'contexts' import { EmitterProvider } from 'providers/EmitterProvider/provider' import { useWeb3Provider } from 'hooks' -import userbase from 'userbase-js' import { Activator } from './Activator' import { UserBase as UBase } from './components/userBase/UserBase' +import { DB } from './api/database' + export const ProvidersWrapper: React.FC = () => { // react hooks const [ configuration, setConfig ] = useState(null) @@ -27,21 +28,19 @@ export const ProvidersWrapper: React.FC = () => { // load serBase const [ db, setDB ] = useState(null) + console.log('ProvidersWrapper:React.FC -> db', db) useEffect(() => { - userbase.init({ appId: process.env.REACT_APP_USERBASE_APP_ID }).then((session) => { - userbase.deleteUser = null - userbase.purchaseSubscription = null - userbase.cancelSubscription = null - userbase.resumeSubscription = null - userbase.updatePaymentMethod = null - // SDK initialized successfully - if (session.user) { - // there is a valid active session - // console.log(session.user.username) - } - }).catch((e) => console.error(e)) + const makeDBConnection = async () => { + const db = await new DB({ appId: process.env.REACT_APP_USERBASE_APP_ID, projectId: consts.global.apiKey }) + setDB(db) + // db.init().then((session) => { + // setDB(db) + // console.log('The session: ', session) + // }).catch((e) => console.error(e)) + } + makeDBConnection() }, []) // load contracts effects only if not paused @@ -103,7 +102,7 @@ export const ProvidersWrapper: React.FC = () => { - + { supportedNetworks={supportedNetworks} domElementsFilteredForContracts={smartcontractElements.domElementsFilteredForContracts} contractElements={smartcontractElements.contractElements} - db={userbase} + db={db} /> diff --git a/src/api/database.ts b/src/api/database.ts new file mode 100644 index 0000000..471219c --- /dev/null +++ b/src/api/database.ts @@ -0,0 +1,46 @@ +import userbase from 'userbase-js' + +export class DB { + constructor({ appId, projectId }) { + this.projectId = projectId + userbase.init({ appId }) + } + + // async init(): Promise { + // return this.userbase.init({ appId: this.appId }) + // } + + async signUp(details): Promise { + return userbase.signUp(details) + } + + async signIn(details): Promise { + console.log('details', details) + return userbase.signIn({ ...details }) + } + + async signOut(): Promise { + return userbase.signOut() + } + + async forgotPassword(username): Promise { + return userbase.forgotPassword(username) + } + + async openDatabase(changeFunc): Promise { + return userbase.openDatabase({ databaseName: this.projectId, changeHandler: changeFunc }) + } + + async insertItem(item): Promise { + return userbase.insertItem({ databaseName: this.projectId, item }) + } + + async updateItem(item, itemId): Promise { + return userbase.updateItem({ databaseName: this.projectId, item, itemId }) + } + + async deleteItem(itemId): Promise { + return userbase.deleteItem({ databaseName: this.projectId, itemId }) + } + +} From 274170abfe3e5160fdd8857ba6ccb328b18cba86 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 15:55:02 -0400 Subject: [PATCH 08/23] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20Add=20types=20to?= =?UTF-8?q?=20DB=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ProvidersWrapper.tsx | 10 +++------- src/api/database.ts | 7 ++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index 47328ba..f72530a 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -28,19 +28,15 @@ export const ProvidersWrapper: React.FC = () => { // load serBase const [ db, setDB ] = useState(null) - console.log('ProvidersWrapper:React.FC -> db', db) useEffect(() => { const makeDBConnection = async () => { const db = await new DB({ appId: process.env.REACT_APP_USERBASE_APP_ID, projectId: consts.global.apiKey }) setDB(db) - // db.init().then((session) => { - // setDB(db) - // console.log('The session: ', session) - // }).catch((e) => console.error(e)) } - - makeDBConnection() + if (consts.global.apiKey) { + makeDBConnection() + } }, []) // load contracts effects only if not paused diff --git a/src/api/database.ts b/src/api/database.ts index 471219c..de66f4c 100644 --- a/src/api/database.ts +++ b/src/api/database.ts @@ -1,21 +1,18 @@ import userbase from 'userbase-js' export class DB { + projectId: string + constructor({ appId, projectId }) { this.projectId = projectId userbase.init({ appId }) } - // async init(): Promise { - // return this.userbase.init({ appId: this.appId }) - // } - async signUp(details): Promise { return userbase.signUp(details) } async signIn(details): Promise { - console.log('details', details) return userbase.signIn({ ...details }) } From dbbb922874cfb79a1655ac92b2e7b5de164a86ea Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 15 Jun 2020 15:56:18 -0400 Subject: [PATCH 09/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20=20truncating?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ProvidersWrapper.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index f72530a..a3518d0 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -31,8 +31,7 @@ export const ProvidersWrapper: React.FC = () => { useEffect(() => { const makeDBConnection = async () => { - const db = await new DB({ appId: process.env.REACT_APP_USERBASE_APP_ID, projectId: consts.global.apiKey }) - setDB(db) + setDB(await new DB({ appId: process.env.REACT_APP_USERBASE_APP_ID, projectId: consts.global.apiKey })) } if (consts.global.apiKey) { makeDBConnection() From c27c04cb40200776d8c116fe1f034db99d273c10 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Tue, 16 Jun 2020 14:48:06 -0400 Subject: [PATCH 10/23] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20remove=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ProvidersWrapper.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index a3518d0..cf7e3aa 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -97,7 +97,7 @@ export const ProvidersWrapper: React.FC = () => { - + {/* */} Date: Tue, 16 Jun 2020 15:02:39 -0400 Subject: [PATCH 11/23] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/dappHero.ts | 18 +++++++++--------- src/components/userBase/UserBase.tsx | 14 +++++++------- src/protocol/ethereum/nft/useRenderNfts.tsx | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/api/dappHero.ts b/src/api/dappHero.ts index 99b62e1..666b8c2 100644 --- a/src/api/dappHero.ts +++ b/src/api/dappHero.ts @@ -65,15 +65,15 @@ export const getContractsByProjectKeyDappHero = async (projectId) => { } } -const compareResponses = async (originalOutput, projectId) => { - const compareOutput = await getContractsByProjectKeyV2(projectId) - const isEqual = !!(JSON.stringify(originalOutput) === JSON.stringify(compareOutput)) - // logger.info(`Cache Check isEqual: ${isEqual.toString()}`) - if (!isEqual) { - logger.info('', compareOutput) - logger.info('', originalOutput) - } -} +// const compareResponses = async (originalOutput, projectId) => { +// const compareOutput = await getContractsByProjectKeyV2(projectId) +// const isEqual = !!(JSON.stringify(originalOutput) === JSON.stringify(compareOutput)) +// // logger.info(`Cache Check isEqual: ${isEqual.toString()}`) +// if (!isEqual) { +// logger.info('', compareOutput) +// logger.info('', originalOutput) +// } +// } export const getContractsByProjectKeyBubble = async (projectId) => { logger.log(`projectId: ${projectId}`) diff --git a/src/components/userBase/UserBase.tsx b/src/components/userBase/UserBase.tsx index 12574f1..c2cac4d 100644 --- a/src/components/userBase/UserBase.tsx +++ b/src/components/userBase/UserBase.tsx @@ -28,13 +28,13 @@ export const UserBase = ({ db }) => { setIsOpen(false) } - useEffect(() => { - if (window.dappHero) { - // window.dappHero.db = db - window.dappHero.openModal = openModal - window.dappHero.closeModal = closeModal - } - }, [ window.dappHero, db ]) + // useEffect(() => { + // if (window.dappHero) { + // // window.dappHero.db = db + // window.dappHero.openModal = openModal + // window.dappHero.closeModal = closeModal + // } + // }, [ window.dappHero, db ]) return (
diff --git a/src/protocol/ethereum/nft/useRenderNfts.tsx b/src/protocol/ethereum/nft/useRenderNfts.tsx index 9018279..7400293 100644 --- a/src/protocol/ethereum/nft/useRenderNfts.tsx +++ b/src/protocol/ethereum/nft/useRenderNfts.tsx @@ -125,7 +125,7 @@ export const useRenderNfts = ({ nfts, item, element, getAssetElements }) => { 'data-dh-property-method-id', 'data-dh-property-asset-contract-address' ] // Replace the Inner text for any element type. - Array.from(item.root.children).forEach((element) => { + Array.from(item.root.children).forEach((element: HTMLElement) => { displayKeyValueElementInnerText(clonedItem, '$THIS_TokenID', nft?.token_id, element.nodeName) displayKeyValueElementInnerText(clonedItem, '$THIS_ContractAddress', nft?.asset_contract.address, element.nodeName) displayKeyValueElementInnerText(clonedItem, '$THIS_OwnerAddress', nft?.owner.address, element.nodeName) @@ -134,7 +134,7 @@ export const useRenderNfts = ({ nfts, item, element, getAssetElements }) => { // TODO: Add recursion to get inner children elements // Substitute the $THIS value on any attribute from array above, for any child element. - Array.from(item.root.children).forEach((element) => { + Array.from(item.root.children).forEach((element: HTMLElement) => { attributes.forEach((attribute) => { displayValueOnElementAttribute(clonedItem, '$THIS_TokenID', nft?.token_id, attribute) displayValueOnElementAttribute(clonedItem, '$THIS_ContractAddress', nft?.asset_contract.address, attribute) From eed2ee6324e8ffdf3130d1190530802c480e47c2 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Tue, 16 Jun 2020 16:11:53 -0400 Subject: [PATCH 12/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20=20HTML=20for=20add?= =?UTF-8?q?ing=20a=20contract=20dynamically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 751 ++++++++++++++++++++------------------- src/ProvidersWrapper.tsx | 1 + src/api/dappHero.ts | 1 + 3 files changed, 397 insertions(+), 356 deletions(-) diff --git a/public/index.html b/public/index.html index ef895ce..c528e15 100644 --- a/public/index.html +++ b/public/index.html @@ -31,7 +31,7 @@ -

amusing-miss-97

+

Perfect-edmund-58

Powered by DappHero.io @@ -48,206 +48,56 @@

amusing-miss-97

+
-

MaticWrappedEth

+

TokenFactory---Mainnet

Public Methods

-

Method "name"

-
- -
-
-
- , -
-
-

Method "totalSupply"

-
- -
-
-
- , -
-
-

Method "decimals"

-
- -
-
-
- , -
-
-

Method "balanceOf"

+

Method "createdContracts"

-
-
-
- , -
-
-

Method "symbol"

-
- -
-
-
- , -
-
-

Method "allowance"

-
-
@@ -261,214 +111,47 @@

Method "allowance"

-

Method "approve"

+

Method "createToken"

-
-
-
- , -
-
-

Method "transferFrom"

-
- -
-
-
- , -
-
-

Method "withdraw"

-
- -
-
-
- , -
-
-

Method "transfer"

-
- -
-
-
- , -
-
-

Method "deposit"

-
-
@@ -479,7 +162,7 @@

Method "deposit"

diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index cf7e3aa..8457cec 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -16,6 +16,7 @@ import { DB } from './api/database' export const ProvidersWrapper: React.FC = () => { // react hooks const [ configuration, setConfig ] = useState(null) + console.log('ProvidersWrapper:React.FC -> configuration', configuration) const [ domElements, setDomElements ] = useState(null) const [ timestamp, setTimestamp ] = useState(+new Date()) const [ supportedNetworks, setSupportedNetworks ] = useState([]) diff --git a/src/api/dappHero.ts b/src/api/dappHero.ts index 666b8c2..29f1ab9 100644 --- a/src/api/dappHero.ts +++ b/src/api/dappHero.ts @@ -114,6 +114,7 @@ export const getContractsByProjectKey = async (projectId) => { // first try our cache server try { + return (await getContractsByProjectKeyBubble(projectId)) return (await getContractsByProjectKeyDappHero(projectId)) } catch (error) { // If the error fails, then try bubble From ffa1cd7a96cd5caddf9d73d210a072b66062c0b5 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Tue, 16 Jun 2020 17:24:28 -0400 Subject: [PATCH 13/23] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Fix=20support=20for?= =?UTF-8?q?=20multiple=20contracts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index-dynamicContracts.html | 555 +++++++ public/index.html | 1315 ++++++++++++----- src/ProvidersWrapper.tsx | 1 - .../ethereum/customContract/Manager.tsx | 35 +- .../ethereum/customContract/Router.tsx | 3 - 5 files changed, 1517 insertions(+), 392 deletions(-) create mode 100644 public/index-dynamicContracts.html diff --git a/public/index-dynamicContracts.html b/public/index-dynamicContracts.html new file mode 100644 index 0000000..c528e15 --- /dev/null +++ b/public/index-dynamicContracts.html @@ -0,0 +1,555 @@ + + + + + DappHero HTML Generation + + + + + + + + + +
+ +

Perfect-edmund-58

+

+ + Powered by DappHero.io + +

+

+ This is a description of what you are trying to do with your project. + Edit it so you have something snazzy! +

+
+

+ +

+
+
+
+

TokenFactory---Mainnet

+
+
+

Public Methods

+
+
+

Method "createdContracts"

+
+ +
+
+
+
+
+
+
+

Transaction Methods

+
+
+

Method "createToken"

+
+ +
+
+
+
+
+
+ + + + + + diff --git a/public/index.html b/public/index.html index c528e15..8af975c 100644 --- a/public/index.html +++ b/public/index.html @@ -31,7 +31,7 @@ -

Perfect-edmund-58

+

Token Factory

Powered by DappHero.io @@ -48,7 +48,6 @@

Perfect-edmund-58

-

TokenFactory---Mainnet

@@ -57,7 +56,7 @@

Perfect-edmund-58

Method "createdContracts"
Output...
Output...
Output...
@@ -95,7 +94,7 @@

Method "createdContracts"

@@ -111,7 +110,7 @@

Method "createdContracts"

Method "createToken" @@ -133,7 +132,7 @@

Method "createToken"

@@ -142,14 +141,14 @@

Method "createToken"

@@ -160,6 +159,932 @@

Method "createToken"

+
+

Sample-ERC20

+
+
+

Public Methods

+
+
+

Method "allowance"

+
+ +
+
+
+ , +
+
+

Method "balanceOf"

+
+ +
+
+
+ , +
+
+

Method "decimals"

+
+ +
+
+
+ , +
+
+

Method "name"

+
+ +
+
+
+ , +
+
+

Method "symbol"

+
+ +
+
+
+ , +
+
+

Method "totalSupply"

+
+ +
+
+
+
+
+
+
+

Transaction Methods

+
+
+

Method "approve"

+
+ +
+
+
+ , +
+
+

Method "decreaseAllowance"

+
+ +
+
+
+ , +
+
+

Method "increaseAllowance"

+
+ +
+
+
+ , +
+
+

Method "transfer"

+
+ +
+
+
+ , +
+
+

Method "transferFrom"

+
+ +
+
+
+
+
+
+
+

DH-Test-Rinkeby

+
+
+

Public Methods

+
+
+

Method "hello"

+
+ +
+
+
+ , +
+
+

Method "viewMultipleArgsMultipleReturn"

+
+ +
+
+
+ , +
+
+

Method "viewMultipleArgsSingleReturn"

+
+ +
+
+
+ , +
+
+

Method "viewNoArgsMultipleReturn"

+
+ +
+
+
+ , +
+
+

Method "important"

+
+ +
+
+
+ , +
+
+

Method "owner"

+
+ +
+
+
+
+
+
+
+

Transaction Methods

+
+
+

Method "sendMinimumTwoEthNoArgs"

+
+ +
+
+
+ , +
+
+

Method "makeTxNoArgs"

+
+ +
+
+
+ , +
+
+

Method "sendEthWithArgs"

+
+ +
+
+
+ , +
+
+

Method "makeTxWithArgs"

+
+ +
+
+
+ , +
+
+

Method "sendEthNoArgs"

+
+ +
+
+
+ , +
+
+

Method "sendMinimumTwoEthWithArgs"

+
+ +
+
+
+ , +
+
+

Method "triggerEvent"

+
+ +
+
+
+
+
+
diff --git a/src/ProvidersWrapper.tsx b/src/ProvidersWrapper.tsx index 8457cec..cf7e3aa 100644 --- a/src/ProvidersWrapper.tsx +++ b/src/ProvidersWrapper.tsx @@ -16,7 +16,6 @@ import { DB } from './api/database' export const ProvidersWrapper: React.FC = () => { // react hooks const [ configuration, setConfig ] = useState(null) - console.log('ProvidersWrapper:React.FC -> configuration', configuration) const [ domElements, setDomElements ] = useState(null) const [ timestamp, setTimestamp ] = useState(+new Date()) const [ supportedNetworks, setSupportedNetworks ] = useState([]) diff --git a/src/protocol/ethereum/customContract/Manager.tsx b/src/protocol/ethereum/customContract/Manager.tsx index b3a044f..c480754 100644 --- a/src/protocol/ethereum/customContract/Manager.tsx +++ b/src/protocol/ethereum/customContract/Manager.tsx @@ -22,19 +22,24 @@ export const Manager: React.FunctionComponent = ({ customContractE // TODO: [DEV-318] Create a function to add a new contract name and add a new configuration - for (const contractName of uniqueContractNames) { - - const newDomElements = getDomElements(configuration) - const contractElements = newDomElements.filter((element) => element.feature === 'customContract') - const methodsByContractAsElements = contractElements.filter((element) => element.contract.contractName === contractName) - const contract = configuration.contracts.filter((thisContract) => (thisContract.contractName === contractName))[0] - - return ( - - ) - } + // for (const contractName of uniqueContractNames) + return ( + <> + {Array.from(uniqueContractNames).map((contractName) => { + const newDomElements = getDomElements(configuration) + const contractElements = newDomElements.filter((element) => element.feature === 'customContract') + const methodsByContractAsElements = contractElements.filter((element) => element.contract.contractName === contractName) + const contract = configuration.contracts.filter((thisContract) => (thisContract.contractName === contractName))[0] + + return ( + + ) + })} + + ) } diff --git a/src/protocol/ethereum/customContract/Router.tsx b/src/protocol/ethereum/customContract/Router.tsx index ed83c7c..4347771 100644 --- a/src/protocol/ethereum/customContract/Router.tsx +++ b/src/protocol/ethereum/customContract/Router.tsx @@ -25,7 +25,6 @@ type RouterProps = { } export const Router: React.FunctionComponent = ({ listOfContractMethods, contract, timestamp }) => { - const ethereum = useContext(contexts.EthereumContext) const { signer, isEnabled: writeEnabled, chainId: writeChainId, provider } = ethereum const { contractAddress, contractAbi, networkId } = contract @@ -47,10 +46,8 @@ export const Router: React.FunctionComponent = ({ listOfContractMet let readContractInstance = null // Make the contract instance from either the local provider or remote provider if (provider && contractNetwork === provider?._network?.name) { - console.log('Using local provider for contract reads.') readContractInstance = new ethers.Contract(contractAddress, contractAbi, provider) } else { - console.log('Using DH-backend provider for contract reads.') readContractInstance = new ethers.Contract(contractAddress, contractAbi, stableReadProvider) } readContractInstance.on('*', (data) => emitToEvent( From 7966763b19ec7094ffe7f930d24fe75b50a19425 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Tue, 16 Jun 2020 17:33:40 -0400 Subject: [PATCH 14/23] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20Fix=20multiple?= =?UTF-8?q?=20Contracts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index-stanard.html | 2 +- public/index.html | 1935 ++++++++++++++++--------------------- 2 files changed, 829 insertions(+), 1108 deletions(-) diff --git a/public/index-stanard.html b/public/index-stanard.html index 8cadef0..4a1da82 100644 --- a/public/index-stanard.html +++ b/public/index-stanard.html @@ -838,7 +838,7 @@

src="" type="text/javascript" id="dh-apiKey" - data-api="1581368358384x830713010847744000" + data-api="1592342853928x247583279535882240" > diff --git a/public/index.html b/public/index.html index 8af975c..4a1da82 100644 --- a/public/index.html +++ b/public/index.html @@ -1,1124 +1,845 @@ - - + + + - DappHero HTML Generation - - - - - - + + DappHero: Components + + - -
- -

Token Factory

-

- - Powered by DappHero.io - -

-

- This is a description of what you are trying to do with your project. - Edit it so you have something snazzy! -

-
-

-

+ +
+ + + -

- -
-

TokenFactory---Mainnet

-
-
-

Public Methods

-
-
-

Method "createdContracts"

-
- -
-
-
-
-
-
-
-

Transaction Methods

-
-
-

Method "createToken"

-
- -
-
-
-
-
+ +
+ *Return value: -* +
+
+ +
+ + + + + +
Method: "sendEthWithArgs"
+
Payable: true - StateMutability: "payable"
+
ETH Value: User Input
+
+

Inputs

+
    +
  • message - bytes32
  • +
+ +

Outputs

+
    +
  • none
  • +
+
+ +
This is the method
+ + + + + + + +
+ *Return value: -* +
+ + +
+ + + + + + + + +
Method: "viewMultipleArgsMultipleReturn"
+
Payable: false - StateMutability: "view"
+
+

Inputs

+
    +
  • from - address
  • +
  • multiplier - uint256
  • +
+ +

Outputs

+
    +
  • _balanceMultiplied - uint256
  • +
  • _hello - bytes32
  • +
+
+ +
+ + + + + +
+ *Return value: -* +
+
+ + + + + +
Method: "sendVariableEthNoArgs"
+
Payable: true - StateMutability: "payable"
+
No eth is sent here.
+
+

Inputs

+
    +
  • none
  • +
+ +

Outputs

+
    +
  • none
  • +
+ > + +
+ + +
+ *Return value: -* +
+
+ +
+ + +
Method: "viewMultipleArgsSingleReturn"
+
Payable: false - StateMutability: "view"
+
+

Inputs

+
    +
  • fromAddress - address
  • +
  • amount - uint256
  • +
+ +

Outputs

+
    +
  • longInteger - uint256 : (Should be: 8989898989)
  • +
+
+ +
+ + + + + + +
+ *Return value: -* +
+
+ +
+ + +
Method: "viewNoArgsMultipleReturn"
+
Payable: false - StateMutability: "view"
+
+

Inputs

+
    +
  • none
  • +
+ +

Outputs

+
    +
  • importantNumber - uint256 (should be zero)
  • +
  • hello - bytes32
  • +
+
+ +
+ --> + + All the args are returned in one, and in their respective output +
+ A greeting here in bytes32 +
+
+ A greeting here in bytes32 +
+ +
Important Number here
+ +
+ *Return value: -* +
+
+ *Return value: -* +
+
+ +
+ + + + + + + + + + + + + + + + + + + + +
ERC721 - Single NFT from an Owner
+
With Owner Account address and Token id
+ +
+
+
+ +
+

+
+ $THIS_TokenID +
-
-

Sample-ERC20

-
-
-

Public Methods

-
-
-

Method "allowance"

-
- -
-
-
- , -
-
-

Method "balanceOf"

-
- -
-
-
- , -
-
-

Method "decimals"

-
- -
-
-
- , -
-
-

Method "name"

-
- -
-
-
- , -
-
-

Method "symbol"

-
- -
-
-
- , -
-
-

Method "totalSupply"

-
- -
-
-
-
-
-
-
-

Transaction Methods

-
-
-

Method "approve"

-
- -
-
-
- , -
-
-

Method "decreaseAllowance"

-
- -
-
-
- , -
-
-

Method "increaseAllowance"

-
- -
-
-
- , -
-
-

Method "transfer"

-
- -
-
-
- , -
-
-

Method "transferFrom"

-
- -
-
-
-
-
+ +
+ +
+ + + +
ERC721 - List of specific NFTs from an Owner
+
With Owner Account address and Token ids
+ +
+
+ +

+
+
+ +
+ + + +
ERC721 - List of NFTs from an Owner
+
With Owner Account address
+ +
+
+ +

+
+
+ +
+ + +
ERC721 - List of NFTs from an Owner with Pagination
+
With Owner Account address
+ +
+ + + +
+ +

+
+ +
+ + +
ERC721 - Single NFT from an Contract
+
With Asset contract address
+ +
+
+ +

+
+
+ +
+ + +
ERC721 - List of NFTs from an Contract
+
With Asset contract address
+ +
+
+ +

+
+
+ +
+ + +
ERC721 - List of NFTs from an Contract
+
With Asset contract address
+ +
+
+ +

+
+
+ +
+ +
-

DH-Test-Rinkeby

-
-
-

Public Methods

-
-
-

Method "hello"

-
- -
-
-
- , -
-
-

Method "viewMultipleArgsMultipleReturn"

-
- -
-
-
- , -
-
-

Method "viewMultipleArgsSingleReturn"

-
- -
-
-
- , -
-
-

Method "viewNoArgsMultipleReturn"

-
- -
-
-
- , -
-
-

Method "important"

-
- -
-
-
- , -
-
-

Method "owner"

-
- -
-
-
-
-
-
-
-

Transaction Methods

-
-
-

Method "sendMinimumTwoEthNoArgs"

-
- -
-
-
- , -
-
-

Method "makeTxNoArgs"

-
- -
-
-
- , -
-
-

Method "sendEthWithArgs"

-
- -
-
-
- , -
-
-

Method "makeTxWithArgs"

-
- -
-
-
- , -
-
-

Method "sendEthNoArgs"

-
- -
-
-
- , -
-
-

Method "sendMinimumTwoEthWithArgs"

-
- -
-
-
- , -
-
-

Method "triggerEvent"

-
- -
-
-
-
-
+
+ + + - - - + From 6456a89b6610dc48d34338fe49f0b88eb2989bb2 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 11:54:53 -0400 Subject: [PATCH 15/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Add=20listener=20fo?= =?UTF-8?q?r=20User=20Address?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 20 ++++++++++++++++++- src/Activator.tsx | 2 ++ src/protocol/ethereum/user/EthUserAddress.tsx | 11 ++++++++++ src/providers/EmitterProvider/constants.ts | 4 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index 4a1da82..f67dc79 100644 --- a/public/index.html +++ b/public/index.html @@ -834,11 +834,29 @@

crossorigin="anonymous" > --> + + diff --git a/src/Activator.tsx b/src/Activator.tsx index 70397fc..b1dd4f7 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -78,6 +78,8 @@ export const Activator: React.FC = ({ listenToTransactionStatusChange: (cb): void => listenToEvent(EVENT_NAMES.contract.statusChange, cb), listenToContractInvokeTriggerChange: (cb): void => listenToEvent(EVENT_NAMES.contract.invokeTrigger, cb), listenToSmartContractBlockchainEvent: (cb): void => listenToEvent(EVENT_NAMES.contract.contractEvent, cb), + listenToUserAddressChange: (cb): void => listenToEvent(EVENT_NAMES.user.addressStatusChange, cb), + listenToUserBalanceChange: (cb): void => listenToEvent(EVENT_NAMES.user.balanceStatusChange, cb), } Object.assign(window, { dappHero }) diff --git a/src/protocol/ethereum/user/EthUserAddress.tsx b/src/protocol/ethereum/user/EthUserAddress.tsx index ca2ce8d..35ce3ce 100644 --- a/src/protocol/ethereum/user/EthUserAddress.tsx +++ b/src/protocol/ethereum/user/EthUserAddress.tsx @@ -2,6 +2,8 @@ import { useEffect, FunctionComponent, useContext, useMemo } from 'react' import * as contexts from 'contexts' import { logger } from 'logger/customLogger' +import { EmitterContext } from 'providers/EmitterProvider/context' +import { EVENT_NAMES, EVENT_STATUS } from 'providers/EmitterProvider/constants' interface EthUserAddressProps { element: HTMLElement; @@ -10,6 +12,8 @@ interface EthUserAddressProps { export const EthUserAddress: FunctionComponent = ({ element, displayFormat }) => { const ethereum = useContext(contexts.EthereumContext) + const { actions: { emitToEvent } } = useContext(EmitterContext) + const { address, isEnabled } = ethereum const memoizedValue = useMemo( @@ -17,6 +21,13 @@ export const EthUserAddress: FunctionComponent = ({ element , [], ) + useEffect(() => { + emitToEvent( + EVENT_NAMES.user.addressStatusChange, + { value: address, step: 'User address value change', status: EVENT_STATUS.resolved }, + ) + }, [ address, isEnabled ]) + useEffect(() => { try { if (address && isEnabled) { diff --git a/src/providers/EmitterProvider/constants.ts b/src/providers/EmitterProvider/constants.ts index 64cfc9b..1b648fc 100644 --- a/src/providers/EmitterProvider/constants.ts +++ b/src/providers/EmitterProvider/constants.ts @@ -6,6 +6,10 @@ export const EVENT_NAMES = { invokeTrigger: 'contract:invokeTriggerChange', contractEvent: 'contract:contractEvent', }, + user: { + addressStatusChange: 'address:statusChange', + balanceStatusChange: 'balance:statusChange', + }, } export const EVENT_STATUS = { pending: 'PENDING', resolved: 'RESOLVED', rejected: 'REJECTED' } From 9e56907a667cc58d3f814dc6f49e6c5f970ffc8d Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 12:46:01 -0400 Subject: [PATCH 16/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Add=20event=20f?= =?UTF-8?q?or=20Balance=20Change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 6 +-- src/protocol/ethereum/user/EthUserBalance.tsx | 46 +++++++++++++++++-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index f67dc79..8458b8b 100644 --- a/public/index.html +++ b/public/index.html @@ -842,8 +842,8 @@

console.log("It's loaded"); console.log("dapphero: ", dappHero) - dappHero.listenToUserAddressChange(data => { - console.log("Listening to address change", data); + dappHero.listenToUserBalanceChange(data => { + console.log("Listening to balance change", data); }); // dappHero.listenToSmartContractBlockchainEvent(data => { // console.log("The blockChain Events: ", data) @@ -856,7 +856,7 @@

src="" type="text/javascript" id="dh-apiKey" - data-api="" + data-api="1592342853928x247583279535882240" > diff --git a/src/protocol/ethereum/user/EthUserBalance.tsx b/src/protocol/ethereum/user/EthUserBalance.tsx index 14f3375..c4343a4 100644 --- a/src/protocol/ethereum/user/EthUserBalance.tsx +++ b/src/protocol/ethereum/user/EthUserBalance.tsx @@ -1,7 +1,9 @@ import { logger } from 'logger/customLogger' -import { useEffect, useState, useContext, FunctionComponent, useMemo } from 'react' +import { useEffect, useState, useContext, FunctionComponent, useMemo, useRef } from 'react' import { useInterval } from 'beautiful-react-hooks' import { EthereumUnits } from 'types/types' +import { EmitterContext } from 'providers/EmitterProvider/context' +import { EVENT_NAMES, EVENT_STATUS } from 'providers/EmitterProvider/constants' import { useNetworkStatus } from 'react-adaptive-hooks/network' import * as utils from 'utils' import * as contexts from 'contexts' @@ -14,11 +16,34 @@ interface EthUserBalanceProps { } export const EthUserBalance: FunctionComponent = ({ element, units, decimals }) => { + + const { actions: { emitToEvent } } = useContext(EmitterContext) + const memoizedValue = useMemo( () => element.innerText , [], ) + // // Hook + const useMemoCompare = (value, compare) => { + // Ref for storing previous value + const previousRef = useRef() + const previous = previousRef.current + + // Pass previous and new value to compare function + const isEqual = compare(previous, value) + + // If not equal update previous to new value (for next render) + // and then return new new value below. + useEffect(() => { + if (!isEqual) { + previousRef.current = value + } + }) + + return isEqual ? previous : value + } + const initialEffectiveConnectionType = '4g' const { effectiveConnectionType } = useNetworkStatus(initialEffectiveConnectionType) units = units ?? 'wei' //eslint-disable-line @@ -29,17 +54,21 @@ export const EthUserBalance: FunctionComponent = ({ element const [ balance, setBalance ] = useState(null) + const emitBalanceValue = useMemoCompare(balance, (prev) => prev && prev._hex === balance._hex) + // TODO: [DEV-264] Feature: NotifyJS for UserBalance polling const poll = async () => { try { - const balance = await provider.getBalance(address) - setBalance(balance) + const newBalance = await provider.getBalance(address) + setBalance(newBalance) } catch (error) { logger.log(`Error getting balance: ${error}`) } } - if (address && isEnabled) poll() + useEffect(() => { + if (address && isEnabled) poll() + }, []) useInterval(() => { if (address && isEnabled) poll() @@ -58,5 +87,14 @@ export const EthUserBalance: FunctionComponent = ({ element if (address && isEnabled && balance) { getBalance() } else { element.innerHTML = memoizedValue } }, [ address, isEnabled, balance ]) + useEffect(() => { + + emitToEvent( + EVENT_NAMES.user.balanceStatusChange, + { value: balance?.toString(), step: 'User balance value change', status: EVENT_STATUS.resolved }, + ) + + }, [ emitBalanceValue ]) + return null } From 5031f015f2871246b8b413c5d18bba354533ca05 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 12:59:49 -0400 Subject: [PATCH 17/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Add=20event=20l?= =?UTF-8?q?istenin=20for=20NFT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 4 +-- src/Activator.tsx | 3 ++ .../nft/useGetTokensForContractAddress.tsx | 30 ++++++++++++++++--- src/providers/EmitterProvider/constants.ts | 5 ++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/public/index.html b/public/index.html index 8458b8b..7029ec4 100644 --- a/public/index.html +++ b/public/index.html @@ -842,8 +842,8 @@

console.log("It's loaded"); console.log("dapphero: ", dappHero) - dappHero.listenToUserBalanceChange(data => { - console.log("Listening to balance change", data); + dappHero.listenToNFTLoadAllToken(data => { + console.log("Listening to change", data.value); }); // dappHero.listenToSmartContractBlockchainEvent(data => { // console.log("The blockChain Events: ", data) diff --git a/src/Activator.tsx b/src/Activator.tsx index b1dd4f7..4f244b7 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -80,6 +80,9 @@ export const Activator: React.FC = ({ listenToSmartContractBlockchainEvent: (cb): void => listenToEvent(EVENT_NAMES.contract.contractEvent, cb), listenToUserAddressChange: (cb): void => listenToEvent(EVENT_NAMES.user.addressStatusChange, cb), listenToUserBalanceChange: (cb): void => listenToEvent(EVENT_NAMES.user.balanceStatusChange, cb), + listenToNFTLoadSingleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadSingleToken, cb), + listenToNFTLoadMultipleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadMultipleTokens, cb), + listenToNFTLoadAllToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadAllTokens, cb), } Object.assign(window, { dappHero }) diff --git a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx index 2eb8680..f096eaa 100644 --- a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx +++ b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx @@ -1,10 +1,14 @@ -import { useEffect, useState } from 'react' +import { useEffect, useState, useContext } from 'react' +import { EmitterContext } from 'providers/EmitterProvider/context' +import { EVENT_NAMES, EVENT_STATUS } from 'providers/EmitterProvider/constants' import { openSeaApi } from './api' export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens, isAllTokens, parsedTokens, assetContractAddress, assetOwnerAddress, limit, offset, tokens }) => { const [ nfts, setNfts ] = useState(null) const [ error, setError ] = useState(null) + const { actions: { emitToEvent } } = useContext(EmitterContext) + useEffect(() => { if (assetOwnerAddress || !assetContractAddress) return @@ -15,7 +19,13 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens openSeaApi.contract .getSingleAsset({ assetContractAddress, token }) - .then(setNfts) + .then((nfts) => { + emitToEvent( + EVENT_NAMES.nft.loadSingleToken, + { value: nfts, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setNfts(nfts) + }) .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) } @@ -25,7 +35,13 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens openSeaApi.contract .getMultipleAssets({ assetContractAddress, tokens, limit, offset }) - .then(setNfts) + .then((nfts) => { + emitToEvent( + EVENT_NAMES.nft.loadMultipleTokens, + { value: nfts, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setNfts(nfts) + }) .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) } @@ -35,7 +51,13 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens openSeaApi.contract .getAllAssets({ assetContractAddress, limit, offset }) - .then(setNfts) + .then((nfts) => { + emitToEvent( + EVENT_NAMES.nft.loadAllTokens, + { value: nfts, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setNfts(nfts) + }) .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) } }, [ assetContractAddress, offset ]) diff --git a/src/providers/EmitterProvider/constants.ts b/src/providers/EmitterProvider/constants.ts index 1b648fc..d9068ab 100644 --- a/src/providers/EmitterProvider/constants.ts +++ b/src/providers/EmitterProvider/constants.ts @@ -10,6 +10,11 @@ export const EVENT_NAMES = { addressStatusChange: 'address:statusChange', balanceStatusChange: 'balance:statusChange', }, + nft: { + loadSingleToken: 'nft:loadSingleToken', + loadMultipleTokens: 'nft:loadMultipleTokens', + loadAllTokens: 'nft:loadAllTokens', + }, } export const EVENT_STATUS = { pending: 'PENDING', resolved: 'RESOLVED', rejected: 'REJECTED' } From 6c4c86fe4c3fddbbf4ccac71134d7034beef23f4 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 13:01:35 -0400 Subject: [PATCH 18/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20=20add=20more=20cov?= =?UTF-8?q?erage=20for=20NFT=20events.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ethereum/nft/useGetTokensFromOwner.tsx | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx index cd5e17e..101af5a 100644 --- a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx +++ b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx @@ -1,10 +1,14 @@ -import { useEffect, useState } from 'react' +import { useEffect, useState, useContext } from 'react' +import { EmitterContext } from 'providers/EmitterProvider/context' +import { EVENT_NAMES, EVENT_STATUS } from 'providers/EmitterProvider/constants' import { openSeaApi } from './api' export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTokens, isSingleToken, isMultipleTokens, assetContractAddress, tokens, limit, offset }) => { const [ nfts, setNfts ] = useState(null) const [ error, setError ] = useState(null) + const { actions: { emitToEvent } } = useContext(EmitterContext) + useEffect(() => { if (!assetOwnerAddress) return @@ -15,7 +19,13 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo openSeaApi.owner .getSingleAsset({ assetOwnerAddress, assetContractAddress, token }) - .then(setNfts) + .then((nfts) => { + emitToEvent( + EVENT_NAMES.nft.loadSingleToken, + { value: nfts, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setNfts(nfts) + }) .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) } @@ -25,7 +35,13 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo openSeaApi.owner .getMultipleAssets({ assetOwnerAddress, assetContractAddress, tokens, limit, offset }) - .then(setNfts) + .then((nfts) => { + emitToEvent( + EVENT_NAMES.nft.loadMultipleTokens, + { value: nfts, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setNfts(nfts) + }) .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) } @@ -35,7 +51,13 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo openSeaApi.owner .getAllAssets({ assetOwnerAddress, assetContractAddress, limit, offset }) - .then(setNfts) + .then((nfts) => { + emitToEvent( + EVENT_NAMES.nft.loadAllTokens, + { value: nfts, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setNfts(nfts) + }) .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) } }, [ assetOwnerAddress, offset ]) From 40dd56131c5bf7b176f0264f090eb675539e44ed Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 13:05:03 -0400 Subject: [PATCH 19/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Catch=20and=20e?= =?UTF-8?q?mit=20nft=20Load=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Activator.tsx | 1 + .../nft/useGetTokensForContractAddress.tsx | 24 ++++++++++++++++--- .../ethereum/nft/useGetTokensFromOwner.tsx | 24 ++++++++++++++++--- src/providers/EmitterProvider/constants.ts | 1 + 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/Activator.tsx b/src/Activator.tsx index 4f244b7..538b6e7 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -83,6 +83,7 @@ export const Activator: React.FC = ({ listenToNFTLoadSingleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadSingleToken, cb), listenToNFTLoadMultipleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadMultipleTokens, cb), listenToNFTLoadAllToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadAllTokens, cb), + listenToNFTLoadError: (cb): void => listenToEvent(EVENT_NAMES.nft.loadError, cb), } Object.assign(window, { dappHero }) diff --git a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx index f096eaa..a918f14 100644 --- a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx +++ b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx @@ -26,7 +26,13 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens ) setNfts(nfts) }) - .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) + .catch((error) => { + emitToEvent( + EVENT_NAMES.nft.loadError, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setError({ simpleErrorMessage, completeErrorMessage, error }) + }) } if (isMultipleTokens) { @@ -42,7 +48,13 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens ) setNfts(nfts) }) - .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) + .catch((error) => { + emitToEvent( + EVENT_NAMES.nft.loadError, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setError({ simpleErrorMessage, completeErrorMessage, error }) + }) } if (isAllTokens) { @@ -58,7 +70,13 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens ) setNfts(nfts) }) - .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) + .catch((error) => { + emitToEvent( + EVENT_NAMES.nft.loadError, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setError({ simpleErrorMessage, completeErrorMessage, error }) + }) } }, [ assetContractAddress, offset ]) diff --git a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx index 101af5a..aa98605 100644 --- a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx +++ b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx @@ -26,7 +26,13 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo ) setNfts(nfts) }) - .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) + .catch((error) => { + emitToEvent( + EVENT_NAMES.nft.loadError, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setError({ simpleErrorMessage, completeErrorMessage, error }) + }) } if (isMultipleTokens) { @@ -42,7 +48,13 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo ) setNfts(nfts) }) - .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) + .catch((error) => { + emitToEvent( + EVENT_NAMES.nft.loadError, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setError({ simpleErrorMessage, completeErrorMessage, error }) + }) } if (isAllTokens) { @@ -58,7 +70,13 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo ) setNfts(nfts) }) - .catch((error) => setError({ simpleErrorMessage, completeErrorMessage, error })) + .catch((error) => { + emitToEvent( + EVENT_NAMES.nft.loadError, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + ) + setError({ simpleErrorMessage, completeErrorMessage, error }) + }) } }, [ assetOwnerAddress, offset ]) diff --git a/src/providers/EmitterProvider/constants.ts b/src/providers/EmitterProvider/constants.ts index d9068ab..cb41d62 100644 --- a/src/providers/EmitterProvider/constants.ts +++ b/src/providers/EmitterProvider/constants.ts @@ -14,6 +14,7 @@ export const EVENT_NAMES = { loadSingleToken: 'nft:loadSingleToken', loadMultipleTokens: 'nft:loadMultipleTokens', loadAllTokens: 'nft:loadAllTokens', + loadError: 'nft:loadTokenError', }, } From f4b757aa2078f26efaca4aebc1d9485188b2bf0f Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 13:06:16 -0400 Subject: [PATCH 20/23] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20Catch=20and=20em?= =?UTF-8?q?it=20NFT=20load=20Errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ethereum/nft/useGetTokensForContractAddress.tsx | 6 +++--- src/protocol/ethereum/nft/useGetTokensFromOwner.tsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx index a918f14..38a7336 100644 --- a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx +++ b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx @@ -29,7 +29,7 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens .catch((error) => { emitToEvent( EVENT_NAMES.nft.loadError, - { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) }) @@ -51,7 +51,7 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens .catch((error) => { emitToEvent( EVENT_NAMES.nft.loadError, - { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) }) @@ -73,7 +73,7 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens .catch((error) => { emitToEvent( EVENT_NAMES.nft.loadError, - { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) }) diff --git a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx index aa98605..37a8349 100644 --- a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx +++ b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx @@ -29,7 +29,7 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo .catch((error) => { emitToEvent( EVENT_NAMES.nft.loadError, - { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) }) @@ -51,7 +51,7 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo .catch((error) => { emitToEvent( EVENT_NAMES.nft.loadError, - { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) }) @@ -73,7 +73,7 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo .catch((error) => { emitToEvent( EVENT_NAMES.nft.loadError, - { value: error, step: 'Load Single Token', status: EVENT_STATUS.resolved }, + { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) }) From 4acdfdabbd669ce5699936fd8cc425ff994214d3 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 13:13:57 -0400 Subject: [PATCH 21/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Refactor=20Even?= =?UTF-8?q?t=20for=20rejected=20+=203box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Activator.tsx | 2 +- .../nft/useGetTokensForContractAddress.tsx | 6 +++--- .../ethereum/nft/useGetTokensFromOwner.tsx | 6 +++--- src/protocol/ethereum/threeBox/Reducer.tsx | 17 +++++++++++++++++ src/providers/EmitterProvider/constants.ts | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Activator.tsx b/src/Activator.tsx index 538b6e7..19bd182 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -83,7 +83,7 @@ export const Activator: React.FC = ({ listenToNFTLoadSingleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadSingleToken, cb), listenToNFTLoadMultipleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadMultipleTokens, cb), listenToNFTLoadAllToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadAllTokens, cb), - listenToNFTLoadError: (cb): void => listenToEvent(EVENT_NAMES.nft.loadError, cb), + listenTo3BoxProfile: (cb): void => listenToEvent(EVENT_NAMES.threeBox.loadProfile, cb), } Object.assign(window, { dappHero }) diff --git a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx index 38a7336..39d7477 100644 --- a/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx +++ b/src/protocol/ethereum/nft/useGetTokensForContractAddress.tsx @@ -28,7 +28,7 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens }) .catch((error) => { emitToEvent( - EVENT_NAMES.nft.loadError, + EVENT_NAMES.nft.loadSingleToken, { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) @@ -50,7 +50,7 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens }) .catch((error) => { emitToEvent( - EVENT_NAMES.nft.loadError, + EVENT_NAMES.nft.loadMultipleTokens, { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) @@ -72,7 +72,7 @@ export const useGetTokensForContractAddress = ({ isSingleToken, isMultipleTokens }) .catch((error) => { emitToEvent( - EVENT_NAMES.nft.loadError, + EVENT_NAMES.nft.loadAllTokens, { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) diff --git a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx index 37a8349..96a17b8 100644 --- a/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx +++ b/src/protocol/ethereum/nft/useGetTokensFromOwner.tsx @@ -28,7 +28,7 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo }) .catch((error) => { emitToEvent( - EVENT_NAMES.nft.loadError, + EVENT_NAMES.nft.loadSingleToken, { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) @@ -50,7 +50,7 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo }) .catch((error) => { emitToEvent( - EVENT_NAMES.nft.loadError, + EVENT_NAMES.nft.loadMultipleTokens, { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) @@ -72,7 +72,7 @@ export const useGetTokensFromOwner = ({ assetOwnerAddress, isAllTokens, parsedTo }) .catch((error) => { emitToEvent( - EVENT_NAMES.nft.loadError, + EVENT_NAMES.nft.loadAllTokens, { value: error, step: 'Load Single Token', status: EVENT_STATUS.rejected }, ) setError({ simpleErrorMessage, completeErrorMessage, error }) diff --git a/src/protocol/ethereum/threeBox/Reducer.tsx b/src/protocol/ethereum/threeBox/Reducer.tsx index 8fb529c..69558f9 100644 --- a/src/protocol/ethereum/threeBox/Reducer.tsx +++ b/src/protocol/ethereum/threeBox/Reducer.tsx @@ -3,6 +3,8 @@ import * as contexts from 'contexts' import { useWeb3React } from '@web3-react/core' import { logger } from 'logger/customLogger' import { getProfile } from '3box/lib/api' +import { EmitterContext } from 'providers/EmitterProvider/context' +import { EVENT_NAMES, EVENT_STATUS } from 'providers/EmitterProvider/constants' import { ThreeBoxProfileDataElement } from './ThreeBoxProfileDataElement' import { ThreeBoxProfileImgElement } from './ThreeBoxProfileImgElement' @@ -15,6 +17,9 @@ interface ReducerProps { } export const Reducer: FunctionComponent = ({ element, info }) => { + + const { actions: { emitToEvent } } = useContext(EmitterContext) + // const injectedContext = useWeb3React() // const { address } = injectedContext const defaultProfile = { @@ -46,9 +51,21 @@ export const Reducer: FunctionComponent = ({ element, info }) => { const fetchProfile = async () => { try { // TODO: [DEV-97] How to we check the status of a request? When no Profile this 404's + emitToEvent( + EVENT_NAMES.threeBox.loadProfile, + { value: null, step: 'Three Box Profile Load', status: EVENT_STATUS.pending }, + ) const profile = await get3boxProfile(address) + emitToEvent( + EVENT_NAMES.threeBox.loadProfile, + { value: profile, step: 'Three Box Profile Load', status: EVENT_STATUS.resolved }, + ) setThreeBoxProfile(profile) } catch (error) { + emitToEvent( + EVENT_NAMES.threeBox.loadProfile, + { value: error, step: 'Three Box Profile Load Error', status: EVENT_STATUS.rejected }, + ) logger.log('You have no profile. ', error) } } diff --git a/src/providers/EmitterProvider/constants.ts b/src/providers/EmitterProvider/constants.ts index cb41d62..6776e84 100644 --- a/src/providers/EmitterProvider/constants.ts +++ b/src/providers/EmitterProvider/constants.ts @@ -14,8 +14,8 @@ export const EVENT_NAMES = { loadSingleToken: 'nft:loadSingleToken', loadMultipleTokens: 'nft:loadMultipleTokens', loadAllTokens: 'nft:loadAllTokens', - loadError: 'nft:loadTokenError', }, + threeBox: { loadProfile: 'threebox:loadProfile' }, } export const EVENT_STATUS = { pending: 'PENDING', resolved: 'RESOLVED', rejected: 'REJECTED' } From 85d13a79c7f313777f3947bb7f8a1b07da9eff58 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 13:23:30 -0400 Subject: [PATCH 22/23] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Add=20event=20to=20?= =?UTF-8?q?EthTransfer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/protocol/ethereum/network/EthTransfer.tsx | 29 +++++++++++++++++-- src/providers/EmitterProvider/constants.ts | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/protocol/ethereum/network/EthTransfer.tsx b/src/protocol/ethereum/network/EthTransfer.tsx index d7f4430..885544f 100644 --- a/src/protocol/ethereum/network/EthTransfer.tsx +++ b/src/protocol/ethereum/network/EthTransfer.tsx @@ -4,6 +4,8 @@ import { logger } from 'logger/customLogger' import * as utils from 'utils' import * as contexts from 'contexts' import { ethers } from 'ethers' +import { EmitterContext } from 'providers/EmitterProvider/context' +import { EVENT_NAMES, EVENT_STATUS } from 'providers/EmitterProvider/constants' const apiKey = process.env.REACT_APP_BLOCKNATIVE_API interface EthTransferProps { @@ -17,6 +19,8 @@ interface EthTransferProps { export const EthTransfer: FunctionComponent = ({ element, amountObj, addressObj, outputObj, info }) => { const ethereum = useContext(contexts.EthereumContext) + const { actions: { emitToEvent } } = useContext(EmitterContext) + const { signer, provider, isEnabled } = ethereum useEffect(() => { @@ -48,15 +52,36 @@ export const EthTransfer: FunctionComponent = ({ element, amou } ] if (from && isEnabled) { // We will only attempt this if we actually got our address from the signer ourslves. + emitToEvent( + EVENT_NAMES.ethTransfer.sendEther, + { value: params, step: 'Send Ether', status: EVENT_STATUS.pending }, + ) provider.send('eth_sendTransaction', params) - .then(notify.hash) - .catch((err) => logger.info('There was an error sending ether with metaMask', err)) + .then((hash) => { + emitToEvent( + EVENT_NAMES.ethTransfer.sendEther, + { value: params, step: 'Send Ether Params', status: EVENT_STATUS.pending }, + ) + notify.hash(hash) + }) + .catch((err) => { + emitToEvent( + EVENT_NAMES.ethTransfer.sendEther, + { value: err, step: 'Send Ether Error', status: EVENT_STATUS.rejected }, + ) + + logger.info('There was an error sending ether with metaMask', err) + }) .finally(() => { amountObj.element.value = '' addressObj.element.value = '' }) } } catch (err) { + emitToEvent( + EVENT_NAMES.ethTransfer.sendEther, + { value: err, step: 'Send Ether Error', status: EVENT_STATUS.rejected }, + ) logger.warn('There was an error transfering ether', err) } } diff --git a/src/providers/EmitterProvider/constants.ts b/src/providers/EmitterProvider/constants.ts index 6776e84..8cfccaf 100644 --- a/src/providers/EmitterProvider/constants.ts +++ b/src/providers/EmitterProvider/constants.ts @@ -16,6 +16,7 @@ export const EVENT_NAMES = { loadAllTokens: 'nft:loadAllTokens', }, threeBox: { loadProfile: 'threebox:loadProfile' }, + ethTransfer: { sendEther: 'ethTransfer:sendEther' }, } export const EVENT_STATUS = { pending: 'PENDING', resolved: 'RESOLVED', rejected: 'REJECTED' } From d93b751526182e478617d68a053272caa6ffadc0 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 17 Jun 2020 13:24:35 -0400 Subject: [PATCH 23/23] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20add=20Eth=20tra?= =?UTF-8?q?snfer=20to=20a=20listen=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Activator.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Activator.tsx b/src/Activator.tsx index 19bd182..c076241 100644 --- a/src/Activator.tsx +++ b/src/Activator.tsx @@ -84,6 +84,7 @@ export const Activator: React.FC = ({ listenToNFTLoadMultipleToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadMultipleTokens, cb), listenToNFTLoadAllToken: (cb): void => listenToEvent(EVENT_NAMES.nft.loadAllTokens, cb), listenTo3BoxProfile: (cb): void => listenToEvent(EVENT_NAMES.threeBox.loadProfile, cb), + listenToEthTransfer: (cb): void => listenToEvent(EVENT_NAMES.ethTransfer.sendEther, cb), } Object.assign(window, { dappHero })