Skip to content

Commit

Permalink
Merge pull request #152 from blocknative/develop
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
lnbc1QWFyb24 authored Jul 30, 2020
2 parents e79430a + 4b7a490 commit 7781629
Show file tree
Hide file tree
Showing 17 changed files with 1,417 additions and 975 deletions.
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-notify",
"version": "1.2.4",
"version": "1.3.0",
"description": "Show web3 users realtime transaction notifications",
"keywords": [
"ethereum",
Expand All @@ -9,8 +9,8 @@
"notifications"
],
"main": "dist/notify.umd.js",
"module": "dist/notify.esm.js",
"typings": "dist/src/notify.d.ts",
"module": "dist/notify.js",
"typings": "dist/types/notify.d.ts",
"files": [
"dist"
],
Expand All @@ -25,24 +25,28 @@
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@pyoner/svelte-ts-preprocess": "^1.2.1",
"@rollup/plugin-commonjs": "^12.0.0",
"@rollup/plugin-json": "^4.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@tsconfig/svelte": "^1.0.4",
"@types/lodash.debounce": "^4.0.6",
"@types/uuid": "^3.4.5",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"@wessberg/rollup-plugin-ts": "^1.2.34",
"babel-plugin-external-helpers": "^6.18.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"prettier": "^2.0.5",
"rollup": "^1.12.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup": "^2.3.4",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-typescript2": "0.21.0",
"svelte": "^3.12.1",
"svelte-check": "^1.0.0",
"svelte-i18n": "^1.1.2-beta",
"typescript": "^3.4.5"
"svelte-preprocess": "^4.0.0",
"tslib": "^2.0.0",
"typescript": "^3.9.3"
},
"dependencies": {
"bignumber.js": "^9.0.0",
Expand All @@ -52,8 +56,9 @@
"uuid": "^3.3.3"
},
"scripts": {
"build": "rollup -c && babel dist/notify.esm.js --out-file dist/notify.esm.js && babel dist/notify.umd.js --out-file dist/notify.umd.js --minified",
"build": "npm run validate && rollup -c && babel dist/notify.umd.js --out-file dist/notify.umd.js --minified",
"test": "echo \"TBD\" && exit 0",
"prepare": "npm run build"
"prepare": "npm run build",
"validate": "svelte-check"
}
}
52 changes: 19 additions & 33 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
import svelte from 'rollup-plugin-svelte'
import resolve from 'rollup-plugin-node-resolve'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import sveltePreprocess from 'svelte-preprocess'
import typescript from '@wessberg/rollup-plugin-ts'
import json from '@rollup/plugin-json'
import commonjs from 'rollup-plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'

import {
preprocess,
createEnv,
readConfigFile,
} from '@pyoner/svelte-ts-preprocess'

const env = createEnv()
const compilerOptions = readConfigFile(env)
const opts = {
env,
compilerOptions: {
...compilerOptions,
allowNonTsExtensions: true,
},
}

