Skip to content

Commit 2032915

Browse files
temp date solution
1 parent 3b20fe9 commit 2032915

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

Assets/Thirdweb/Scripts/ERC721.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ public class ERC721MintPayload
134134
public NFTMetadata? metadata;
135135
public string uid;
136136
// TODO implement these, needs JS bridging support
137-
public DateTime? mintStartTime;
138-
public DateTime? mintEndTime;
137+
public long mintStartTime;
138+
public long mintEndTime;
139139

140140
public ERC721MintPayload() {
141141
this.to = Utils.AddressZero;
@@ -146,9 +146,10 @@ public ERC721MintPayload() {
146146
this.royaltyBps = 0;
147147
this.quantity = 1;
148148
this.metadata = null;
149-
this.mintEndTime = null;
150-
this.mintEndTime = null;
151149
this.uid = Utils.ToBytes32HexString(Guid.NewGuid().ToByteArray());
150+
// TODO temporary solution
151+
this.mintStartTime = Utils.UnixTimeNowMs() * 1000L;
152+
this.mintEndTime = this.mintStartTime + 1000L * 60L * 60L * 24L * 365L;
152153
}
153154
}
154155

Assets/Thirdweb/Scripts/Utils.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Text;
23
using UnityEngine;
34

@@ -33,7 +34,13 @@ public static string ToBytes32HexString(byte[] bytes)
3334
{
3435
hex.AppendFormat("{0:x2}", b);
3536
}
36-
return "0x" + hex.ToString().PadRight(64, '0');
37+
return "0x" + hex.ToString().PadLeft(64, '0');
38+
}
39+
40+
public static long UnixTimeNowMs()
41+
{
42+
var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
43+
return (long) timeSpan.TotalMilliseconds;
3744
}
3845
}
3946
}

Assets/WebGLTemplates/Better2020/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
import { ThirdwebSDK } from "https://esm.sh/@thirdweb-dev/sdk@nightly?bundle"
8686
// import { ethers } from "https://cdn.ethers.io/lib/ethers-5.2.esm.min.js";
8787
// big number transform
88-
const bigNumberReplacer = (_key, value) => {
88+
const bigNumberReplacer = (key, value) => {
8989
// if we find a BigNumber then make it into a string (since that is safe)
9090
if (ethers.BigNumber.isBigNumber(value) ||
9191
(typeof value === "object" &&
@@ -98,7 +98,15 @@
9898
return value;
9999
};
100100

101-
let id = 0;
101+
const parserTransform = (key, value) => {
102+
// if we find a BigNumber then make it into a string (since that is safe)
103+
if (key.toLowerCase().includes("time")) {
104+
console.log("converting time", value);
105+
return new Date(value);
106+
}
107+
return value;
108+
};
109+
102110
const w = window;
103111
w.bridge = {};
104112
w.bridge.initialize = (chain) => {
@@ -121,7 +129,7 @@
121129
return null;
122130
}
123131
} else {
124-
console.error("Please install a wallet browser extension")
132+
console.error("Please install a wallet browser extension");
125133
return null;
126134
}
127135
}
@@ -130,10 +138,10 @@
130138
const routeArgs = route.split(".")
131139
const addr = routeArgs[0];
132140
const contract = await w.thirdweb.getContract(addr)
133-
const fnArgs = JSON.parse(payload).arguments;
141+
const fnArgs = JSON.parse(payload, parserTransform).arguments;
134142
const parsedArgs = fnArgs.map((arg) => {
135143
try {
136-
return JSON.parse(arg);
144+
return JSON.parse(arg, parserTransform);
137145
} catch (e) {
138146
return arg;
139147
}

0 commit comments

Comments
 (0)