Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b02d8a7
Adding the react-components library.
erchaves Sep 3, 2021
4e4ed2a
first pass -- adding a couple navigation buttons which go to url routes
erchaves Sep 4, 2021
c67b07a
first demonstration of changing views.
erchaves Sep 4, 2021
01584c1
clean up comments, add isActive state style
erchaves Sep 4, 2021
1fe3be8
use new NavLink instead of NavButton
erchaves Sep 7, 2021
98a3111
adding utils/urlParams from a future branch.
erchaves Sep 8, 2021
96cca54
adding an owners page, updating logic to use page url constants
erchaves Sep 8, 2021
71035c1
adding case for owners page to show accounts only on that owners page
erchaves Sep 8, 2021
cf12b13
lint fixes
erchaves Sep 8, 2021
accd382
fixing missing comma
erchaves Sep 8, 2021
ea81b4e
First pass at refactoring MSIG and restyling it.
erchaves Sep 8, 2021
f9d5e80
lint fixes
erchaves Sep 8, 2021
56ea3cf
rename the lint fix helper that I added before. lint:fix better match…
erchaves Sep 8, 2021
b28dadc
adding other pages
erchaves Sep 8, 2021
0f23ff1
lint fix
erchaves Sep 8, 2021
4fe310e
lint updates
erchaves Sep 8, 2021
cbe693e
Merge branch 'primary' into feat/GLIF-39-refactor-multisig-navigation
erchaves Sep 10, 2021
26dc071
adding close buttons to individual addresses
erchaves Sep 10, 2021
bbfefa1
lint fixes
erchaves Sep 10, 2021
12e2b9c
differentiating between onClose and onComplete calls
erchaves Sep 10, 2021
64f9c5a
Merge branch 'primary' into feat/GLIF-39-refactor-multisig-navigation
erchaves Sep 10, 2021
fd20e5a
fix merge for msig/home/index
erchaves Sep 10, 2021
40f529a
Fix issue with input
Schwartz10 Sep 10, 2021
d517937
auto selecting the user to remove
erchaves Sep 10, 2021
2dbfab4
adding onComplete in addition to onClose to other pages
erchaves Sep 10, 2021
f2d4fe1
Merge branch 'primary' into feat/GLIF-39-refactor-multisig-navigation
erchaves Sep 10, 2021
085c6a7
Fixing merge after react-components update. And Factoring NavMenu out…
erchaves Sep 11, 2021
93c7cc9
Linting. And fixing name of MyNavLink
erchaves Sep 11, 2021
253705c
fix issue where this was opening in a new window which was breaking t…
erchaves Sep 11, 2021
4451f39
cleanup and replacing shared components with glif/react-components
erchaves Sep 11, 2021
234c8fb
More switching from shared to glif/react-components
erchaves Sep 11, 2021
97c33ae
adding msig.NumApprovalsThreshold
erchaves Sep 11, 2021
77f0faa
lint cleanup. Change tooltip msg
erchaves Sep 11, 2021
113a068
Merge branch 'primary' into GLIF-39
erchaves Sep 13, 2021
dfa7799
rebuild package.lock after merge for good measure.
erchaves Sep 13, 2021
97513b6
Fixing tests. Mostly around replacing close to onClose and adding an …
erchaves Sep 13, 2021
1dbaebe
These functions aren't used anywhere, remove them from the test
erchaves Sep 13, 2021
326e644
adding logout button to msig
erchaves Sep 13, 2021
43105af
lint fixes
erchaves Sep 13, 2021
96399e0
fix proptype the Cid is just a string
erchaves Sep 13, 2021
90ac202
Merge branch 'primary' of github.com:glifio/wallet into GLIF-39
Schwartz10 Sep 14, 2021
8151cf5
Initial code review + revisions
Schwartz10 Sep 14, 2021
32f8789
Almost finished refactoring all the msig tabs to pages
Schwartz10 Sep 15, 2021
64b0997
Fix bug
Schwartz10 Sep 15, 2021
34c45e6
Fix error prone logic in the urlParams helpers
Schwartz10 Sep 15, 2021
7215618
Fix add and remove signer
Schwartz10 Sep 15, 2021
7cccc9d
UI Cleanup
Schwartz10 Sep 16, 2021
6fdd6ff
Cleanup NAV UI
Schwartz10 Sep 16, 2021
44576bf
Separate add/rm signer from each other
Schwartz10 Sep 16, 2021
65aba1c
Clean up some more visuals
Schwartz10 Sep 16, 2021
a5d0df0
Fix tests
Schwartz10 Sep 16, 2021
e5d48a3
Fix url params error
Schwartz10 Sep 16, 2021
94878ba
Fix bug on withdraw
Schwartz10 Sep 16, 2021
e9ff02b
Let the child component under header breath
Schwartz10 Sep 16, 2021
881fff5
Change owners => admin
Schwartz10 Sep 16, 2021
6ff5c81
Add test for msig/home
Schwartz10 Sep 18, 2021
8b46138
Add tests for Msig/Home
Schwartz10 Sep 20, 2021
487eca9
Fix fetchAndSetMsigActor tests
Schwartz10 Sep 20, 2021
06e3043
Fix msig/Create tests
Schwartz10 Sep 20, 2021
87986b7
Fix msig withdraw tests
Schwartz10 Sep 20, 2021
b75ac4c
Clean up Change Signer
Schwartz10 Sep 20, 2021
6b50559
Wire up change signer
Schwartz10 Sep 20, 2021
535f1a1
Fix change signer names and tests
Schwartz10 Sep 20, 2021
6e3e523
Fix tests from react component changes
Schwartz10 Sep 20, 2021
131d453
Revert mistaken changes
Schwartz10 Sep 20, 2021
4a9e072
Delete unused code
Schwartz10 Sep 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions MsigProvider/__mocks__/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { FilecoinNumber } from '@glif/filecoin-number'
import { createContext, ReactNode, Dispatch, useContext } from 'react'
import { SWRConfig } from 'swr'
import { MsigActorState } from '../../MsigProvider/types'

