Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
cc56187a
Commit
cc56187a
authored
May 30, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix write contract
parent
8d9b3f49
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
54 deletions
+32
-54
ContractWrite.tsx
ui/address/contract/ContractWrite.tsx
+17
-14
context.tsx
ui/address/contract/context.tsx
+11
-35
utils.ts
ui/address/contract/utils.ts
+2
-4
Web3ModalProvider.tsx
ui/shared/Web3ModalProvider.tsx
+2
-1
No files found.
ui/address/contract/ContractWrite.tsx
View file @
cc56187a
...
...
@@ -39,17 +39,17 @@ const ContractWrite = ({ addressHash, isProxy, isCustomAbi }: Props) => {
},
});
const
{
contract
,
proxy
,
custom
}
=
useContractContext
();
const
_contract
=
(()
=>
{
const
{
contract
Info
,
customInfo
,
proxyInfo
}
=
useContractContext
();
const
abi
=
(()
=>
{
if
(
isProxy
)
{
return
proxy
;
return
proxy
Info
?.
abi
;
}
if
(
isCustomAbi
)
{
return
custom
;
return
custom
Info
?.
abi
;
}
return
contract
;
return
contract
Info
?.
abi
;
})();
const
handleMethodFormSubmit
=
React
.
useCallback
(
async
(
item
:
SmartContractWriteMethod
,
args
:
Array
<
string
|
Array
<
unknown
>>
)
=>
{
...
...
@@ -61,34 +61,37 @@ const ContractWrite = ({ addressHash, isProxy, isCustomAbi }: Props) => {
await
switchNetworkAsync
?.(
Number
(
config
.
network
.
id
));
}
if
(
!
_contract
)
{
if
(
!
abi
)
{
throw
new
Error
(
'
Something went wrong. Try again later.
'
);
}
if
(
item
.
type
===
'
receive
'
)
{
const
value
=
args
[
0
]
?
getNativeCoinValue
(
args
[
0
])
:
'
0
'
;
if
(
item
.
type
===
'
receive
'
||
item
.
type
===
'
fallback
'
)
{
const
value
=
getNativeCoinValue
(
args
[
0
])
;
const
hash
=
await
walletClient
?.
sendTransaction
({
to
:
addressHash
as
`0x
${
string
}
`
|
undefined
,
value
:
BigInt
(
value
),
// todo_tom simplify this
value
,
});
return
{
hash
};
}
const
_args
=
'
stateMutability
'
in
item
&&
item
.
stateMutability
===
'
payable
'
?
args
.
slice
(
0
,
-
1
)
:
args
;
const
value
=
'
stateMutability
'
in
item
&&
item
.
stateMutability
===
'
payable
'
?
getNativeCoinValue
(
args
[
args
.
length
-
1
])
:
undefined
;
const
methodName
=
item
.
type
===
'
fallback
'
?
'
fallback
'
:
item
.
name
;
const
methodName
=
item
.
name
;
if
(
!
methodName
)
{
throw
new
Error
(
'
Method name is not defined
'
);
}
const
hash
=
await
_contract
.
write
[
methodName
](...
_args
,
{
gasLimit
:
100
_000
,
value
,
const
hash
=
await
walletClient
?.
writeContract
({
args
:
_args
,
abi
:
abi
,
functionName
:
methodName
,
address
:
addressHash
as
`0x
${
string
}
`
,
value
:
value
as
undefined
,
});
return
{
hash
};
},
[
_contract
,
addressHash
,
chain
,
isConnected
,
walletClient
,
switchNetworkAsync
]);
},
[
isConnected
,
chain
,
abi
,
walletClient
,
addressHash
,
switchNetworkAsync
]);
const
renderContent
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
index
:
number
,
id
:
number
)
=>
{
return
(
...
...
ui/address/contract/context.tsx
View file @
cc56187a
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
type
{
Abi
}
from
'
abitype
'
;
import
React
from
'
react
'
;
import
type
{
WalletClient
}
from
'
wagmi
'
;
import
{
useWalletClient
}
from
'
wagmi
'
;
import
type
{
GetContractResult
}
from
'
wagmi/actions
'
;
import
{
getContract
}
from
'
wagmi/actions
'
;
import
type
{
Address
}
from
'
types/api/address
'
;
import
type
{
SmartContract
}
from
'
types/api/contract
'
;
import
useApiQuery
,
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
...
...
@@ -16,19 +12,18 @@ type ProviderProps = {
}
type
TContractContext
=
{
contract
:
GetContractResult
<
Abi
,
WalletClient
>
|
undefined
;
proxy
:
GetContractResult
<
Abi
,
WalletClient
>
|
undefined
;
custom
:
GetContractResult
<
Abi
,
WalletClient
>
|
undefined
;
contract
Info
:
SmartContract
|
undefined
;
proxy
Info
:
SmartContract
|
undefined
;
custom
Info
:
SmartContract
|
undefined
;
};
const
ContractContext
=
React
.
createContext
<
TContractContext
>
({
contract
:
undefined
,
proxy
:
undefined
,
custom
:
undefined
,
proxyInfo
:
undefined
,
contractInfo
:
undefined
,
custom
Info
:
undefined
,
});
export
function
ContractContextProvider
({
addressHash
,
children
}:
ProviderProps
)
{
const
{
data
:
walletClient
}
=
useWalletClient
();
const
queryClient
=
useQueryClient
();
const
{
data
:
contractInfo
}
=
useApiQuery
(
'
contract
'
,
{
...
...
@@ -60,30 +55,11 @@ export function ContractContextProvider({ addressHash, children }: ProviderProps
},
});
const
contract
=
addressHash
&&
contractInfo
?.
abi
?
getContract
({
address
:
addressHash
as
`0x
${
string
}
`
,
abi
:
contractInfo
?.
abi
??
undefined
,
walletClient
:
walletClient
??
undefined
,
})
:
undefined
;
const
proxy
=
addressInfo
?.
implementation_address
&&
proxyInfo
?.
abi
?
getContract
({
address
:
addressInfo
?.
implementation_address
as
`0x
${
string
}
`
,
abi
:
proxyInfo
?.
abi
,
walletClient
:
walletClient
??
undefined
,
})
:
undefined
;
const
custom
=
addressHash
&&
customInfo
?
getContract
({
address
:
addressHash
as
`0x
${
string
}
`
,
abi
:
customInfo
,
walletClient
:
walletClient
??
undefined
,
})
:
undefined
;
const
value
=
React
.
useMemo
(()
=>
({
contract
,
proxy
,
custom
,
// todo_tom fix this
}
as
TContractContext
),
[
contract
,
proxy
,
custom
]);
proxyInfo
,
contractInfo
,
customInfo
,
}
as
TContractContext
),
[
proxyInfo
,
contractInfo
,
customInfo
]);
return
(
<
ContractContext
.
Provider
value=
{
value
}
>
...
...
ui/address/contract/utils.ts
View file @
cc56187a
import
BigNumber
from
'
bignumber.js
'
;
import
config
from
'
configs/app/config
'
;
export
const
getNativeCoinValue
=
(
value
:
string
|
Array
<
unknown
>
)
=>
{
const
_value
=
Array
.
isArray
(
value
)
?
value
[
0
]
:
value
;
if
(
typeof
_value
!==
'
string
'
)
{
return
'
0
'
;
return
BigInt
(
0
)
;
}
return
Big
Number
(
_value
).
times
(
10
**
config
.
network
.
currency
.
decimals
).
toString
(
);
return
Big
Int
(
Number
(
_value
)
*
10
**
config
.
network
.
currency
.
decimals
);
};
export
const
addZeroesAllowed
=
(
valueType
:
string
)
=>
{
...
...
ui/shared/Web3ModalProvider.tsx
View file @
cc56187a
...
...
@@ -56,11 +56,12 @@ const getConfig = () => {
}
};
const
{
wagmiConfig
,
ethereumClient
}
=
getConfig
();
interface
Props
{
children
:
React
.
ReactNode
;
fallback
?:
JSX
.
Element
|
(()
=>
JSX
.
Element
);
}
const
{
wagmiConfig
,
ethereumClient
}
=
getConfig
();
const
Web3ModalProvider
=
({
children
,
fallback
}:
Props
)
=>
{
const
modalZIndex
=
useToken
<
string
>
(
'
zIndices
'
,
'
modal
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment