-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-backend): introduce web-monetization payment pointers (#896)
* fix(wallet-backend): env parsing * feat(wallet-backend) add caching * fix(wallet-backend): docker-compose dev variable names * feat(wallet-backend): introduce web monetized payment pointers module * feat(wallet-backend): update balance now only does balance add register key and revoke key to wmPaymentPointerService move wm module out of paymentPointers directory * feat(wallet-backend): WM payment pointers: use revoke and register key in paymentPointerService to also apply changes to WMPaymentPointers getAccounts for user now also returns wmPaymentPointers getRafikiAsset can now receive an assetScale filter param along with the assetCode one * chore(wallet-backend): remove comment * fix(wallet-backend): wm get shouldn't throw * chore(wallet-backend): wmPp get method refactor * move wmPaymentPointerModel into paymentPointerModule * move wmPaymentPointers to PaymentPointers * add REDIS_URL to prod env.example * cache service now has a generic type across the cache * rename CacheService to Cache * list now returns 2 arrays of wm or not wm paymentPointers * update frontend to match list response * remove leftover wmPaymentPointers relation on getAccounts * format * add concat on paymentPointers response to transactions list as well * lint * fix frontend error * fix frontend error * add redis_url default value in env * accountId is now optional on Payment pointer getByID * update balance no longer needs accoutId * format & errors * resolve PR comments * remove wmPaymentPointers from the account page payment pointers list * format
- Loading branch information
1 parent
75a01f3
commit 4c06043
Showing
24 changed files
with
415 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
packages/wallet/backend/migrations/20231013113754_add_wm_payment_pointers_table.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/wallet/backend/migrations/20231018084125_update_payment_pointers_table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return knex.schema.alterTable('paymentPointers', (table) => { | ||
table.boolean('isWM').defaultTo(false) | ||
table.string('assetCode', 3) | ||
table.smallint('assetScale') | ||
table.decimal('balance', 10, 2).defaultTo(0) | ||
}) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.alterTable('paymentPointers', (table) => { | ||
table.dropColumn('isWM') | ||
table.dropColumn('assetCode') | ||
table.dropColumn('assetScale') | ||
table.dropColumn('balance') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Redis } from 'ioredis' | ||
|
||
export type EntryOptions = { | ||
expiry?: number | ||
} | ||
|
||
export interface IRedisClient { | ||
set<T>( | ||
key: string, | ||
value: T | string, | ||
options?: EntryOptions | ||
): Promise<string> | ||
get<T>(key: string): Promise<T | null> | ||
delete(key: string): Promise<number> | ||
} | ||
|
||
export class RedisClient implements IRedisClient { | ||
constructor(private redis: Redis) {} | ||
|
||
async set<T>( | ||
key: string, | ||
value: T | string, | ||
options?: EntryOptions | ||
): Promise<string> { | ||
const serializedValue = | ||
typeof value === 'string' ? value : JSON.stringify(value) | ||
|
||
if (options?.expiry) { | ||
return await this.redis.set(key, serializedValue, 'EX', options.expiry) | ||
} | ||
|
||
return await this.redis.set(key, serializedValue) | ||
} | ||
|
||
async get<T>(key: string): Promise<T | null> { | ||
const serializedValue = await this.redis.get(key) | ||
if (serializedValue) { | ||
return typeof serializedValue === 'string' | ||
? (JSON.parse(serializedValue) as T) | ||
: serializedValue | ||
} | ||
return null | ||
} | ||
|
||
async delete(key: string): Promise<number> { | ||
return await this.redis.del(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { EntryOptions, IRedisClient } from './redis-client' | ||
|
||
export interface ICacheService<T> { | ||
set(key: string, value: T | string): Promise<string> | ||
get(key: string): Promise<T | null> | ||
delete(key: string): Promise<number> | ||
} | ||
|
||
export class Cache<T> implements ICacheService<T> { | ||
private namespace: string = 'Testnet:' | ||
|
||
constructor( | ||
private cache: IRedisClient, | ||
namespace: string | ||
) { | ||
this.namespace = this.namespace + namespace + ':' | ||
} | ||
|
||
async set( | ||
key: string, | ||
value: T | string, | ||
options?: EntryOptions | ||
): Promise<string> { | ||
const namespacedKey = this.namespace + key | ||
return await this.cache.set<T>(namespacedKey, value, options) | ||
} | ||
|
||
async get(key: string): Promise<T | null> { | ||
const namespacedKey = this.namespace + key | ||
return await this.cache.get<T>(namespacedKey) | ||
} | ||
|
||
async delete(key: string): Promise<number> { | ||
const namespacedKey = this.namespace + key | ||
return await this.cache.delete(namespacedKey) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.