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
22990d6a
Commit
22990d6a
authored
Jun 07, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove contract context
parent
058575d9
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
62 deletions
+26
-62
AddressContract.tsx
ui/address/AddressContract.tsx
+4
-9
ContractWrite.tsx
ui/address/contract/ContractWrite.tsx
+5
-16
useContractAbi.tsx
ui/address/contract/useContractAbi.tsx
+14
-34
Address.tsx
ui/pages/Address.tsx
+2
-2
Token.tsx
ui/pages/Token.tsx
+1
-1
No files found.
ui/address/AddressContract.tsx
View file @
22990d6a
...
...
@@ -2,7 +2,6 @@ import React from 'react';
import
type
{
RoutedSubTab
}
from
'
ui/shared/Tabs/types
'
;
import
{
ContractContextProvider
}
from
'
ui/address/contract/context
'
;
import
RoutedTabs
from
'
ui/shared/Tabs/RoutedTabs
'
;
import
Web3ModalProvider
from
'
ui/shared/Web3ModalProvider
'
;
...
...
@@ -15,21 +14,17 @@ const TAB_LIST_PROPS = {
columnGap
:
3
,
};
const
AddressContract
=
({
addressHash
,
tabs
}:
Props
)
=>
{
const
AddressContract
=
({
tabs
}:
Props
)
=>
{
const
fallback
=
React
.
useCallback
(()
=>
{
const
noProviderTabs
=
tabs
.
filter
(({
id
})
=>
id
===
'
contact_code
'
);
return
(
<
ContractContextProvider
addressHash=
{
addressHash
}
>
<
RoutedTabs
tabs=
{
noProviderTabs
}
variant=
"outline"
colorScheme=
"gray"
size=
"sm"
tabListProps=
{
TAB_LIST_PROPS
}
/>
</
ContractContextProvider
>
);
},
[
addressHash
,
tabs
]);
},
[
tabs
]);
return
(
<
Web3ModalProvider
fallback=
{
fallback
}
>
<
ContractContextProvider
addressHash=
{
addressHash
}
>
<
RoutedTabs
tabs=
{
tabs
}
variant=
"outline"
colorScheme=
"gray"
size=
"sm"
tabListProps=
{
TAB_LIST_PROPS
}
/>
</
ContractContextProvider
>
</
Web3ModalProvider
>
);
};
...
...
ui/address/contract/ContractWrite.tsx
View file @
22990d6a
...
...
@@ -9,12 +9,12 @@ import ContractMethodsAccordion from 'ui/address/contract/ContractMethodsAccordi
import
ContentLoader
from
'
ui/shared/ContentLoader
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
{
useContractContext
}
from
'
./context
'
;
import
ContractConnectWallet
from
'
./ContractConnectWallet
'
;
import
ContractCustomAbiAlert
from
'
./ContractCustomAbiAlert
'
;
import
ContractImplementationAddress
from
'
./ContractImplementationAddress
'
;
import
ContractMethodCallable
from
'
./ContractMethodCallable
'
;
import
ContractWriteResult
from
'
./ContractWriteResult
'
;
import
useContractAbi
from
'
./useContractAbi
'
;
import
{
getNativeCoinValue
}
from
'
./utils
'
;
interface
Props
{
...
...
@@ -39,18 +39,7 @@ const ContractWrite = ({ addressHash, isProxy, isCustomAbi }: Props) => {
},
});
const
{
contractInfo
,
customInfo
,
proxyInfo
}
=
useContractContext
();
const
abi
=
(()
=>
{
if
(
isProxy
)
{
return
proxyInfo
?.
abi
;
}
if
(
isCustomAbi
)
{
return
customInfo
?.
abi
;
}
return
contractInfo
?.
abi
;
})();
const
contractAbi
=
useContractAbi
({
addressHash
,
isProxy
,
isCustomAbi
});
const
handleMethodFormSubmit
=
React
.
useCallback
(
async
(
item
:
SmartContractWriteMethod
,
args
:
Array
<
string
|
Array
<
unknown
>>
)
=>
{
if
(
!
isConnected
)
{
...
...
@@ -61,7 +50,7 @@ const ContractWrite = ({ addressHash, isProxy, isCustomAbi }: Props) => {
await
switchNetworkAsync
?.(
Number
(
config
.
network
.
id
));
}
if
(
!
a
bi
)
{
if
(
!
contractA
bi
)
{
throw
new
Error
(
'
Something went wrong. Try again later.
'
);
}
...
...
@@ -84,14 +73,14 @@ const ContractWrite = ({ addressHash, isProxy, isCustomAbi }: Props) => {
const
hash
=
await
walletClient
?.
writeContract
({
args
:
_args
,
abi
:
a
bi
,
abi
:
contractA
bi
,
functionName
:
methodName
,
address
:
addressHash
as
`0x
${
string
}
`
,
value
:
value
as
undefined
,
});
return
{
hash
};
},
[
isConnected
,
chain
,
a
bi
,
walletClient
,
addressHash
,
switchNetworkAsync
]);
},
[
isConnected
,
chain
,
contractA
bi
,
walletClient
,
addressHash
,
switchNetworkAsync
]);
const
renderContent
=
React
.
useCallback
((
item
:
SmartContractWriteMethod
,
index
:
number
,
id
:
number
)
=>
{
return
(
...
...
ui/address/contract/
context
.tsx
→
ui/address/contract/
useContractAbi
.tsx
View file @
22990d6a
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
type
{
Abi
}
from
'
abitype
'
;
import
React
from
'
react
'
;
import
type
{
Address
}
from
'
types/api/address
'
;
import
type
{
SmartContract
}
from
'
types/api/contract
'
;
import
useApiQuery
,
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
type
ProviderProps
=
{
interface
Params
{
addressHash
?:
string
;
children
:
React
.
ReactNode
;
isProxy
?:
boolean
;
isCustomAbi
?:
boolean
;
}
type
TContractContext
=
{
contractInfo
:
SmartContract
|
undefined
;
proxyInfo
:
SmartContract
|
undefined
;
customInfo
:
SmartContract
|
undefined
;
};
const
ContractContext
=
React
.
createContext
<
TContractContext
>
({
proxyInfo
:
undefined
,
contractInfo
:
undefined
,
customInfo
:
undefined
,
});
export
function
ContractContextProvider
({
addressHash
,
children
}:
ProviderProps
)
{
export
default
function
useContractAbi
({
addressHash
,
isProxy
,
isCustomAbi
}:
Params
):
Abi
|
undefined
{
const
queryClient
=
useQueryClient
();
const
{
data
:
contractInfo
}
=
useApiQuery
(
'
contract
'
,
{
...
...
@@ -46,7 +35,6 @@ export function ContractContextProvider({ addressHash, children }: ProviderProps
},
});
// todo_tom check custom abi case
const
{
data
:
customInfo
}
=
useApiQuery
(
'
contract_methods_write
'
,
{
pathParams
:
{
hash
:
addressHash
},
queryParams
:
{
is_custom_abi
:
'
true
'
},
...
...
@@ -56,23 +44,15 @@ export function ContractContextProvider({ addressHash, children }: ProviderProps
},
});
const
value
=
React
.
useMemo
(()
=>
({
proxyInfo
,
contractInfo
,
customInfo
,
}
as
TContractContext
),
[
proxyInfo
,
contractInfo
,
customInfo
]);
return
(
<
ContractContext
.
Provider
value=
{
value
}
>
{
children
}
</
ContractContext
.
Provider
>
);
}
return
React
.
useMemo
(()
=>
{
if
(
isProxy
)
{
return
proxyInfo
?.
abi
??
undefined
;
}
export
function
useContractContext
()
{
const
context
=
React
.
useContext
(
ContractContext
);
if
(
context
===
undefined
)
{
throw
new
Error
(
'
useContractContext must be used within a ContractContextProvider
'
);
if
(
isCustomAbi
)
{
return
customInfo
;
}
return
context
;
return
contractInfo
?.
abi
??
undefined
;
},
[
contractInfo
?.
abi
,
customInfo
,
isCustomAbi
,
isProxy
,
proxyInfo
?.
abi
]);
}
ui/pages/Address.tsx
View file @
22990d6a
...
...
@@ -86,11 +86,11 @@ const AddressPageContent = () => {
return
'
Contract
'
;
},
component
:
<
AddressContract
tabs=
{
contractTabs
}
addressHash=
{
hash
}
/>,
component
:
<
AddressContract
tabs=
{
contractTabs
}
/>,
subTabs
:
contractTabs
.
map
(
tab
=>
tab
.
id
),
}
:
undefined
,
].
filter
(
Boolean
);
},
[
addressQuery
.
data
,
contractTabs
,
hash
]);
},
[
addressQuery
.
data
,
contractTabs
]);
const
tags
=
(
<
EntityTags
...
...
ui/pages/Token.tsx
View file @
22990d6a
...
...
@@ -178,7 +178,7 @@ const TokenPageContent = () => {
return 'Contract';
},
component: <AddressContract tabs={ contractTabs }
addressHash={ hashString }
/>,
component: <AddressContract tabs={ contractTabs }/>,
subTabs: contractTabs.map(tab => tab.id),
} : undefined,
].filter(Boolean);
...
...
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