add dates to frontend
This commit is contained in:
@@ -114,9 +114,14 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<h3 class="card-header">
|
<h3 class="card-header">
|
||||||
{{shout.title}}
|
{{shout.title}}
|
||||||
<a [href]="'https://testnet.xrpl.org/transactions/'+shout.hash+'/detailed'" target="_blank">
|
<span class="p3">
|
||||||
<cds-icon shape="link"></cds-icon>
|
<br />
|
||||||
</a>
|
({{shout.date}}
|
||||||
|
<a [href]="'https://testnet.xrpl.org/transactions/'+shout.hash+'/detailed'" target="_blank">
|
||||||
|
<cds-icon shape="link"></cds-icon>
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
<div class="card-block">
|
<div class="card-block">
|
||||||
<div class="card-text">
|
<div class="card-text">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, NgZone, OnInit } from '@angular/core';
|
||||||
import { ShoutboxDataService } from './services/ShoutboxData.service';
|
import { ShoutboxDataService } from './services/ShoutboxData.service';
|
||||||
import { makeTestnetWallet } from './util/TestnetUtils';
|
import { makeTestnetWallet } from './util/TestnetUtils';
|
||||||
|
|
||||||
@@ -19,7 +19,8 @@ export class AppComponent implements OnInit {
|
|||||||
title: "",
|
title: "",
|
||||||
body: "",
|
body: "",
|
||||||
from: "",
|
from: "",
|
||||||
hash: ""
|
hash: "",
|
||||||
|
date: "",
|
||||||
}
|
}
|
||||||
userWallet = {
|
userWallet = {
|
||||||
address: "",
|
address: "",
|
||||||
@@ -31,7 +32,8 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private dataService: ShoutboxDataService
|
private dataService: ShoutboxDataService,
|
||||||
|
private zone: NgZone
|
||||||
) {
|
) {
|
||||||
this.contractAddress = dataService.getContractAddress()
|
this.contractAddress = dataService.getContractAddress()
|
||||||
}
|
}
|
||||||
@@ -44,7 +46,8 @@ export class AppComponent implements OnInit {
|
|||||||
title: "",
|
title: "",
|
||||||
body: "",
|
body: "",
|
||||||
from: "",
|
from: "",
|
||||||
hash: ""
|
hash: "",
|
||||||
|
date: "",
|
||||||
}
|
}
|
||||||
this.lastMessageHash = hash
|
this.lastMessageHash = hash
|
||||||
})
|
})
|
||||||
@@ -56,15 +59,18 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
Promise.all([makeTestnetWallet(), makeTestnetWallet()]).then(([userWallet, drainWallet]) => {
|
Promise.all([makeTestnetWallet(), makeTestnetWallet()])
|
||||||
console.log(userWallet, drainWallet)
|
.then(async ([userWallet, drainWallet]) => {
|
||||||
this.userWallet = userWallet
|
this.userWallet = userWallet
|
||||||
this.drainWallet = drainWallet
|
this.drainWallet = drainWallet
|
||||||
|
|
||||||
this.dataService.initialize((shout: any) => {
|
await this.dataService.initialize((shout: any) => {
|
||||||
this.shouts.unshift(shout)
|
this.zone.run(_ => {
|
||||||
|
this.shouts.unshift(shout)
|
||||||
|
console.log(shout)
|
||||||
|
})
|
||||||
|
}, userWallet, drainWallet)
|
||||||
this.initializing = false
|
this.initializing = false
|
||||||
}, userWallet, drainWallet)
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { ChangeDetectorRef, Injectable, NgZone } from "@angular/core";
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
declare const RJSVM: any;
|
declare const RJSVM: any;
|
||||||
@@ -11,16 +11,18 @@ const listeningAddress = "rMBYWyxGx1b5zEjJKF18TTwF5X3vP2WyjR"
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShoutboxDataService {
|
export class ShoutboxDataService {
|
||||||
|
|
||||||
public history: any[] = []
|
|
||||||
private dataWriter = undefined as any
|
private dataWriter = undefined as any
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
) { }
|
||||||
|
|
||||||
public submitShout = async (shout: any) => {
|
public submitShout = async (shout: any) => {
|
||||||
return await this.dataWriter.callEndpoint('submit', shout, 10)
|
return await this.dataWriter.callEndpoint('submit', shout, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getContractAddress = () => listeningAddress
|
public getContractAddress = () => listeningAddress
|
||||||
|
|
||||||
initialize = async (onData:Function, userWallet?:any, drainWallet?:any) => {
|
initialize = async (onData: Function, userWallet?: any, drainWallet?: any) => {
|
||||||
|
|
||||||
this.dataWriter = new Datawriter({
|
this.dataWriter = new Datawriter({
|
||||||
receiveAddress: drainWallet.address,
|
receiveAddress: drainWallet.address,
|
||||||
@@ -33,70 +35,69 @@ export class ShoutboxDataService {
|
|||||||
title: z.string(),
|
title: z.string(),
|
||||||
body: z.string(),
|
body: z.string(),
|
||||||
from: z.string(),
|
from: z.string(),
|
||||||
|
hash: z.optional(z.string()),
|
||||||
|
date: z.optional(z.string()),
|
||||||
id: z.optional(z.string())
|
id: z.optional(z.string())
|
||||||
})
|
})
|
||||||
//type Shout = z.infer<typeof shoutSchema>
|
type Shout = z.infer<typeof shoutSchema>
|
||||||
|
|
||||||
type State = {
|
type State = {}
|
||||||
shouts: any[]
|
|
||||||
}
|
|
||||||
|
|
||||||
// #########################
|
// #########################
|
||||||
// Define endpoints
|
// Define endpoints
|
||||||
// #########################
|
// #########################
|
||||||
|
|
||||||
type RJSVM_Endpoints = {
|
type RJSVM_Endpoints = {
|
||||||
submit: (data: any) => void
|
submit: (data: Shout) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
// #########################
|
// #########################
|
||||||
// Define init state
|
// Define init state
|
||||||
// #########################
|
// #########################
|
||||||
|
|
||||||
abstract class RJSVM_Base
|
abstract class RJSVM_Base
|
||||||
extends RJSVM<State, RJSVM_Endpoints>
|
extends RJSVM<State, RJSVM_Endpoints>
|
||||||
{
|
{
|
||||||
|
|
||||||
owner = userWallet.address
|
owner = userWallet.address
|
||||||
|
|
||||||
state: State = {
|
state: State = {}
|
||||||
shouts: []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #########################
|
// #########################
|
||||||
// Implement logic
|
// Implement logic
|
||||||
// #########################
|
// #########################
|
||||||
|
|
||||||
const RJSVM_Contract = {
|
const RJSVM_Contract = {
|
||||||
submit: {
|
submit: {
|
||||||
implementation: function (env:any, shout: any) {
|
implementation: function (env: any, shout: Shout) {
|
||||||
shout.hash = env.hash;
|
shout.hash = env.hash;
|
||||||
(this as any).state.shouts.unshift(shout)
|
const d = new Date("2000-01-01");
|
||||||
|
d.setSeconds(d.getSeconds() + env.date)
|
||||||
|
shout.date = d.toLocaleString("de-DE")
|
||||||
},
|
},
|
||||||
visibility: 'public',
|
visibility: 'public',
|
||||||
fee: 10,
|
fee: 10,
|
||||||
parameterSchema: shoutSchema
|
parameterSchema: shoutSchema
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #########################
|
// #########################
|
||||||
// Build and connect
|
// Build and connect
|
||||||
// #########################
|
// #########################
|
||||||
|
|
||||||
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
|
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
|
||||||
|
|
||||||
const conf = {
|
const conf = {
|
||||||
listeningAddress: listeningAddress,
|
listeningAddress: listeningAddress,
|
||||||
rippleNode: xrpNode
|
rippleNode: xrpNode
|
||||||
}
|
}
|
||||||
|
|
||||||
const rjsvm = new Rjsvm(conf)
|
const rjsvm = new Rjsvm(conf)
|
||||||
await rjsvm.connect()
|
await rjsvm.connect()
|
||||||
|
|
||||||
rjsvm.on('error', console.log)
|
rjsvm.on('error', console.log)
|
||||||
rjsvm.on('submit', onData)
|
rjsvm.on('submit', onData)
|
||||||
|
|
||||||
this.history = rjsvm.state.shouts
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user