export default [
{
Expand All @@ -27,6 +12,7 @@ export default [
format: 'umd',
name: 'notify',
file: 'dist/notify.umd.js',
sourcemap: 'inline'
},
onwarn: (warning, warn) => {
if (warning.code === 'THIS_IS_UNDEFINED') {
Expand All @@ -38,23 +24,24 @@ export default [
plugins: [
json(),
svelte({
preprocess: preprocess(opts),
preprocess: sveltePreprocess()
}),
resolve({
browser: true,
dedupe: (importee) =>
importee === 'svelte' || importee.startsWith('svelte/'),
dedupe: ['svelte']
}),
commonjs(),
typescript(),
],
typescript({
tsconfig: resolvedConfig => ({ ...resolvedConfig, declaration: false })
})
]
},
{
input: 'src/notify.ts',
output: {
sourcemap: true,
format: 'es',
file: 'dist/notify.esm.js',
file: 'dist/notify.js',
sourcemap: 'inline'
},
onwarn: (warning, warn) => {
if (warning.code === 'THIS_IS_UNDEFINED') {
Expand All @@ -66,22 +53,21 @@ export default [
plugins: [
json(),
svelte({
preprocess: preprocess(opts),
preprocess: sveltePreprocess()
}),
resolve({
browser: true,
dedupe: (importee) =>
importee === 'svelte' || importee.startsWith('svelte/'),
dedupe: ['svelte']
}),
commonjs(),
typescript(),
typescript()
],
external: [
'bignumber.js',
'bnc-sdk',
'lodash.debounce',
'uuid/v4',
'regenerator-runtime/runtime',
],
},
'regenerator-runtime/runtime'
]
}
]
38 changes: 34 additions & 4 deletions src/components/NotificationContent.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
<script lang="ts">
import { timeString } from '../utilities'
import { _ as formatter } from 'svelte-i18n'
import { onDestroy } from 'svelte'
import { app } from '../stores'
import NotificationMessage from '../elements/NotificationMessage.svelte'
import Clock from '../elements/Clock.svelte'
import Time from '../elements/Time.svelte'
import Timer from '../elements/Timer.svelte'
function timeString(time: number): string {
const seconds = Math.floor(time / 1000)
const formattedSeconds = seconds < 0 ? 0 : seconds
return formattedSeconds >= 60
? `${Math.floor(formattedSeconds / 60).toLocaleString(
$app.clientLocale
)} ${$formatter('time.minutes')}`
: `${formattedSeconds.toLocaleString($app.clientLocale)} ${$formatter(
'time.seconds'
)}`
}
function formatTime(number: number): string {
const time = new Date(number)
return time.toLocaleString($app.clientLocale, {
hour: 'numeric',
minute: 'numeric',
hour12: true
})
}
export let notification: {
id: string
type: string
Expand All @@ -15,8 +37,16 @@
message: string
autoDismiss?: number
}
export let formattedTime: string
export let currentTime: number
let currentTime = Date.now()
const intervalId = setInterval(() => {
currentTime = Date.now()
}, 1000)
onDestroy(() => {
clearInterval(intervalId)
})
</script>

<style>
Expand Down Expand Up @@ -55,7 +85,7 @@
<NotificationMessage message={notification.message} />
<p
class="bn-notify-custom bn-notify-notification-info-meta {$app.name ? `bn-notify-${$app.name}` : ''}">
<Time time={formattedTime} />
<Time time={formatTime(currentTime)} />
{#if notification.type === 'pending' && notification.startTime}
<span
class="bn-notify-custom bn-notify-notification-info-meta-duration {$app.name ? `bn-notify-${$app.name}` : ''}">
Expand Down
2 changes: 1 addition & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NotificationType } from './interfaces'
import type { NotificationType } from './interfaces'

export function eventToType(eventCode: string | undefined): NotificationType {
switch (eventCode) {
Expand Down
8 changes: 8 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const defaultNotifyMessages: any = {
'Your account successfully {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}',
txFailed:
'Your account failed to {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}'
},
time: {
minutes: 'min',
seconds: 'sec'
}
},
es: {
Expand Down Expand Up @@ -71,6 +75,10 @@ export const defaultNotifyMessages: any = {
'su cuenta {verb, select, received {recibió} sent {ha enviado}} con éxito {formattedValue} {asset} {preposition, select, from {de} to {a}} {counterpartyShortened}',
txFailed:
'su cuenta fallado {verb, select, received {recibió} sent {ha enviado}} con éxito {formattedValue} {asset} {preposition, select, from {de} to {a}} {counterpartyShortened}'
},
time: {
minutes: 'min',
seconds: 'sec'
}
}
}
15 changes: 9 additions & 6 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export interface LocaleMessages {
watched: {
[key: string]: string
}
time: {
[key: string]: string
}
}

export interface TransactionOptions {
Expand Down Expand Up @@ -173,32 +176,32 @@ export interface ConfigOptions {
clientLocale?: string
}

interface Hash {
export interface Hash {
(hash: string, id?: string):
| never
| { details: TransactionLog; emitter: Emitter }
}

interface Transaction {
export interface Transaction {
(options: TransactionOptions): { result: Promise<string>; emitter: Emitter }
}

interface Account {
export interface Account {
(address: string): never | { details: { address: string }; emitter: Emitter }
}

interface Unsubscribe {
export interface Unsubscribe {
(addressOrHash: string): void
}

interface Notification {
export interface Notification {
(notificationObject: CustomNotificationObject): {
dismiss: () => void
update: UpdateNotification
}
}

interface Config {
export interface Config {
(options: ConfigOptions): void
}

Expand Down
2 changes: 1 addition & 1 deletion src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { notifications } from './stores'
import { eventToType, typeToDismissTimeout } from './defaults'
import { defaultNotifyMessages } from './i18n'

import {
import type {
CustomNotificationObject,
TransactionData,
NotificationType,
Expand Down
54 changes: 46 additions & 8 deletions src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { handleTransactionEvent, preflightTransaction } from './transactions'
import { createNotification } from './notifications'

import { getBlocknative } from './services'
import { LocaleMessages } from './interfaces'

import {
import type {
InitOptions,
TransactionHandler,
AppStore,
Expand All @@ -22,7 +21,43 @@ import {
TransactionOptions,
CustomNotificationObject,
UpdateNotification,
ConfigOptions
ConfigOptions,
LocaleMessages
} from './interfaces'

export type {
InitOptions,
TransactionHandler,
TransactionEvent,
System,
TransactionEventCode,
TransactionData,
NotificationType,
CustomNotificationObject,
BitcoinInputOutput,
NotificationObject,
ContractObject,
AppStore,
NotifyMessages,
LocaleMessages,
TransactionOptions,
PreflightEvent,
UpdateNotification,
ConfigOptions,
Hash,
Transaction,
Account,
Unsubscribe,
Notification,
Config,
API,
TransactionLog,
EmitterListener,
Emitter,
NotificationDetails,
WritableStore,
TransactionStore,
NotificationStore
} from './interfaces'

import {
Expand Down Expand Up @@ -52,7 +87,8 @@ function init(options: InitOptions): API {
networkId,
transactionHandler,
name,
apiUrl
apiUrl,
clientLocale
} = options

const transactionHandlers: TransactionHandler[] = [handleTransactionEvent]
Expand All @@ -75,10 +111,12 @@ function init(options: InitOptions): API {
...store,
...options,
version,
clientLocale: getClientLocale({
fallback: 'en',
navigator: true
})
clientLocale:
clientLocale ||
getClientLocale({
fallback: 'en',
navigator: true
})
}))

// initialize App
Expand Down
Loading

0 comments on commit 7781629

Please sign in to comment.