-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'polygon-prototype-staging' into 58-dump-signed-transact…
…ions-for-manual-resolution
- Loading branch information
Showing
18 changed files
with
340 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React from 'preact/compat'; | ||
|
||
export enum EventStatus { | ||
Success = 'success', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import AccountBalanceWalletOutlinedIcon from '@mui/icons-material/AccountBalanceWalletOutlined'; | ||
import { Progress } from 'react-daisyui'; | ||
import { FC } from 'preact/compat'; | ||
|
||
import { SigningPhase } from '../../hooks/useMainProcess'; | ||
|
||
const progressValues: Record<SigningPhase, string> = { | ||
started: '25', | ||
approved: '50', | ||
signed: '75', | ||
finished: '100', | ||
}; | ||
|
||
function getProgressValue(step: SigningPhase): string { | ||
return progressValues[step] || '0'; | ||
} | ||
|
||
function getSignatureNumber(step: SigningPhase): string { | ||
return step === 'started' ? '1' : '2'; | ||
} | ||
|
||
interface SigningBoxProps { | ||
step?: SigningPhase; | ||
} | ||
|
||
export const SigningBox: FC<SigningBoxProps> = ({ step }) => { | ||
if (!step) return <></>; | ||
if (step !== 'started' && step !== 'approved' && step !== 'signed') return <></>; | ||
|
||
return ( | ||
<section className="toast toast-end"> | ||
<div className="shadow-2xl"> | ||
<header className="bg-pink-500 rounded-t"> | ||
<h1 className="w-full py-2 text-center text-white">Action Required</h1> | ||
</header> | ||
<main className="px-8 bg-white"> | ||
<div className="flex items-center justify-center"> | ||
<div className="flex items-center justify-center w-10 h-10 border rounded-full border-primary"> | ||
<AccountBalanceWalletOutlinedIcon className="text-primary" /> | ||
</div> | ||
<div className="mx-4 my-5 text-xs"> | ||
<p>Please sign the transaction in</p> | ||
<p>your connected wallet to proceed</p> | ||
</div> | ||
</div> | ||
<div className="w-full mb-2.5"> | ||
<Progress | ||
value={getProgressValue(step)} | ||
max="100" | ||
className="h-4 bg-white border progress-primary border-primary" | ||
/> | ||
</div> | ||
</main> | ||
<footer className="flex items-center justify-center bg-[#5E88D5] text-white rounded-b"> | ||
<span className="loading loading-spinner loading-sm"></span> | ||
<p className="ml-2.5 my-2 text-xs">Waiting for signature {getSignatureNumber(step)}/2</p> | ||
</footer> | ||
</div> | ||
</section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { createContext } from 'preact'; | ||
import { PropsWithChildren, useCallback, useContext, useEffect, useRef, useState } from 'preact/compat'; | ||
import { useAccount } from 'wagmi'; | ||
import { INPUT_TOKEN_CONFIG, OUTPUT_TOKEN_CONFIG } from '../constants/tokenConfig'; | ||
import { OfframpingState } from '../services/offrampingFlow'; | ||
|
||
declare global { | ||
interface Window { | ||
dataLayer: Record<string, any>[]; | ||
} | ||
} | ||
|
||
const UNIQUE_EVENT_TYPES = ['amount_type', 'click_details', 'click_support']; | ||
|
||
export interface AmountTypeEvent { | ||
event: `amount_type`; | ||
} | ||
|
||
export interface ClickDetailsEvent { | ||
event: 'click_details'; | ||
} | ||
|
||
export interface WalletConnectEvent { | ||
event: 'wallet_connect'; | ||
wallet_action: 'connect' | 'disconnect' | 'change'; | ||
} | ||
|
||
export interface TransactionEvent { | ||
event: 'transaction_confirmation' | 'kyc_completed' | 'transaction_success' | 'transaction_failure'; | ||
from_asset: string; | ||
to_asset: string; | ||
from_amount: string; | ||
to_amount: string; | ||
} | ||
|
||
export interface ClickSupportEvent { | ||
event: 'click_support'; | ||
transaction_status: 'success' | 'failure'; | ||
} | ||
|
||
export type TrackableEvent = | ||
| AmountTypeEvent | ||
| ClickDetailsEvent | ||
| WalletConnectEvent | ||
| TransactionEvent | ||
| ClickSupportEvent; | ||
|
||
type EventType = TrackableEvent['event']; | ||
|
||
type UseEventsContext = ReturnType<typeof useEvents>; | ||
const useEvents = () => { | ||
const [_, setTrackedEventTypes] = useState<Set<EventType>>(new Set()); | ||
|
||
const previousAddress = useRef<`0x${string}` | undefined>(undefined); | ||
const { address } = useAccount(); | ||
|
||
const trackEvent = useCallback( | ||
(event: TrackableEvent) => { | ||
setTrackedEventTypes((trackedEventTypes) => { | ||
if (UNIQUE_EVENT_TYPES.includes(event.event)) { | ||
if (trackedEventTypes.has(event.event)) { | ||
return trackedEventTypes; | ||
} else { | ||
trackedEventTypes = new Set(trackedEventTypes); | ||
trackedEventTypes.add(event.event); | ||
} | ||
} | ||
console.log('Push data layer', event); | ||
|
||
window.dataLayer.push(event); | ||
|
||
return trackedEventTypes; | ||
}); | ||
}, | ||
[setTrackedEventTypes], | ||
); | ||
|
||
useEffect(() => { | ||
const wasConnected = previousAddress.current !== undefined; | ||
const isConnected = address !== undefined; | ||
|
||
if (!isConnected) { | ||
trackEvent({ event: 'wallet_connect', wallet_action: 'disconnect' }); | ||
} else { | ||
trackEvent({ event: 'wallet_connect', wallet_action: wasConnected ? 'change' : 'connect' }); | ||
} | ||
|
||
previousAddress.current = address; | ||
}, [address]); | ||
|
||
return { | ||
trackEvent, | ||
}; | ||
}; | ||
|
||
const Context = createContext<UseEventsContext | undefined>(undefined); | ||
|
||
export const useEventsContext = () => { | ||
const contextValue = useContext(Context); | ||
if (contextValue === undefined) { | ||
throw new Error('Context must be inside a Provider'); | ||
} | ||
|
||
return contextValue; | ||
}; | ||
|
||
export function EventsProvider({ children }: PropsWithChildren) { | ||
const useEventsResult = useEvents(); | ||
|
||
return <Context.Provider value={useEventsResult}>{children}</Context.Provider>; | ||
} | ||
|
||
export function createTransactionEvent(type: TransactionEvent['event'], state: OfframpingState) { | ||
return { | ||
event: type, | ||
from_asset: INPUT_TOKEN_CONFIG[state.inputTokenType].assetSymbol, | ||
to_asset: OUTPUT_TOKEN_CONFIG[state.outputTokenType].stellarAsset.code.string, | ||
from_amount: state.inputAmount.units, | ||
to_amount: state.outputAmount.units, | ||
}; | ||
} |
Oops, something went wrong.