export const MULTISIG_ACTOR_ADDRESS =
'f2m4f2dv7m35skytoqzsyrh5wqz3kxxfflxsha5za'
export const MULTISIG_SIGNER_ADDRESS =
'f1nq5k2mps5umtebdovlyo7y6a3ywc7u4tobtuo3a'

const MsigProviderContextMock = createContext<
MsigActorState & {
setMsigActor: null | Dispatch<string | null>
} & { loading: boolean }
>({
Address: MULTISIG_ACTOR_ADDRESS,
ActorCode: 'fil/5/multisig',
Balance: new FilecoinNumber('1', 'fil'),
AvailableBalance: new FilecoinNumber('1', 'fil'),
Signers: [
{
account: MULTISIG_SIGNER_ADDRESS,
id: 't01234'
}
],
InitialBalance: new FilecoinNumber('1', 'fil'),
NextTxnID: 0,
NumApprovalsThreshold: 1,
StartEpoch: 0,
UnlockDuration: 0,
errors: {
notMsigActor: false,
connectedWalletNotMsigSigner: false,
actorNotFound: true,
unhandledError: ''
},
loading: false,
setMsigActor: null
})

export const MsigProviderWrapper = ({ children }: { children: ReactNode }) => {
return (
<SWRConfig value={{ dedupingInterval: 0 }}>
<MsigProviderContextMock.Provider
value={{
Address: 'f2m4f2dv7m35skytoqzsyrh5wqz3kxxfflxsha5za',
ActorCode: 'fil/5/multisig',
Balance: new FilecoinNumber('1', 'fil'),
AvailableBalance: new FilecoinNumber('1', 'fil'),
Signers: [],
InitialBalance: new FilecoinNumber('1', 'fil'),
NextTxnID: 0,
NumApprovalsThreshold: 1,
StartEpoch: 0,
UnlockDuration: 0,
errors: {
notMsigActor: false,
connectedWalletNotMsigSigner: false,
actorNotFound: true,
unhandledError: ''
},
loading: false,
setMsigActor: () => {}
}}
>
{children}
</MsigProviderContextMock.Provider>
</SWRConfig>
)
}

export const useMsig = () => useContext(MsigProviderContextMock)
5 changes: 5 additions & 0 deletions MsigProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const MsigProviderContext = createContext<
setMsigActor: null
})

export type MsigProviderContextType = MsigActorState & {
setMsigActor: null | Dispatch<string | null>
loading: boolean
}

