Skip to content

Commit 79db467

Browse files
author
Dane
authored
Merge pull request #1 from mars-protocol/v1.1.0
v1.1.0
2 parents 5f019f3 + 04537f8 commit 79db467

File tree

114 files changed

+5186
-8037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5186
-8037
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22

33
![mars-banner-1200w](https://marsprotocol.io/banner.png)
44

5-
## Web App
5+
## 1. Web App
66

77
This project is a [NextJS](https://nextjs.org/). React application.
88

9-
The project utilises [React hooks](https://reactjs.org/docs/hooks-intro.html), functional components, Zustand for state management, and useQuery for general data fetching and management.
9+
The project utilises [React hooks](https://reactjs.org/docs/hooks-intro.html), functional components, [Zustand](https://github.com/pmndrs/zustand) for state management, and [useQuery](https://github.com/TanStack/query) for general data fetching and management.
1010

1111
Typescript is added and utilised (but optional if you want to create .jsx or .tsx files).
1212

1313
SCSS with [CSS modules](https://create-react-app.dev/docs/adding-a-css-modules-stylesheet) (webpack allows importing css files into javascript, use the CSS module technique to avoid className clashes).
1414

1515
Sentry is used for front end error logging/exception & bug reporting.
1616

17-
## Deployment
17+
## 2. Deployment
1818

1919
Start web server
2020

2121
```bash
2222
yarn && yarn dev
2323
```
2424

25-
### Contributing
25+
## 3. Text and translations
2626

27-
We welcome and encourage contributions! Please create a pull request with as much information about the work you did and what your motivation/intention was.
27+
This repository makes use of a [translation repository](https://github.com/mars-protocol/translations). This repository containes all of the translation key values that are used within the UI. The rationale is to have no _hardcoded_ display string values in this repository.
28+
29+
## 4. Development practices
2830

29-
## Imports
31+
### 4.1 Imports
3032

3133
Local components are imported via index files, which can be automatically generated with `yarn index`. This command targets index.ts files with a specific pattern in order to automate component exports. This results in clean imports throughout the pages:
3234

3335
```
34-
import { Button, Card, Titlte } from 'components/common'
36+
import { Button, Card, Title } from 'components/common'
3537
```
3638

3739
or
@@ -42,6 +44,16 @@ import { Breakdown, RepayInput } from 'components/fields'
4244

4345
In order for this to work, components are place in a folder with UpperCamelCase with the respective Component.tsx file. The component cannot be exported at default, so rather export the `const` instead.
4446

45-
## License
47+
### 4.2 Data orchestration
48+
49+
Data is handled with a combination of container components, useQuery and Zustand. Container components are responsible for syncing the application state with the wallet-provider state. This fire of the required queries in useQuery, which are for many cases also stored in Zustand.
50+
51+
We aim to have as much as possible available in Zustand, to have one source of truth.
52+
53+
## 5. Contributing
54+
55+
We welcome and encourage contributions! Please create a pull request with as much information about the work you did and what your motivation/intention was.
56+
57+
## 6. License
4658

4759
Contents of this repository are open source under the [Mars Protocol Web Application License Agreement](./LICENSE).

package.json

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mars",
33
"homepage": "./",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"private": false,
66
"license": "SEE LICENSE IN LICENSE FILE",
77
"scripts": {
@@ -22,48 +22,48 @@
2222
"@cosmjs/launchpad": "^0.27.1",
2323
"@cosmjs/proto-signing": "^0.29.5",
2424
"@cosmjs/stargate": "^0.29.5",
25-
"@marsprotocol/wallet-connector": "^0.9.12",
25+
"@marsprotocol/wallet-connector": "^1.2.3",
2626
"@material-ui/core": "^4.12.4",
2727
"@material-ui/icons": "^4.11.3",
28-
"@ramonak/react-progress-bar": "^5.0.2",
29-
"@sentry/nextjs": "^7.12.1",
30-
"@tanstack/react-query": "^4.3.4",
31-
"@tanstack/react-table": "^8.5.13",
32-
"@testing-library/dom": "^8.17.1",
28+
"@ramonak/react-progress-bar": "^5.0.3",
29+
"@sentry/nextjs": "^7.34.0",
30+
"@tanstack/react-query": "^4.24.4",
31+
"@tanstack/react-table": "^8.7.9",
32+
"@testing-library/dom": "^8.20.0",
3333
"@testing-library/jest-dom": "^5.16.5",
3434
"@testing-library/react": "^13.4.0",
3535
"@testing-library/user-event": "^14.4.3",
3636
"@tippyjs/react": "^4.2.6",
37-
"bignumber.js": "^9.1.0",
38-
"chart.js": "^3.9.1",
39-
"classnames": "^2.3.1",
37+
"bignumber.js": "^9.1.1",
38+
"chart.js": "^4.2.0",
39+
"classnames": "^2.3.2",
4040
"create-conical-gradient": "^1.1.0",
4141
"graphql": "^16.6.0",
42-
"graphql-request": "^5.0.0",
43-
"i18next": "^21.9.1",
44-
"i18next-browser-languagedetector": "^6.1.5",
45-
"i18next-http-backend": "^1.4.1",
42+
"graphql-request": "^5.1.0",
43+
"i18next": "^22.4.9",
44+
"i18next-browser-languagedetector": "^7.0.1",
45+
"i18next-http-backend": "^2.1.1",
4646
"lodash.clonedeep": "^4.5.0",
4747
"lodash.isequal": "^4.5.0",
4848
"lodash.throttle": "^4.1.1",
4949
"moment": "^2.29.4",
5050
"moment-duration-format": "^2.3.2",
51-
"next": "^12.2.5",
51+
"next": "^13.1.6",
5252
"numeral": "^2.0.6",
5353
"ramda": "^0.28.0",
5454
"react": "^18.2.0",
55-
"react-chartjs-2": "^4.3.1",
56-
"react-currency-input-field": "^3.6.4",
55+
"react-chartjs-2": "^5.2.0",
56+
"react-currency-input-field": "^3.6.9",
5757
"react-device-detect": "^2.2.2",
5858
"react-dom": "^18.2.0",
59-
"react-i18next": "^11.18.5",
60-
"react-spring": "^9.5.5",
59+
"react-i18next": "^12.1.4",
60+
"react-spring": "^9.6.1",
6161
"react-table": "^7.8.0",
62-
"react-use-clipboard": "^1.0.8",
63-
"sass": "^1.56.1",
64-
"typescript": "^4.8.2",
65-
"web-vitals": "^3.0.1",
66-
"zustand": "^4.1.1"
62+
"react-use-clipboard": "^1.0.9",
63+
"sass": "^1.57.1",
64+
"typescript": "^4.9.5",
65+
"web-vitals": "^3.1.1",
66+
"zustand": "^4.3.2"
6767
},
6868
"browserslist": {
6969
"production": [
@@ -80,26 +80,26 @@
8080
"devDependencies": {
8181
"@types/chart.js": "^2.9.37",
8282
"@types/classnames": "^2.3.1",
83-
"@types/jest": "^29.2.3",
83+
"@types/jest": "^29.4.0",
8484
"@types/lodash.clonedeep": "^4.5.7",
8585
"@types/lodash.isequal": "^4.5.6",
8686
"@types/lodash.throttle": "^4.1.7",
87-
"@types/node": "^18.7.15",
87+
"@types/node": "^18.11.18",
8888
"@types/numeral": "^2.0.2",
89-
"@types/prettier": "^2.7.0",
90-
"@types/ramda": "^0.28.15",
91-
"@types/react": "^18.0.18",
92-
"@types/react-dom": "^18.0.6",
93-
"@types/react-table": "^7.7.12",
94-
"eslint": "^8.23.0",
95-
"eslint-config-next": "^12.2.5",
96-
"eslint-plugin-simple-import-sort": "^8.0.0",
89+
"@types/prettier": "^2.7.2",
90+
"@types/ramda": "^0.28.22",
91+
"@types/react": "^18.0.27",
92+
"@types/react-dom": "^18.0.10",
93+
"@types/react-table": "^7.7.14",
94+
"eslint": "^8.33.0",
95+
"eslint-config-next": "^13.1.6",
96+
"eslint-plugin-simple-import-sort": "^10.0.0",
9797
"eslint-plugin-unused-imports": "^2.0.0",
98-
"jest": "^29.3.1",
99-
"jest-environment-jsdom": "^29.3.1",
100-
"prettier": "^2.7.1",
98+
"jest": "^29.4.1",
99+
"jest-environment-jsdom": "^29.4.1",
100+
"prettier": "^2.8.3",
101101
"pretty-quick": "^3.1.3",
102-
"vscode-generate-index-standalone": "^1.6.0"
102+
"vscode-generate-index-standalone": "^1.7.1"
103103
},
104104
"engines": {
105105
"npm": "please-use-yarn",

src/components/common/Backdrop/Backdrop.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import classNames from 'classnames/bind'
1+
import classNames from 'classnames'
22

33
import styles from './Backdrop.module.scss'
44

src/components/common/CellAmount/CellAmount.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import classNames from 'classnames/bind'
1+
import classNames from 'classnames'
22
import { AnimatedNumber, DisplayCurrency } from 'components/common'
33
import { lookup } from 'libs/parse'
44

src/components/common/Containers/CommonContainer.tsx

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { useWallet } from '@marsprotocol/wallet-connector'
1+
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
2+
import {
3+
getChainInfo,
4+
getClient,
5+
useWallet,
6+
useWalletManager,
7+
WalletConnectionStatus,
8+
} from '@marsprotocol/wallet-connector'
29
import { useQueryClient } from '@tanstack/react-query'
310
import { MARS_SYMBOL, USDC_SYMBOL } from 'constants/appConstants'
411
import {
@@ -9,9 +16,10 @@ import {
916
useUserBalance,
1017
useUserDebt,
1118
useUserDeposit,
19+
useUserIcns,
1220
} from 'hooks/queries'
1321
import { useSpotPrice } from 'hooks/queries/useSpotPrice'
14-
import { ReactNode, useEffect } from 'react'
22+
import { ReactNode, useEffect, useState } from 'react'
1523
import useStore from 'store'
1624
import { State } from 'types/enums'
1725
import { Network } from 'types/enums/network'
@@ -24,9 +32,15 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
2432
// ------------------
2533
// EXTERNAL HOOKS
2634
// ---------------
27-
const { chainInfo, address, signingCosmWasmClient, name } = useWallet()
35+
const { recentWallet, simulate, sign, broadcast } = useWallet()
36+
const { status } = useWalletManager()
2837
const queryClient = useQueryClient()
2938

39+
const chainInfo = recentWallet?.network ? getChainInfo(recentWallet?.network.chainId) : undefined
40+
const address = status !== WalletConnectionStatus.Connected ? '' : recentWallet?.account.address
41+
42+
const [cosmWasmClient, setCosmWasmClient] = useState<CosmWasmClient | undefined>()
43+
3044
// ------------------
3145
// STORE STATE
3246
// ------------------
@@ -54,7 +68,6 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
5468
const setClient = useStore((s) => s.setClient)
5569
const setUserBalancesState = useStore((s) => s.setUserBalancesState)
5670
const setUserWalletAddress = useStore((s) => s.setUserWalletAddress)
57-
const setUserWalletName = useStore((s) => s.setUserWalletName)
5871

5972
// ------------------
6073
// SETTERS
@@ -75,21 +88,11 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
7588
setUserWalletAddress(address || '')
7689
}, [setUserWalletAddress, address])
7790

78-
useEffect(() => {
79-
if (!name) return
80-
setUserWalletName(name)
81-
}, [setUserWalletName, name])
82-
8391
useEffect(() => {
8492
if (!rpc || !chainID) return
8593
setLcdClient(rpc, chainID)
8694
}, [rpc, chainID, setLcdClient])
8795

88-
useEffect(() => {
89-
if (!signingCosmWasmClient) return
90-
setClient(signingCosmWasmClient)
91-
}, [signingCosmWasmClient, setClient])
92-
9396
useEffect(() => {
9497
if (userDebts && userDeposits && userBalances) {
9598
setUserBalancesState(State.READY)
@@ -98,6 +101,28 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
98101
}
99102
}, [userDebts, userDeposits, userBalances, setUserBalancesState])
100103

104+
useEffect(() => {
105+
if (!recentWallet) return
106+
if (!cosmWasmClient) {
107+
const getCosmWasmClient = async () => {
108+
const cosmClient = await getClient(recentWallet.network.rpc)
109+
setCosmWasmClient(cosmClient)
110+
}
111+
112+
getCosmWasmClient()
113+
return
114+
}
115+
116+
const client = {
117+
broadcast,
118+
cosmWasmClient,
119+
recentWallet,
120+
sign,
121+
simulate,
122+
}
123+
setClient(client)
124+
}, [simulate, sign, recentWallet, cosmWasmClient, broadcast, setClient])
125+
101126
useEffect(() => {
102127
setRedBankAssets()
103128
}, [
@@ -126,6 +151,7 @@ export const CommonContainer = ({ children }: CommonContainerProps) => {
126151
useBlockHeight()
127152
useRedBank()
128153
useUserBalance()
154+
useUserIcns()
129155
useUserDeposit()
130156
useUserDebt()
131157
useMarsOracle()

src/components/common/Containers/FieldsContainer.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { ReactNode, useEffect } from 'react'
22
import useStore from 'store'
3+
import { AccountNftClient, CreditManagerClient } from 'types/classes'
34

45
interface FieldsContainerProps {
56
children: ReactNode
@@ -9,15 +10,17 @@ export const FieldsContainer = ({ children }: FieldsContainerProps) => {
910
const client = useStore((s) => s.client)
1011
const networkConfig = useStore((s) => s.networkConfig)
1112
const userWalletAddress = useStore((s) => s.userWalletAddress)
12-
const setAccountNftClient = useStore((s) => s.setAccountNftClient)
13-
const setCreditManagerClient = useStore((s) => s.setCreditManagerClient)
1413
const setCreditManagerMsgComposer = useStore((s) => s.setCreditManagerMsgComposer)
1514

1615
useEffect(() => {
17-
if (!client) return
18-
setAccountNftClient(client)
19-
setCreditManagerClient(client)
20-
}, [client, setAccountNftClient, setCreditManagerClient])
16+
if (!client || !networkConfig) return
17+
useStore.setState({
18+
creditManagerClient: new CreditManagerClient(networkConfig?.contracts.creditManager, client),
19+
})
20+
useStore.setState({
21+
accountNftClient: new AccountNftClient(networkConfig?.contracts.accountNft, client),
22+
})
23+
}, [client, networkConfig])
2124

2225
useEffect(() => {
2326
if (!userWalletAddress || !networkConfig?.contracts.creditManager) return

0 commit comments

Comments
 (0)