Skip to content

Commit 75434ec

Browse files
committed
Interoperability with Binance Test Smart Chain
1 parent 07fefca commit 75434ec

22 files changed

Lines changed: 177 additions & 67 deletions

payment-chooser/build/resources/static/static/js/payment-chooser.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

payment-chooser/build/resources/static/static/js/payment-chooser.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

payment-chooser/src/index.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ let widgetData;
55
const spinner = document.getElementById("spinner");
66
const orderKey = document.body.dataset.order;
77
const host = document.body.dataset.host;
8+
const currency = document.body.dataset.currency;
89
const OPEN_URL = `${host}/widget/payment/addresses/order/${orderKey}`;
10+
let timerId = 1;
911

1012
async function getAddressData(URI){
1113
let response = await fetch(URI, {
@@ -37,11 +39,20 @@ function fetchTransactionData() {
3739
}
3840

3941
function loadTransactionData(result) {
40-
console.log(result);
42+
4143
const amount = document.querySelector(".amount");
4244
const remaining = document.querySelector(".remaining");
4345
amount.innerHTML = `${result.orderAmount}`;
44-
remaining.innerHTML = `${result.orderAmount - result.paid}`;
46+
//let leftAmount = Math.ceil(result.orderAmount - result.paid);
47+
let leftAmount = result.orderAmount - result.paid;
48+
remaining.innerHTML = `${leftAmount}`;
49+
50+
if ( result.orderAmount <= result.paid){
51+
clearInterval(timerId);
52+
const counter = document.getElementById("countdown");
53+
counter.setAttribute('class','completed')
54+
counter.innerHTML = "Order Completed";
55+
}
4556

4657
for (let blockchain of result.wallets) {
4758
const tbody = document.querySelector("."+`${blockchain.blockchain+blockchain.address}`);
@@ -74,9 +85,11 @@ async function openPaymentWidget(){
7485
const amount = document.querySelector(".amount");
7586
const remaining = document.querySelector(".remaining");
7687
amount.innerHTML = `${widgetData.orderAmount}`;
77-
remaining.innerHTML = `${widgetData.orderAmount - widgetData.paid}`;
88+
//let leftAmount = Math.ceil(widgetData.orderAmount - widgetData.paid);
89+
let leftAmount = widgetData.orderAmount - widgetData.paid;
90+
remaining.innerHTML = `${leftAmount}` ;
7891

79-
countdownTimer(new Date(`${widgetData.orderDate}`).getTime())
92+
countdownTimer(new Date(`${widgetData.orderDate}`).getTime(), widgetData.orderAmount, widgetData.paid);
8093

8194
const accordion = document.querySelector(".accordion");
8295
let i = 1;
@@ -189,6 +202,9 @@ function getBlockchainObject(blockchain){
189202
} else if (blockchain.blockchain === "RopstenBlockchain"){
190203
IDs['imgSrc'] = "/static/images/ETH.png";
191204
IDs['title'] = "Ropsten";
205+
} else if(blockchain.blockchain === "BinanceTestnetBlockchain") {
206+
IDs['imgSrc'] = "/static/images/BNB.png";
207+
IDs['title'] = "Binance Test";
192208
} else {
193209
IDs['imgSrc'] = "/static/images/BNB.png";
194210
IDs['title'] = "Binance";
@@ -197,9 +213,9 @@ function getBlockchainObject(blockchain){
197213
return IDs;
198214
}
199215

200-
function countdownTimer(countDownDate){
216+
function countdownTimer(countDownDate, amount, paid){
201217

202-
let x = setInterval(function() {
218+
timerId = setInterval(function() {
203219

204220
let now = new Date().getTime();
205221
let distance = countDownDate - now;
@@ -208,11 +224,17 @@ function countdownTimer(countDownDate){
208224
let minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
209225
let seconds = Math.floor((distance % (1000 * 60)) / 1000);
210226

211-
document.getElementById("countdown").innerHTML = hours + "h:" + minutes + "m:" + seconds+"s";
227+
const counter = document.getElementById("countdown");
228+
counter.innerHTML = hours + "h:" + minutes + "m:" + seconds+"s";
212229

213230
if (distance < 0) {
214-
clearInterval(x);
215-
document.getElementById("countdown").innerHTML = "EXPIRED";
231+
clearInterval(timerId);
232+
counter.innerHTML = "EXPIRED";
233+
}
234+
if (amount <= paid){
235+
clearInterval(timerId);
236+
counter.setAttribute('class','completed')
237+
counter.innerHTML = "Order Completed";
216238
}
217239
}, 1000);
218240
}

payment-chooser/src/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ div, input.card-input, select.card-input {
5353

5454
.amount, .remaining{
5555
color: #007bff;
56+
text-align: left;
57+
}
58+
.completed{
59+
background: #28a745!important;
60+
color: #fff;
5661
}
5762

5863
#spinner:not([hidden]) {
@@ -112,4 +117,8 @@ div, input.card-input, select.card-input {
112117
}
113118
h5.mb-0{
114119
text-align: left;
120+
}
121+
122+
.align-items-center{
123+
text-align: left;
115124
}

src/main/kotlin/io/openfuture/api/annotation/resolver/CurrentUserArgumentResolver.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ class CurrentUserArgumentResolver(
1515
) : HandlerMethodArgumentResolver {
1616

1717
override fun supportsParameter(parameter: MethodParameter): Boolean =
18-
parameter.hasParameterAnnotation(CurrentUser::class.java)
18+
parameter.hasParameterAnnotation(CurrentUser::class.java)
1919

20-
override fun resolveArgument(parameter: MethodParameter, mavContainer: ModelAndViewContainer?, webRequest: NativeWebRequest, binderFactory: WebDataBinderFactory?): Any? {
20+
override fun resolveArgument(
21+
parameter: MethodParameter,
22+
mavContainer: ModelAndViewContainer?,
23+
webRequest: NativeWebRequest,
24+
binderFactory: WebDataBinderFactory?
25+
): Any? {
2126
val authentication = SecurityContextHolder.getContext().authentication
2227
val user = authentication.principal as OidcUser
2328
return userService.findByGoogleId(user.subject)

src/main/kotlin/io/openfuture/api/component/state/DefaultStateApi.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,33 @@ import io.openfuture.api.domain.key.KeyWalletDto
44
import io.openfuture.api.domain.state.*
55
import io.openfuture.api.domain.widget.PaymentWidgetResponse
66
import io.openfuture.api.entity.state.Blockchain
7+
import io.openfuture.api.util.getOrderKey
8+
import io.openfuture.api.util.getRandomNumber
79
import org.springframework.stereotype.Component
810
import org.springframework.web.client.RestTemplate
11+
import java.math.BigDecimal
912

1013
@Component
1114
class DefaultStateApi(private val stateRestTemplate: RestTemplate) : StateApi {
1215

13-
override fun createWallet(address: String, webHook: String, blockchain: Blockchain): StateWalletDto {
14-
val request = CreateStateWalletRequest(address, webHook, blockchain)
15-
//val request = CreateStateWalletRequestMetadata(webHook, listOf(KeyWalletDto(address,blockchain.getValue())), WalletMetaData())
16-
val response = stateRestTemplate.postForEntity("/wallets", request, StateWalletDto::class.java)
17-
return response.body!!
16+
override fun createWallet(address: String, webHook: String, blockchain: Blockchain): CreateStateWalletResponse {
17+
val request = CreateStateWalletRequestMetadata(
18+
webHook,
19+
listOf(KeyWalletDto(address, blockchain.getValue())),
20+
WalletMetaData(
21+
"0",
22+
getRandomNumber(1000, 9999).toString(),
23+
getOrderKey("op_"),
24+
"USD",
25+
"open",
26+
false
27+
)
28+
)
29+
return stateRestTemplate.postForEntity("/wallets", request, CreateStateWalletResponse::class.java).body!!
1830
}
1931

20-
override fun createWalletWithMetadata(request: CreateStateWalletRequestMetadata) {
21-
stateRestTemplate.postForEntity("/wallets", request, Void::class.java)
32+
override fun createWalletWithMetadata(request: CreateStateWalletRequestMetadata): CreateStateWalletResponse {
33+
return stateRestTemplate.postForEntity("/wallets", request, CreateStateWalletResponse::class.java).body!!
2234
}
2335

2436
override fun deleteWallet(address: String, blockchain: Blockchain) {

src/main/kotlin/io/openfuture/api/component/state/StateApi.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package io.openfuture.api.component.state
22

3-
import io.openfuture.api.domain.state.CreateStateWalletRequestMetadata
4-
import io.openfuture.api.domain.state.StateWalletDto
5-
import io.openfuture.api.domain.state.StateWalletTransaction
6-
import io.openfuture.api.domain.state.StateWalletTransactionDetail
3+
import io.openfuture.api.domain.state.*
74
import io.openfuture.api.domain.transaction.TransactionDto
85
import io.openfuture.api.domain.widget.PaymentWidgetResponse
96
import io.openfuture.api.entity.state.Blockchain
107

118
interface StateApi {
129

13-
fun createWallet(address: String, webHook: String, blockchain: Blockchain): StateWalletDto
10+
fun createWallet(address: String, webHook: String, blockchain: Blockchain): CreateStateWalletResponse
1411

15-
fun createWalletWithMetadata(request: CreateStateWalletRequestMetadata)
12+
fun createWalletWithMetadata(request: CreateStateWalletRequestMetadata): CreateStateWalletResponse
1613

1714
fun deleteWallet(address: String, blockchain: Blockchain)
1815

src/main/kotlin/io/openfuture/api/config/handler/AuthenticationSuccessHandler.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import javax.servlet.http.HttpServletRequest
99
import javax.servlet.http.HttpServletResponse
1010

1111
class AuthenticationSuccessHandler(
12-
private val userService: UserService
12+
private val userService: UserService
1313
) : SavedRequestAwareAuthenticationSuccessHandler() {
1414

15-
override fun onAuthenticationSuccess(request: HttpServletRequest, response: HttpServletResponse,
16-
authentication: Authentication) {
15+
override fun onAuthenticationSuccess(
16+
request: HttpServletRequest, response: HttpServletResponse,
17+
authentication: Authentication
18+
) {
1719
val principal = authentication.principal as OidcUser
1820
userService.findByGoogleId(principal.subject) ?: userService.save(User(principal.subject))
1921
response.sendRedirect("/ethereum-scaffolds")

src/main/kotlin/io/openfuture/api/controller/api/ApplicationApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ApplicationApiController(
2727
}
2828

2929
@PostMapping
30-
fun save(@Valid @RequestBody request: ApplicationRequest, @CurrentUser user: User): Application =
30+
fun save(@Valid @RequestBody request: ApplicationRequest, @CurrentUser user: User): Application =
3131
service.save(request, user, digitalKeyGenerator.generateApplicationAccessKey())
3232

3333
@DeleteMapping

src/main/kotlin/io/openfuture/api/controller/api/ApplicationWalletApiController.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class ApplicationWalletApiController(
2020
service.generateWallet(request, user)
2121

2222
@DeleteMapping
23-
fun delete(@RequestParam("applicationId") applicationId: String, @RequestParam("address") address: String): Boolean {
23+
fun delete(
24+
@RequestParam("applicationId") applicationId: String,
25+
@RequestParam("address") address: String
26+
): Boolean {
2427
service.deleteWallet(applicationId, address)
2528
return true
2629
}
@@ -31,7 +34,10 @@ class ApplicationWalletApiController(
3134
}
3235

3336
@PostMapping("/sign/address/{address}")
34-
fun generateSignature(@PathVariable("address") address: String, @Valid @RequestBody request: StateSignRequest): String {
37+
fun generateSignature(
38+
@PathVariable("address") address: String,
39+
@Valid @RequestBody request: StateSignRequest
40+
): String {
3541
return service.generateSignature(address, request)
3642
}
3743

0 commit comments

Comments
 (0)