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
9faebc10
Commit
9faebc10
authored
Jul 19, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hotfix: filter out unmatched contract method signatures
parent
cc644b71
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
2 deletions
+110
-2
ContractWrite.tsx
ui/address/contract/ContractWrite.tsx
+3
-2
utils.test.ts
ui/address/contract/utils.test.ts
+78
-0
utils.ts
ui/address/contract/utils.ts
+29
-0
No files found.
ui/address/contract/ContractWrite.tsx
View file @
9faebc10
...
...
@@ -15,7 +15,7 @@ import ContractImplementationAddress from './ContractImplementationAddress';
import
ContractMethodCallable
from
'
./ContractMethodCallable
'
;
import
ContractWriteResult
from
'
./ContractWriteResult
'
;
import
useContractAbi
from
'
./useContractAbi
'
;
import
{
getNativeCoinValue
}
from
'
./utils
'
;
import
{
getNativeCoinValue
,
prepareAbi
}
from
'
./utils
'
;
interface
Props
{
addressHash
?:
string
;
...
...
@@ -71,9 +71,10 @@ const ContractWrite = ({ addressHash, isProxy, isCustomAbi }: Props) => {
throw
new
Error
(
'
Method name is not defined
'
);
}
const
abi
=
prepareAbi
(
contractAbi
,
item
);
const
hash
=
await
walletClient
?.
writeContract
({
args
:
_args
,
abi
:
contractAbi
,
abi
,
functionName
:
methodName
,
address
:
addressHash
as
`0x
${
string
}
`
,
value
:
value
as
undefined
,
...
...
ui/address/contract/utils.test.ts
0 → 100644
View file @
9faebc10
import
{
prepareAbi
}
from
'
./utils
'
;
describe
(
'
function prepareAbi()
'
,
()
=>
{
const
commonAbi
=
[
{
inputs
:
[
{
internalType
:
'
address
'
,
name
:
'
_pool
'
,
type
:
'
address
'
},
{
internalType
:
'
address
'
,
name
:
'
_token
'
,
type
:
'
address
'
},
{
internalType
:
'
uint256
'
,
name
:
'
_denominator
'
,
type
:
'
uint256
'
},
],
stateMutability
:
'
nonpayable
'
as
const
,
type
:
'
constructor
'
as
const
,
},
{
anonymous
:
false
,
inputs
:
[
{
indexed
:
false
,
internalType
:
'
uint256[]
'
,
name
:
'
indices
'
,
type
:
'
uint256[]
'
},
],
name
:
'
CompleteDirectDepositBatch
'
,
type
:
'
event
'
as
const
,
},
{
inputs
:
[
{
internalType
:
'
address
'
,
name
:
'
_fallbackUser
'
,
type
:
'
address
'
},
{
internalType
:
'
string
'
,
name
:
'
_zkAddress
'
,
type
:
'
string
'
},
],
name
:
'
directNativeDeposit
'
,
outputs
:
[
{
internalType
:
'
uint256
'
,
name
:
''
,
type
:
'
uint256
'
},
],
stateMutability
:
'
payable
'
as
const
,
type
:
'
function
'
as
const
,
},
];
const
method
=
{
inputs
:
[
{
internalType
:
'
address
'
as
const
,
name
:
'
_fallbackUser
'
,
type
:
'
address
'
as
const
},
{
internalType
:
'
string
'
as
const
,
name
:
'
_zkAddress
'
,
type
:
'
string
'
as
const
},
],
name
:
'
directNativeDeposit
'
,
outputs
:
[
{
internalType
:
'
uint256
'
as
const
,
name
:
''
,
type
:
'
uint256
'
as
const
},
],
stateMutability
:
'
payable
'
as
const
,
type
:
'
function
'
as
const
,
constant
:
false
,
payable
:
true
,
};
it
(
'
if there is only one method with provided name, does nothing
'
,
()
=>
{
const
abi
=
prepareAbi
(
commonAbi
,
method
);
expect
(
abi
).
toHaveLength
(
commonAbi
.
length
);
});
it
(
'
if there are two or more methods with the same name, filters out those which inputs are not matched
'
,
()
=>
{
const
abi
=
prepareAbi
([
...
commonAbi
,
{
inputs
:
[
{
internalType
:
'
address
'
,
name
:
'
_fallbackUser
'
,
type
:
'
address
'
},
{
internalType
:
'
bytes
'
,
name
:
'
_rawZkAddress
'
,
type
:
'
bytes
'
},
],
name
:
'
directNativeDeposit
'
,
outputs
:
[
{
internalType
:
'
uint256
'
,
name
:
''
,
type
:
'
uint256
'
},
],
stateMutability
:
'
payable
'
,
type
:
'
function
'
,
},
],
method
);
expect
(
abi
).
toHaveLength
(
commonAbi
.
length
);
const
item
=
abi
.
find
((
item
)
=>
'
name
'
in
item
?
item
.
name
===
method
.
name
:
false
);
expect
(
item
).
toEqual
(
commonAbi
[
2
]);
});
});
ui/address/contract/utils.ts
View file @
9faebc10
import
type
{
Abi
}
from
'
abitype
'
;
import
type
{
SmartContractWriteMethod
}
from
'
types/api/contract
'
;
export
const
getNativeCoinValue
=
(
value
:
string
|
Array
<
unknown
>
)
=>
{
const
_value
=
Array
.
isArray
(
value
)
?
value
[
0
]
:
value
;
...
...
@@ -42,3 +46,28 @@ export function isExtendedError(error: unknown): error is ExtendedError {
typeof
(
error
as
Record
<
string
,
unknown
>
).
message
===
'
string
'
);
}
export
function
prepareAbi
(
abi
:
Abi
,
item
:
SmartContractWriteMethod
):
Abi
{
if
(
'
name
'
in
item
)
{
const
hasMethodsWithSameName
=
abi
.
filter
((
abiItem
)
=>
'
name
'
in
abiItem
?
abiItem
.
name
===
item
.
name
:
false
).
length
>
1
;
if
(
hasMethodsWithSameName
)
{
return
abi
.
filter
((
abiItem
)
=>
{
if
(
!
(
'
name
'
in
abiItem
))
{
return
true
;
}
if
(
abiItem
.
name
!==
item
.
name
)
{
return
true
;
}
return
abiItem
.
inputs
.
every
(({
name
,
type
})
=>
{
const
itemInput
=
item
.
inputs
.
find
((
input
)
=>
input
.
name
===
name
);
return
Boolean
(
itemInput
)
&&
itemInput
?.
type
===
type
;
});
});
}
}
return
abi
;
}
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