Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Transaction status modal and transaction flow #52

Draft
wants to merge 74 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
1d95025
use waitForTransactionReceipt from publicClient to listen receipt upd…
w1that Dec 5, 2024
0945fdf
add isTimout prop to components
w1that Dec 5, 2024
fcfcfa7
add new messages for timed out transaction receipt fetchs
w1that Dec 5, 2024
d17ebe9
remove useTransactionStatusModal from modals
w1that Dec 5, 2024
dba7c41
add TRANSFER to TransactionType
w1that Dec 5, 2024
3045b2b
add cancel titles
w1that Dec 5, 2024
d9071f1
update modal callbacks
w1that Dec 5, 2024
2cdf4c1
return hash from transfer transaction and show transaction status mod…
w1that Dec 5, 2024
4e0e410
assign collectibleId and format
w1that Dec 6, 2024
3e52fc4
implement utils for generating titles and message
w1that Dec 6, 2024
229d4e0
remove console.logs
w1that Dec 6, 2024
17b1090
change transaction status type and use it
w1that Dec 6, 2024
214e2ca
handle loading collectible preview with skeleton to avoid layout flas…
w1that Dec 6, 2024
f1c2b98
remove unused utils about modal spesific message generation
w1that Dec 6, 2024
ef51f85
avoid misunderstanding on message
w1that Dec 6, 2024
9994774
pass callbacks to TransactionStatusModal on execute-transaction
w1that Dec 6, 2024
8401c27
set optional `confirmations` for ShowTransactionStatusModalArgs
w1that Dec 6, 2024
89b40ff
block showing status modal to not show while approving
w1that Dec 6, 2024
a513778
add objectFit style to image components in token and transaction prev…
w1that Dec 6, 2024
0800416
dont call onTransactionSent and onSuccess after token approval
w1that Dec 6, 2024
abe11ab
* improve naming for token approval base,
w1that Dec 6, 2024
398a0e8
format
w1that Dec 6, 2024
1406726
separate ApprovalStep
w1that Dec 6, 2024
9ed7c27
wrap approve logic with promise
w1that Dec 6, 2024
2f2a488
change the way Transaction machine works, manage state in detail
w1that Dec 9, 2024
fe1db96
remove unused hooks and refactor useCancelOrder temporarily
w1that Dec 9, 2024
a8b6275
update ActionModal to support async onClick handlers
w1that Dec 9, 2024
35408d5
add onClose callback to SwitchChainModal for better state management
w1that Dec 9, 2024
e788eb7
move logic of removed intermediate hook, to buy modal
w1that Dec 9, 2024
b75f5d6
move logic of removed intermediate hook, to create listing modal
w1that Dec 9, 2024
7925f91
move logic of removed intermediate hook, to offer modal
w1that Dec 9, 2024
9165c8b
move logic of removed intermediate hook, to sell modal
w1that Dec 9, 2024
70c9702
format
w1that Dec 9, 2024
eef0117
refactor: update transaction machine methods to use Promises for appr…
w1that Dec 9, 2024
8189484
implement custom hook for using transaction machine
w1that Dec 9, 2024
2b9fc61
delete switch chain modal state on close, set error message
w1that Dec 9, 2024
a891d2c
handle state of machine with useState
w1that Dec 9, 2024
979eb76
refactor useMakeOffer according to state change
w1that Dec 9, 2024
aaa6ec1
move logic of buy modal to separate hook
w1that Dec 9, 2024
1f8b6a5
separate transaction logic for sell modal
w1that Dec 9, 2024
313d7ee
refactor hook and component of make offer modal
w1that Dec 9, 2024
7fa0561
refactor cancel transaction hook with new transaction machine logic
w1that Dec 9, 2024
30b09c4
separate transaction logic for create listing modal
w1that Dec 9, 2024
ceba856
export new hooks
w1that Dec 9, 2024
6a461d5
move dateToUnixTime to util
w1that Dec 9, 2024
103fc5a
rename useCancelOrder to useCancel for consistency
w1that Dec 10, 2024
caa8f3b
watch for chain changes, how switch chain modal immediately
w1that Dec 10, 2024
380caa3
delete modal state after switching chain
w1that Dec 10, 2024
3fee9a6
set steps properly, make approve method public, refactor state manage…
w1that Dec 10, 2024
0c78fe6
use machine.approve method hook level
w1that Dec 10, 2024
47a0018
set main cta disability controls more broadly
w1that Dec 10, 2024
a044056
close action modal after transaction status modal opens
w1that Dec 10, 2024
4cfb0fd
simplify network switch
w1that Dec 10, 2024
41171c4
pass onSuccess and onError callbacks from modals states
w1that Dec 11, 2024
9403185
implement new format of handling transactions to sell modal
w1that Dec 11, 2024
9133bf7
apply new way of handling transactions, for buy modal
w1that Dec 11, 2024
9db7dd2
apply new way of handling transactions, for cancel
w1that Dec 11, 2024
4d96eaf
apply new way of handling transactions, for create listing
w1that Dec 11, 2024
a62496e
useSell: trigger first fetch steps if machine changes
w1that Dec 11, 2024
4530410
pass callback of showing transaction status modal
w1that Dec 11, 2024
c0e7783
format
w1that Dec 11, 2024
a1399e0
manage step fetching on initializing the machine:
w1that Dec 11, 2024
65cd7c7
check steps in execute method of machine
w1that Dec 11, 2024
d7889a3
create listing modal: remove unnecessary functions to check steps, si…
w1that Dec 11, 2024
cc4223b
explain why initial fetch of steps is needed
w1that Dec 11, 2024
14be491
handle showing different actions on playground table properly
w1that Dec 11, 2024
0ec6e42
fix execute function of useCancel
w1that Dec 11, 2024
b9e75db
remove fetching in useEffect for make offer, fetch on initialization …
w1that Dec 11, 2024
a748abf
refactor buy modal, pass missing collectibleId
w1that Dec 11, 2024
d5845a2
fix approving spending erc20 cap for make offer modal
w1that Dec 11, 2024
2169977
improve readability, set methods in correct order
w1that Dec 11, 2024
b5683da
remove unused file
w1that Dec 11, 2024
6f78e83
use placeholder pricePerToken for first fetch to check token approval…
w1that Dec 12, 2024
421eaf0
initialize transaction state only if input is provided
w1that Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Hash } from 'viem';

export type Result<T> = {
data?: T;
error?: Error;
isLoading: boolean;
isComplete: boolean;
};

export default class AsyncResultHandler<T> {
private state: Result<T> = {
isLoading: false,
isComplete: false,
};

constructor(private onError?: (error: Error) => void) {}

getState(): Result<T> {
return this.state;
}

async execute(
operation: () => Promise<T>,
onSuccess?: (hash: Hash) => void,
onError?: (error: Error) => void,
): Promise<Result<T>> {
try {
this.state = {
...this.state,
isLoading: true,
isComplete: false,
error: undefined,
};

const data = await operation();

this.state = {
data,
isLoading: false,
isComplete: true,
};

if (onSuccess) {
onSuccess(data as Hash);
}

return this.state;
} catch (error) {
const err = error as Error;
this.state = {
isLoading: false,
isComplete: true,
error: err,
};

if (this.onError) {
this.onError(err);
}

if (onError) {
onError(err);
}

return this.state;
}
}
}
Loading