-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
107 lines (88 loc) · 3.11 KB
/
script.js
File metadata and controls
107 lines (88 loc) · 3.11 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
96
97
98
99
100
101
102
103
104
105
106
107
const symbol = require('/node_modules/symbol-sdk')
const GENERATION_HASH = '7FCCD304802016BEBBCD342A332F91FF1F3BB5E902988B352697BE245F48E836'
const EPOCH = 1637848847
const XYM_ID = '3A8416DB2D53B6C8'
const NODE_URL = 'https://test.harvester.earth:3001'
const NET_TYPE = symbol.NetworkType.TEST_NET
const repositoryFactory = new symbol.RepositoryFactoryHttp(NODE_URL)
const accountHttp = repositoryFactory.createAccountRepository()
const transactionHttp = repositoryFactory.createTransactionRepository()
setTimeout(() => {
const address = symbol.Address.createFromRawAddress(window.SSS.activeAddress)
const dom_addr = document.getElementById('wallet-addr')
dom_addr.innerText = address.pretty()
accountHttp.getAccountInfo(address)
.toPromise()
.then((accountInfo) => {
for (let m of accountInfo.mosaics) {
if (m.id.id.toHex() === XYM_ID) {
const dom_xym = document.getElementById('wallet-xym')
dom_xym.innerText = `XYM Balance : ${m.amount.compact() / Math.pow(10, 6)}`
}
}
})
const searchCriteria = {
group: symbol.TransactionGroup.Confirmed,
address,
pageNumber: 1,
pageSize: 20,
order: symbol.Order.Desc,
}
transactionHttp
.search(searchCriteria)
.toPromise()
.then((txs) => {
console.log(txs)
const dom_txInfo = document.getElementById('wallet-transactions')
for (let tx of txs.data) {
console.log(tx)
const dom_tx = document.createElement('div')
const dom_txType = document.createElement('div')
const dom_hash = document.createElement('div')
dom_txType.innerText = `Transaction Type : ${getTransactionType(tx.type)}`
dom_hash.innerText = `Transaction Hash : ${tx.transactionInfo.hash}`
dom_tx.appendChild(dom_txType)
dom_tx.appendChild(dom_hash)
dom_tx.appendChild(document.createElement('hr'))
dom_txInfo.appendChild(dom_tx)
}
})
}, 500)
function getTransactionType (type) { // https://symbol.github.io/symbol-sdk-typescript-javascript/1.0.3/enums/TransactionType.html
if (type === 16724) return 'TRANSFER TRANSACTION'
return 'OTHER TRANSACTION'
}
function handleSSS() {
console.log('handle sss')
const addr = document.getElementById('form-addr').value
const amount = document.getElementById('form-amount').value
const message = document.getElementById('form-message').value
const tx = symbol.TransferTransaction.create(
symbol.Deadline.create(EPOCH),
symbol.Address.createFromRawAddress(addr),
[
new symbol.Mosaic(
new symbol.MosaicId(XYM_ID),
symbol.UInt64.fromUint(Number(amount) * Math.pow(10, 6))
)
],
symbol.PlainMessage.create(message),
NET_TYPE,
symbol.UInt64.fromUint(2000000)
)
window.SSS.setTransaction(tx)
window.SSS.requestSign().then(signedTx => {
console.log('signedTx', signedTx)
transactionHttp.announce(signedTx)
})
}
// input range render
function render (output, value) {
output.innerHTML = value
}
const input = document.querySelector('#form-amount')
const output = document.querySelector('b')
input.addEventListener('input', function (e) {
render(output, e.target.value)
}, false)
render(output, input.value)