-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakeOffer.tsx
More file actions
95 lines (88 loc) · 2.46 KB
/
MakeOffer.tsx
File metadata and controls
95 lines (88 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { AgoricWalletConnection } from '@agoric/react-components';
import { DynamicToastChild } from '../Tabs';
import { useContractStore } from '../../store/contract';
export const makeOffer = async (
wallet: AgoricWalletConnection,
addNotification: (arg0: DynamicToastChild) => void,
selectedChain: string,
publicInvitationMaker: string,
offerArgs: Record<string, unknown>,
setLoading: React.Dispatch<React.SetStateAction<boolean>>,
handleToggle: () => void,
setStatusText: React.Dispatch<React.SetStateAction<string>>,
) => {
if (!selectedChain) {
addNotification({
text: `Please Select Chain`,
status: 'error',
});
setLoading(false);
handleToggle();
return;
}
const { instances, brands } = useContractStore.getState();
const instance = instances?.['orca'];
if (!instance || !brands) {
setLoading(false);
handleToggle();
throw Error('No contract instance or brands found.');
}
// fetch the BLD brand
const bldBrand = brands.BLD;
if (!bldBrand) {
setLoading(false);
handleToggle();
throw Error('BLD brand not found.');
}
const want = {};
const give = { Deposit: { brand: bldBrand, value: BigInt(1000) } };
const offerId = Date.now();
await wallet?.makeOffer(
{
source: 'contract',
instance,
publicInvitationMaker,
},
{ give, want },
offerArgs,
(update: { status: string; data?: unknown }) => {
if (update.status === 'error') {
addNotification({
text: `Offer update error: ${update.data}`,
status: 'error',
});
setStatusText('Error during offer submission.');
setLoading(false);
handleToggle();
console.log(update);
}
if (update.status === 'accepted') {
addNotification({
text: 'Offer accepted successfully',
status: 'success',
});
setStatusText('Offer accepted. Processing...');
handleToggle();
setLoading(false);
}
if (update.status === 'refunded') {
addNotification({
text: 'Offer was refunded',
status: 'error',
});
setStatusText('Offer refunded.');
setLoading(false);
handleToggle();
console.log(update);
}
if (update.status === 'done') {
setStatusText('Operation completed successfully.');
setLoading(false);
setTimeout(() => {
handleToggle();
}, 1000);
}
},
offerId,
);
};