Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/masa-finance/masa-react i…
Browse files Browse the repository at this point in the history
…nto feature/no-identity-flow
  • Loading branch information
hide-on-bush-x committed Mar 3, 2023
2 parents 778087a + adc897b commit c8da6a1
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 59 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v1.0.13](https://github.com/masa-finance/masa-react/compare/v1.0.12...v1.0.13)

> 3 March 2023
- update docs [`6da626d`](https://github.com/masa-finance/masa-react/commit/6da626d47483c11a3ebe7775a0a2a2cfcee2e494)
- fix network loading [`809481d`](https://github.com/masa-finance/masa-react/commit/809481de2135a1123e8fce2e41073744274485c8)

#### [v1.0.12](https://github.com/masa-finance/masa-react/compare/v1.0.11...v1.0.12)

> 3 March 2023
- avoid get network, use get chain id and lookup our own data [`#73`](https://github.com/masa-finance/masa-react/pull/73)
- update docs [`74198a8`](https://github.com/masa-finance/masa-react/commit/74198a8356c23e854e2a4a0dbfc66b5b2c3aeb1d)
- update sdk [`c460caa`](https://github.com/masa-finance/masa-react/commit/c460caa4f4944ab404ec044c98457b200f0d7b6e)
- resolve merge conflicts [`10dd4b0`](https://github.com/masa-finance/masa-react/commit/10dd4b016255a46e700e2b54afad1fa17ff5c10c)

#### [v1.0.11](https://github.com/masa-finance/masa-react/compare/v1.0.10...v1.0.11)

> 2 March 2023
- Identity requirement [`d4dd6f2`](https://github.com/masa-finance/masa-react/commit/d4dd6f22784d16527456c2ea7073f7db121dd3cb)

#### [v1.0.10](https://github.com/masa-finance/masa-react/compare/v1.0.9...v1.0.10)

> 2 March 2023
- Callback fix [`ddd1e68`](https://github.com/masa-finance/masa-react/commit/ddd1e68f6983ea5ff60f7541b43814e9fb6a2658)
- Lint fix [`c54a5e5`](https://github.com/masa-finance/masa-react/commit/c54a5e53728852d9e036faf896f72a0d63af8597)

#### [v1.0.9](https://github.com/masa-finance/masa-react/compare/v1.0.8...v1.0.9)

> 2 March 2023
- Soulname mint flow condition fix [`e718383`](https://github.com/masa-finance/masa-react/commit/e718383abc2171391f94d0c9c2421fbf54f5a708)

#### [v1.0.8](https://github.com/masa-finance/masa-react/compare/v1.0.7...v1.0.8)

> 2 March 2023
- Verifying that there is an identity [`6d1bfbd`](https://github.com/masa-finance/masa-react/commit/6d1bfbdfbf175fe8b6da5722836f7733f7b51b74)
- update changelog [`8ef9d8f`](https://github.com/masa-finance/masa-react/commit/8ef9d8f82ad57400e67707f647602be409d8c05c)
- update docs [`932748c`](https://github.com/masa-finance/masa-react/commit/932748cc9a1884141ccaf1ee19cf300b2fed65bf)

#### [v1.0.7](https://github.com/masa-finance/masa-react/compare/v1.0.6...v1.0.7)

> 2 March 2023
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Masa React
- v1.0.7 / [Exports](modules.md)
- v1.0.13 / [Exports](modules.md)

---

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/ArweaveConfig.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[# Masa React
- v1.0.7](../README.md) / [Exports](../modules.md) / ArweaveConfig
- v1.0.13](../README.md) / [Exports](../modules.md) / ArweaveConfig

# Interface: ArweaveConfig

Expand Down
24 changes: 12 additions & 12 deletions docs/interfaces/MasaContextProviderProps.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[# Masa React
- v1.0.7](../README.md) / [Exports](../modules.md) / MasaContextProviderProps
- v1.0.13](../README.md) / [Exports](../modules.md) / MasaContextProviderProps

# Interface: MasaContextProviderProps

Expand All @@ -21,6 +21,7 @@
- [company](MasaContextProviderProps.md#company)
- [connect](MasaContextProviderProps.md#connect)
- [creditScores](MasaContextProviderProps.md#creditscores)
- [currentNetwork](MasaContextProviderProps.md#currentnetwork)
- [environmentName](MasaContextProviderProps.md#environmentname)
- [forcedPage](MasaContextProviderProps.md#forcedpage)
- [greens](MasaContextProviderProps.md#greens)
Expand All @@ -43,7 +44,6 @@
- [isSoulnamesLoading](MasaContextProviderProps.md#issoulnamesloading)
- [isWalletLoading](MasaContextProviderProps.md#iswalletloading)
- [masa](MasaContextProviderProps.md#masa)
- [network](MasaContextProviderProps.md#network)
- [noWallet](MasaContextProviderProps.md#nowallet)
- [openMintSoulnameModal](MasaContextProviderProps.md#openmintsoulnamemodal)
- [provider](MasaContextProviderProps.md#provider)
Expand Down Expand Up @@ -169,6 +169,16 @@ ___

___

### currentNetwork

`Optional` **currentNetwork**: [`Network`](Network.md)

#### Inherited from

[MasaShape](MasaShape.md).[currentNetwork](MasaShape.md#currentnetwork)

___

### environmentName

`Optional` **environmentName**: `undefined`
Expand Down Expand Up @@ -475,16 +485,6 @@ ___

___

### network

`Optional` **network**: `Network`

#### Inherited from

[MasaShape](MasaShape.md).[network](MasaShape.md#network)

___

### noWallet

`Optional` **noWallet**: `boolean`
Expand Down
16 changes: 8 additions & 8 deletions docs/interfaces/MasaShape.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[# Masa React
- v1.0.7](../README.md) / [Exports](../modules.md) / MasaShape
- v1.0.13](../README.md) / [Exports](../modules.md) / MasaShape

# Interface: MasaShape

Expand All @@ -20,6 +20,7 @@
- [company](MasaShape.md#company)
- [connect](MasaShape.md#connect)
- [creditScores](MasaShape.md#creditscores)
- [currentNetwork](MasaShape.md#currentnetwork)
- [forcedPage](MasaShape.md#forcedpage)
- [greens](MasaShape.md#greens)
- [handleCreateCreditScore](MasaShape.md#handlecreatecreditscore)
Expand All @@ -41,7 +42,6 @@
- [isSoulnamesLoading](MasaShape.md#issoulnamesloading)
- [isWalletLoading](MasaShape.md#iswalletloading)
- [masa](MasaShape.md#masa)
- [network](MasaShape.md#network)
- [openMintSoulnameModal](MasaShape.md#openmintsoulnamemodal)
- [provider](MasaShape.md#provider)
- [reloadCreditScores](MasaShape.md#reloadcreditscores)
Expand Down Expand Up @@ -130,6 +130,12 @@ ___

___

### currentNetwork

`Optional` **currentNetwork**: [`Network`](Network.md)

___

### forcedPage

`Optional` **forcedPage**: ``null`` \| `string`
Expand Down Expand Up @@ -346,12 +352,6 @@ ___

___

### network

`Optional` **network**: `Network`

___

### openMintSoulnameModal

`Optional` **openMintSoulnameModal**: (`callback?`: () => `void`) => `void`
Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/ModalProps.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[# Masa React
- v1.0.7](../README.md) / [Exports](../modules.md) / ModalProps
- v1.0.13](../README.md) / [Exports](../modules.md) / ModalProps

# Interface: ModalProps

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/Network.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[# Masa React
- v1.0.7](../README.md) / [Exports](../modules.md) / Network
- v1.0.13](../README.md) / [Exports](../modules.md) / Network

# Interface: Network

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/SpinnerProps.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[# Masa React
- v1.0.7](../README.md) / [Exports](../modules.md) / SpinnerProps
- v1.0.13](../README.md) / [Exports](../modules.md) / SpinnerProps

# Interface: SpinnerProps

Expand Down
8 changes: 4 additions & 4 deletions docs/modules.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[# Masa React
- v1.0.7](README.md) / Exports
- v1.0.13](README.md) / Exports

# # Masa React
- v1.0.7
- v1.0.13

## Table of contents

Expand Down Expand Up @@ -372,7 +372,7 @@ ___
| `masa?` | `default` |
| `isLoggedIn?` | `boolean` |
| `isConnected?` | `boolean` |
| `network?` | `Network` |
| `network?` | [`Network`](interfaces/Network.md) |
| `areScopesFullfiled?` | `boolean` |

#### Returns
Expand Down Expand Up @@ -408,7 +408,7 @@ ___
| Name | Type |
| :------ | :------ |
| `addNetwork` | (`networkDetails`: [`Network`](interfaces/Network.md)) => `void` |
| `network?` | `Network` |
| `currentNetwork?` | [`Network`](interfaces/Network.md) |
| `switchNetwork` | (`chainId`: `number`) => `void` |

___
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@masa-finance/masa-react",
"version": "1.0.10",
"version": "1.0.14",
"license": "MIT",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -29,7 +29,7 @@
"author": "hide-on-bush",
"dependencies": {
"@babel/preset-typescript": "^7.21.0",
"@masa-finance/masa-sdk": "^1.6.4",
"@masa-finance/masa-sdk": "^1.6.5",
"@metamask/providers": "^10.2.1",
"babel-loader": "^9.1.2",
"babel-plugin-import": "^1.13.6",
Expand Down
2 changes: 2 additions & 0 deletions src/components/masa-interface/masa-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const MasaInterface = ({
if (!isLoggedIn && provider) return 'authenticate';

if (
isLoggedIn &&
(!soulnames || (soulnames && soulnames.length === 0)) &&
scope?.includes('soulname')
)
Expand All @@ -64,6 +65,7 @@ export const MasaInterface = ({

if (identity && !creditScores?.length && scope?.includes('credit-score'))
return 'createCreditScore';

if (isConnected && isLoggedIn) return 'connectedState';

return 'connector';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { Network } from '../../../../helpers';
export const InterfaceSwitchChain = (): JSX.Element => {
const { isLoading, switchNetwork, SupportedNetworks, masa } = useMasa();

const currentNetwork: Network | null = useMemo(() => {
const currentNetwork: Network | undefined = useMemo(() => {
if (SupportedNetworks && masa?.config.network)
for (const chainId in SupportedNetworks) {
for (const networkName in SupportedNetworks) {
if (
SupportedNetworks[chainId].chainName
SupportedNetworks[networkName].chainName
?.toLowerCase()
.includes(masa.config.network)
) {
return SupportedNetworks[chainId];
return SupportedNetworks[networkName];
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/provider/masa-context-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const MasaContextProvider = ({
useSession(masaInstance, walletAddress);

// network
const { switchNetwork, network } = useNetwork(provider);
const { switchNetwork, currentNetwork } = useNetwork(provider);

// identity
const {
Expand Down Expand Up @@ -119,7 +119,7 @@ export const MasaContextProvider = ({
masaInstance,
isLoggedIn,
isConnected,
network,
currentNetwork,
areScopesFullfiled
);

Expand Down Expand Up @@ -179,7 +179,7 @@ export const MasaContextProvider = ({
arweaveConfig,
environmentName,
verbose,
network,
currentNetwork,
]);

const context: MasaShape = {
Expand Down Expand Up @@ -245,7 +245,7 @@ export const MasaContextProvider = ({
reloadGreens,

// network
network,
currentNetwork,
SupportedNetworks,
switchNetwork,
};
Expand Down
2 changes: 1 addition & 1 deletion src/provider/masa-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface MasaShape {
reloadGreens?: () => void;

// network
network?: ethers.providers.Network;
currentNetwork?: Network;
SupportedNetworks?: Partial<{ [index in NetworkName]: Network }>;
switchNetwork?: (chainId: number) => void;
}
4 changes: 2 additions & 2 deletions src/provider/modules/modal/modal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useCallback, useState } from 'react';
import { providers } from 'ethers';
import { Masa } from '@masa-finance/masa-sdk';
import { Network } from '../../../helpers';

export const useModal = (
masa?: Masa,
isLoggedIn?: boolean,
isConnected?: boolean,
network?: providers.Network,
network?: Network,
areScopesFullfiled?: boolean
): {
isModalOpen: boolean;
Expand Down
25 changes: 17 additions & 8 deletions src/provider/modules/network/network.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { providers, Signer, utils, Wallet } from 'ethers';
import { Signer, utils, Wallet } from 'ethers';
import { useCallback, useEffect, useState } from 'react';
import { Network, SupportedNetworks } from '../../../helpers';
import {
getNetworkNameByChainId,
Network,
SupportedNetworks,
} from '../../../helpers';

export const useNetwork = (
provider?: Wallet | Signer
): {
addNetwork: (networkDetails: Network) => void;
switchNetwork: (chainId: number) => void;
network?: providers.Network;
currentNetwork?: Network;
} => {
const [network, setNetwork] = useState<providers.Network | undefined>();
const [currentNetwork, setCurrentNetwork] = useState<Network | undefined>();

const addNetwork = useCallback(async (networkDetails: Network) => {
try {
Expand All @@ -34,11 +38,12 @@ export const useNetwork = (
const loadNetwork = useCallback(async (): Promise<void> => {
if (!provider) return;

const newNetwork = await provider.provider?.getNetwork();
const chainId: number = await provider.getChainId();

const newNetwork = SupportedNetworks[getNetworkNameByChainId(chainId)];
console.log({ newNetwork });

setNetwork(newNetwork ?? undefined);
setCurrentNetwork(newNetwork);
}, [provider]);

const switchNetwork = useCallback(
Expand All @@ -54,7 +59,11 @@ export const useNetwork = (
} catch (err) {
const error = err as { code: number };
if (error.code === 4902) {
await addNetwork(SupportedNetworks[chainId]);
const newNetwork =
SupportedNetworks[getNetworkNameByChainId(chainId)];
if (newNetwork) {
await addNetwork(newNetwork);
}
}
}

Expand All @@ -70,6 +79,6 @@ export const useNetwork = (
return {
addNetwork,
switchNetwork,
network,
currentNetwork,
};
};

0 comments on commit c8da6a1

Please sign in to comment.