export const MsigProviderWrapper = ({ children }: { children: ReactNode }) => {
const wallet = useWallet()
const [msigActor, setMsigActor] = useState(null)
Expand Down
7 changes: 6 additions & 1 deletion MsigProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export interface MsigActorErrors {
unhandledError: string
}

export interface Signer {
id: string
account: string
}

export interface MsigActorState {
Address: string | null
ActorCode: string
Expand All @@ -17,7 +22,7 @@ export interface MsigActorState {
NumApprovalsThreshold: number
StartEpoch: number
UnlockDuration: number
Signers: { id: string; account: string }[]
Signers: Signer[]
errors: MsigActorErrors
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,68 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { BigNumber } from '@glif/filecoin-number'
import React, { useCallback, useState } from 'react'
import { useDispatch } from 'react-redux'
import dayjs from 'dayjs'
import { Message } from '@glif/filecoin-message'
import { validateAddressString } from '@glif/filecoin-address'
import { BigNumber } from '@glif/filecoin-number'
import { useRouter } from 'next/router'
import { Box, Button, ButtonClose, Form, Card } from '@glif/react-components'

import { useWalletProvider } from '../../../WalletProvider'
import useWallet from '../../../WalletProvider/useWallet'
import {
Box,
Button,
ButtonClose,
StepHeader,
Input,
Form,
Card
} from '../../Shared'
import {
ADDRESS_PROPTYPE,
FILECOIN_NUMBER_PROP
} from '../../../customPropTypes'
import { CardHeader, ChangeOwnerHeaderText } from '../Shared'
import Preface from './Preface'
import { useMsig } from '../../../MsigProvider'
import { CardHeader, AddRmSignerHeader } from '../Shared'
import Preface from './Prefaces'
import { useWasm } from '../../../lib/WasmLoader'
import ErrorCard from '../../Wallet/Send/ErrorCard'
import ConfirmationCard from '../../Wallet/Send/ConfirmationCard'
import { LEDGER, PROPOSE, emptyGasInfo } from '../../../constants'
import {
LEDGER,
PROPOSE,
emptyGasInfo,
MSIG_METHOD,
PAGE
} from '../../../constants'
import CustomizeFee from '../../Wallet/Send/CustomizeFee'
import {
reportLedgerConfigError,
hasLedgerError
} from '../../../utils/ledger/reportLedgerConfigError'
import reportError from '../../../utils/reportError'
import toLowerCaseMsgFields from '../../../utils/toLowerCaseMsgFields'
import { navigate } from '../../../utils/urlParams'
import { confirmMessage } from '../../../store/actions'
import { AddSignerInput } from './SignerInput'

const ChangeOwner = ({ address, balance, close }) => {
const AddSigner = () => {
const { ledger, connectLedger, resetLedgerState } = useWalletProvider()
const { Address: address, AvailableBalance: balance } = useMsig()
const wallet = useWallet()
const dispatch = useDispatch()
const { serializeParams } = useWasm()
const [step, setStep] = useState(1)
const [attemptingTx, setAttemptingTx] = useState(false)
const [toAddress, setToAddress] = useState('')
const [toAddressError, setToAddressError] = useState('')
const [signerAddress, setSignerAddress] = useState('')
const [signerAddressError, setSignerAddressError] = useState('')
const [uncaughtError, setUncaughtError] = useState('')
const [fetchingTxDetails, setFetchingTxDetails] = useState(false)
const [mPoolPushing, setMPoolPushing] = useState(false)
const [gasError, setGasError] = useState('')
const [gasInfo, setGasInfo] = useState(emptyGasInfo)
const [frozen, setFrozen] = useState(false)
const router = useRouter()

const onClose = useCallback(() => {
navigate(router, { pageUrl: PAGE.MSIG_ADMIN })
}, [router])

const onComplete = useCallback(() => {
navigate(router, { pageUrl: PAGE.MSIG_HISTORY })
}, [router])

const constructMsg = (nonce = 0) => {
const innerParams = {
to: toAddress,
from: wallet.address
signer: signerAddress,
increase: false
}

const serializedInnerParams = Buffer.from(
Expand All @@ -66,7 +73,7 @@ const ChangeOwner = ({ address, balance, close }) => {
const outerParams = {
to: address,
value: '0',
method: 7,
method: MSIG_METHOD.ADD_SIGNER,
params: serializedInnerParams
}

Expand All @@ -79,15 +86,15 @@ const ChangeOwner = ({ address, balance, close }) => {
to: address,
from: wallet.address,
value: '0',
method: 2,
method: MSIG_METHOD.PROPOSE,
nonce,
params: serializedOuterParams,
gasFeeCap: gasInfo.gasFeeCap.toAttoFil(),
gasLimit: new BigNumber(gasInfo.gasLimit.toAttoFil()).toNumber(),
gasPremium: gasInfo.gasPremium.toAttoFil()
})

return { message, params: { ...innerParams, params: outerParams } }
return { message, params: { ...outerParams, params: { ...innerParams } } }
}

const sendMsg = async () => {
Expand Down Expand Up @@ -127,9 +134,9 @@ const ChangeOwner = ({ address, balance, close }) => {
e.preventDefault()
if (step === 1) {
setStep(2)
} else if (step === 2 && !validateAddressString(toAddress)) {
setToAddressError('Invalid to address')
} else if (step === 2 && validateAddressString(toAddress)) {
} else if (step === 2 && !validateAddressString(signerAddress)) {
setSignerAddressError('Invalid address')
} else if (step === 2 && validateAddressString(signerAddress)) {
setStep(3)
} else if (step === 3) {
setAttemptingTx(true)
Expand All @@ -138,7 +145,7 @@ const ChangeOwner = ({ address, balance, close }) => {
setAttemptingTx(false)
if (msg) {
dispatch(confirmMessage(toLowerCaseMsgFields(msg)))
close()
onComplete()
}
} catch (err) {
if (err.message.includes('19')) {
Expand Down Expand Up @@ -200,7 +207,7 @@ const ChangeOwner = ({ address, balance, close }) => {
setAttemptingTx(false)
setUncaughtError('')
resetLedgerState()
close()
onClose()
}}
/>
<Form onSubmit={onSubmit}>
Expand All @@ -211,7 +218,6 @@ const ChangeOwner = ({ address, balance, close }) => {
display='flex'
flexDirection='column'
justifyContent='flex-start'
flexGrow='1'
>
<Box>
{hasLedgerError({ ...ledger, otherError: uncaughtError }) && (
Expand Down Expand Up @@ -250,16 +256,13 @@ const ChangeOwner = ({ address, balance, close }) => {
my={2}
backgroundColor='blue.muted700'
>
<StepHeader
title='Change Ownership'
currentStep={step}
totalSteps={4}
glyphAcronym='Ch'
<AddRmSignerHeader
step={step}
method={MSIG_METHOD.ADD_SIGNER}
/>
<ChangeOwnerHeaderText step={step} />
</Card>
)}
{step === 1 && <Preface />}
{step === 1 && <Preface method={MSIG_METHOD.ADD_SIGNER} />}
<Box boxShadow={2} borderRadius={4}>
{step > 1 && (
<>
Expand All @@ -270,45 +273,41 @@ const ChangeOwner = ({ address, balance, close }) => {
signerBalance={wallet.balance}
/>
<Box width='100%' p={3} border={0} bg='background.screen'>
<Input.Address
label='New owner'
value={toAddress}
onChange={e => setToAddress(e.target.value)}
error={toAddressError}
disabled={step === 3}
onFocus={() => {
if (toAddressError) setToAddressError('')
}}
<AddSignerInput
signerAddress={signerAddress}
setSignerAddress={setSignerAddress}
signerAddressError={signerAddressError}
setSignerAddressError={setSignerAddressError}
step={step}
/>
</Box>
{step > 2 && (
<Box
display='flex'
flexDirection='row'
justifyContent='space-between'
width='100%'
p={3}
border={0}
bg='background.screen'
>
<CustomizeFee
message={constructMsg().message.toLotusType()}
gasInfo={gasInfo}
setGasInfo={setGasInfo}
setFrozen={setFrozen}
setError={setGasError}
error={gasError}
feeMustBeLessThanThisAmount={wallet.balance}
/>
</Box>
)}
</>
)}
{step > 2 && (
<Box
display='flex'
flexDirection='row'
justifyContent='space-between'
width='100%'
p={3}
border={0}
bg='background.screen'
>
<CustomizeFee
message={constructMsg().message.toLotusType()}
gasInfo={gasInfo}
setGasInfo={setGasInfo}
setFrozen={setFrozen}
setError={setGasError}
error={gasError}
feeMustBeLessThanThisAmount={wallet.balance}
/>
</Box>
)}
</Box>
</Box>
<Box
display='flex'
flex='1'
flexDirection='row'
justifyContent='space-between'
alignItems='flex-end'
Expand All @@ -317,7 +316,7 @@ const ChangeOwner = ({ address, balance, close }) => {
width='100%'
minWidth={11}
maxHeight={12}
my={3}
py={4}
>
<Button
title='Back'
Expand All @@ -328,7 +327,7 @@ const ChangeOwner = ({ address, balance, close }) => {
setGasError('')
resetLedgerState()
if (step === 1) {
close()
onClose()
} else {
setStep(step - 1)
}
Expand All @@ -348,10 +347,4 @@ const ChangeOwner = ({ address, balance, close }) => {
)
}

ChangeOwner.propTypes = {
address: ADDRESS_PROPTYPE,
balance: FILECOIN_NUMBER_PROP,
close: PropTypes.func.isRequired
}

export default ChangeOwner
export default AddSigner
Loading