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
9538e63c
Unverified
Commit
9538e63c
authored
Mar 04, 2024
by
Max Alekseenko
Committed by
GitHub
Mar 04, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1639 from blockscout/mixpanel-events-in-dapps
Add mixpanel events to operations in dapps
parents
1d91b29e
8a7cb463
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
10 deletions
+26
-10
utils.ts
lib/mixpanel/utils.ts
+9
-3
useMarketplaceWallet.tsx
ui/marketplace/useMarketplaceWallet.tsx
+15
-4
MarketplaceApp.tsx
ui/pages/MarketplaceApp.tsx
+2
-3
No files found.
lib/mixpanel/utils.ts
View file @
9538e63c
...
...
@@ -74,9 +74,15 @@ Type extends EventTypes.WALLET_CONNECT ? {
'
Source
'
:
'
Header
'
|
'
Smart contracts
'
|
'
Swap button
'
;
'
Status
'
:
'
Started
'
|
'
Connected
'
;
}
:
Type
extends
EventTypes
.
WALLET_ACTION
?
{
'
Action
'
:
'
Open
'
|
'
Address click
'
;
}
:
Type
extends
EventTypes
.
WALLET_ACTION
?
(
{
'
Action
'
:
'
Open
'
|
'
Address click
'
;
}
|
{
'
Action
'
:
'
Send Transaction
'
|
'
Sign Message
'
|
'
Sign Typed Data
'
;
'
Address
'
:
string
|
undefined
;
'
AppId
'
:
string
;
}
)
:
Type
extends
EventTypes
.
CONTRACT_INTERACTION
?
{
'
Method type
'
:
'
Read
'
|
'
Write
'
;
'
Method name
'
:
string
;
...
...
ui/marketplace/useMarketplaceWallet.tsx
View file @
9538e63c
...
...
@@ -4,6 +4,7 @@ import type { Account, SignTypedDataParameters } from 'viem';
import
{
useAccount
,
useSendTransaction
,
useSwitchNetwork
,
useNetwork
,
useSignMessage
,
useSignTypedData
}
from
'
wagmi
'
;
import
config
from
'
configs/app
'
;
import
*
as
mixpanel
from
'
lib/mixpanel/index
'
;
type
SendTransactionArgs
=
{
chainId
?:
number
;
...
...
@@ -20,7 +21,7 @@ export type SignTypedDataArgs<
TPrimaryType
extends
string
=
string
,
>
=
SignTypedDataParameters
<
TTypedData
,
TPrimaryType
,
Account
>
;
export
default
function
useMarketplaceWallet
()
{
export
default
function
useMarketplaceWallet
(
appId
:
string
)
{
const
{
address
}
=
useAccount
();
const
{
chain
}
=
useNetwork
();
const
{
sendTransactionAsync
}
=
useSendTransaction
();
...
...
@@ -28,6 +29,13 @@ export default function useMarketplaceWallet() {
const
{
signTypedDataAsync
}
=
useSignTypedData
();
const
{
switchNetworkAsync
}
=
useSwitchNetwork
({
chainId
:
Number
(
config
.
chain
.
id
)
});
const
logEvent
=
useCallback
((
event
:
mixpanel
.
EventPayload
<
mixpanel
.
EventTypes
.
WALLET_ACTION
>
[
'
Action
'
])
=>
{
mixpanel
.
logEvent
(
mixpanel
.
EventTypes
.
WALLET_ACTION
,
{
Action
:
event
,
Address
:
address
,
AppId
:
appId
},
);
},
[
address
,
appId
]);
const
switchNetwork
=
useCallback
(
async
()
=>
{
if
(
Number
(
config
.
chain
.
id
)
!==
chain
?.
id
)
{
await
switchNetworkAsync
?.();
...
...
@@ -37,14 +45,16 @@ export default function useMarketplaceWallet() {
const
sendTransaction
=
useCallback
(
async
(
transaction
:
SendTransactionArgs
)
=>
{
await
switchNetwork
();
const
tx
=
await
sendTransactionAsync
(
transaction
);
logEvent
(
'
Send Transaction
'
);
return
tx
.
hash
;
},
[
sendTransactionAsync
,
switchNetwork
]);
},
[
sendTransactionAsync
,
switchNetwork
,
logEvent
]);
const
signMessage
=
useCallback
(
async
(
message
:
string
)
=>
{
await
switchNetwork
();
const
signature
=
await
signMessageAsync
({
message
});
logEvent
(
'
Sign Message
'
);
return
signature
;
},
[
signMessageAsync
,
switchNetwork
]);
},
[
signMessageAsync
,
switchNetwork
,
logEvent
]);
const
signTypedData
=
useCallback
(
async
(
typedData
:
SignTypedDataArgs
)
=>
{
await
switchNetwork
();
...
...
@@ -52,8 +62,9 @@ export default function useMarketplaceWallet() {
typedData
.
domain
.
chainId
=
Number
(
typedData
.
domain
.
chainId
);
}
const
signature
=
await
signTypedDataAsync
(
typedData
);
logEvent
(
'
Sign Typed Data
'
);
return
signature
;
},
[
signTypedDataAsync
,
switchNetwork
]);
},
[
signTypedDataAsync
,
switchNetwork
,
logEvent
]);
return
{
address
,
...
...
ui/pages/MarketplaceApp.tsx
View file @
9538e63c
...
...
@@ -97,13 +97,12 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => {
};
const
MarketplaceApp
=
()
=>
{
const
{
address
,
sendTransaction
,
signMessage
,
signTypedData
}
=
useMarketplaceWallet
();
useAutoConnectWallet
();
const
fetch
=
useFetch
();
const
apiFetch
=
useApiFetch
();
const
router
=
useRouter
();
const
id
=
getQueryParamString
(
router
.
query
.
id
);
const
{
address
,
sendTransaction
,
signMessage
,
signTypedData
}
=
useMarketplaceWallet
(
id
);
useAutoConnectWallet
();
const
query
=
useQuery
<
unknown
,
ResourceError
<
unknown
>
,
MarketplaceAppOverview
>
({
queryKey
:
[
'
marketplace-dapps
'
,
id
],
...
...
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