Skip to content

Commit

Permalink
chore: refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jan 10, 2024
1 parent 52085ab commit 659aef2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (svc *Service) AppsCreateHandler(c echo.Context) error {
methodsToCreate := strings.Split(requestMethods, " ")
for _, m := range methodsToCreate {
//if we don't know this method, we return an error
if !validNIP47Methods[m] {
if !strings.Contains(NIP_47_CAPABILITIES, m) {
return fmt.Errorf("Did not recognize request method: %s", m)
}
appPermission := AppPermission{
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/screens/apps/NewApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,31 @@ const NewApp = () => {
parseInt(maxAmountParam || "100000")
);

// returns ISO string
const parseExpiresParam = (expiresParam: string): string => {
if (/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(expiresParam)) {
const d = new Date(expiresParam);
const isIso =
d instanceof Date &&
!isNaN(d.getTime()) &&
d.toISOString() === expiresAtParam;
d.toISOString() === expiresParam;
if (isIso) {
return expiresParam;
}
}
console.info(expiresParam);
if (!isNaN(parseInt(expiresParam))) {
return new Date(parseInt(expiresAtParam as string) * 1000).toISOString();
console.info(
new Date(parseInt(expiresParam as string) * 1000).toISOString()
);
return new Date(parseInt(expiresParam as string) * 1000).toISOString();
}
return "";
};

// Only timestamp in seconds or ISO string is expected
const expiresAtParam = parseExpiresParam(queryParams.get("expires_at") ?? "");
console.info(expiresAtParam);
const [expiresAt, setExpiresAt] = useState(expiresAtParam ?? "");
const [days, setDays] = useState(0);
const [expireOptions, setExpireOptions] = useState(false);
Expand Down Expand Up @@ -349,7 +355,7 @@ const NewApp = () => {
Connection expiry time
</p>
<p className="text-gray-600 dark:text-gray-300 text-sm">
{new Date(parseInt(expiresAtParam) * 1000).toISOString()}
{new Date(expiresAtParam).toLocaleString()}
</p>
</>
)}
Expand Down
9 changes: 0 additions & 9 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ const (
NOSTR_EVENT_STATE_PUBLISH_UNCONFIRMED = "sent"
)

var validNIP47Methods = map[string]bool{
NIP_47_GET_BALANCE_METHOD: true,
NIP_47_GET_INFO_METHOD: true,
NIP_47_PAY_INVOICE_METHOD: true,
NIP_47_MAKE_INVOICE_METHOD: true,
NIP_47_LOOKUP_INVOICE_METHOD: true,
NIP_47_LIST_TRANSACTIONS_METHOD: true,
}

// TODO: move to models/Alby
type AlbyMe struct {
Identifier string `json:"identifier"`
Expand Down

0 comments on commit 659aef2

Please sign in to comment.