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