-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·78 lines (73 loc) · 1.67 KB
/
app.js
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
import React from 'react';
import {
setOpenHandler,
newModalUIID,
renderModal,
renderMessage,
sendMessage,
setMessageRenderer,
Container,
} from 'pangea-sdk';
import Modal from './src/components/Modal';
import SendMessage from './src/components/SendMessage';
import RequestMessage from './src/components/RequestMessage';
function showMainModal(payload, cb) {
// obtain a new modal id
newModalUIID(
() => {
},
(error, modalUIID) => {
if (error) {
return cb(error);
}
renderModal(<Modal title='Send/request money'
context={payload.context}
initialData={payload.initialData}
modalContainer={new Container(modalUIID)}/>, cb);
},
);
}
/**
* @desc Function that is called on DApp start
*/
setOpenHandler((payload, cb) => {
showMainModal(payload, cb);
});
/**
* @desc Function that is called to render message
*/
setMessageRenderer((payload, cb) => {
const { message } = payload;
let Component = null;
let propsToPass = {};
switch (message.type) {
case 'SEND_MONEY':
Component = SendMessage;
break;
case 'REQUEST_MONEY':
Component = RequestMessage;
propsToPass = {
onSelectSend: (payload, cb) => {
showMainModal({
...payload,
initialData: {
amount: message.params.amount,
currency: message.params.currency,
},
}, cb);
},
};
break;
}
if (Component === null) {
cb(null, {});
}
renderMessage(
<Component
payload={payload}
{...propsToPass}
/>,
(jsx) => {
cb(null, jsx);
});
});