-
Notifications
You must be signed in to change notification settings - Fork 41
/
dispatch.foreground.ts
37 lines (31 loc) · 1.06 KB
/
dispatch.foreground.ts
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
import { ACCEPTED_DISPATCH_SIZE, DispatchResult } from "./index";
import { createCoinWithAnimation } from "../sign/animation";
import { TransformFinalizer } from "../../foreground";
import { ModuleFunction } from "../../module";
import Transaction from "arweave/web/lib/transaction";
const foreground: ModuleFunction<Record<any, any>> = (
transaction: Transaction
) => {
// check tx data size
// we don't allow size > ACCEPTED_DISPATCH_SIZE
const dataSize = transaction.data.length;
if (dataSize > ACCEPTED_DISPATCH_SIZE) {
throw new Error(
`ArConnect does not currently support dispatching transactions with data greater than ${ACCEPTED_DISPATCH_SIZE} bytes.`
);
}
return [transaction.toJSON()];
};
export const finalizer: TransformFinalizer<{
arConfetti: string;
res: DispatchResult;
}> = (result) => {
// show a nice confetti eeffect, if enabled
if (result.arConfetti) {
for (let i = 0; i < 8; i++) {
setTimeout(() => createCoinWithAnimation(result.arConfetti), i * 150);
}
}
return result.res;
};
export default foreground;