-
Notifications
You must be signed in to change notification settings - Fork 108
add initial mobx infrastructure #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f4754f4
chore: add configs for eslint, prettier, import-sorter
jamaljsr b183036
feat: add GRPC wrapper classes for lnd & loop
jamaljsr 72de418
feat: add initial store and actions for mobx
jamaljsr a30215c
test: add initial unit tests
jamaljsr 75916b4
chore: add .env.local for environment local vars
jamaljsr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,117 @@ | ||
import { ProtobufMessage } from '@improbable-eng/grpc-web/dist/typings/message'; | ||
import { UnaryMethodDefinition } from '@improbable-eng/grpc-web/dist/typings/service'; | ||
import { UnaryRpcOptions } from '@improbable-eng/grpc-web/dist/typings/unary'; | ||
|
||
// mock grpc module | ||
export const grpc = { | ||
Code: { | ||
OK: 0, | ||
Canceled: 1, | ||
}, | ||
// mock unary function to simulate GRPC requests | ||
unary: <TReq extends ProtobufMessage, TRes extends ProtobufMessage>( | ||
methodDescriptor: UnaryMethodDefinition<TReq, TRes>, | ||
props: UnaryRpcOptions<TReq, TRes>, | ||
) => { | ||
const path = `${methodDescriptor.service.serviceName}.${methodDescriptor.methodName}`; | ||
// return a response by calling the onEnd function | ||
props.onEnd({ | ||
status: 0, | ||
statusMessage: '', | ||
// the message returned should have a toObject function | ||
message: { | ||
toObject: () => mockApiResponses[path], | ||
} as TRes, | ||
headers: {} as any, | ||
trailers: {} as any, | ||
}); | ||
}, | ||
}; | ||
|
||
// collection of mock API responses | ||
const mockApiResponses: Record<string, any> = { | ||
'lnrpc.Lightning.GetInfo': { | ||
version: '0.9.0-beta commit=v0.9.0-beta', | ||
identityPubkey: '038b3fc29cfc195c9b190d86ad2d40ce7550a5c6f13941f53c7d7ac5b25c912a6c', | ||
alias: 'alice', | ||
color: '#cccccc', | ||
numPendingChannels: 0, | ||
numActiveChannels: 1, | ||
numInactiveChannels: 0, | ||
numPeers: 1, | ||
blockHeight: 185, | ||
blockHash: '547d3dcfb7d56532bed2efdeea0d400f11167b34d493bcd45fedb21f2ef7ed43', | ||
bestHeaderTimestamp: 1586548672, | ||
syncedToChain: false, | ||
syncedToGraph: true, | ||
testnet: false, | ||
chainsList: [{ chain: 'bitcoin', network: 'regtest' }], | ||
urisList: [ | ||
'038b3fc29cfc195c9b190d86ad2d40ce7550a5c6f13941f53c7d7ac5b25c912a6c@172.18.0.7:9735', | ||
], | ||
featuresMap: [ | ||
[0, { name: 'data-loss-protect', isRequired: true, isKnown: true }], | ||
[13, { name: 'static-remote-key', isRequired: false, isKnown: true }], | ||
[15, { name: 'payment-addr', isRequired: false, isKnown: true }], | ||
[17, { name: 'multi-path-payments', isRequired: false, isKnown: true }], | ||
[5, { name: 'upfront-shutdown-script', isRequired: false, isKnown: true }], | ||
[7, { name: 'gossip-queries', isRequired: false, isKnown: true }], | ||
[9, { name: 'tlv-onion', isRequired: false, isKnown: true }], | ||
], | ||
}, | ||
'lnrpc.Lightning.ListChannels': { | ||
channelsList: [ | ||
{ | ||
active: true, | ||
remotePubkey: | ||
'037136742c67e24681f36542f7c8916aa6f6fdf665c1dca2a107425503cff94501', | ||
channelPoint: | ||
'0ef6a4ae3d8f800f4eb736f0776f5d3a72571615a1b7218ab17c9a43f85d8949:0', | ||
chanId: '124244814004224', | ||
capacity: 15000000, | ||
localBalance: 9988660, | ||
remoteBalance: 4501409, | ||
commitFee: 11201, | ||
commitWeight: 896, | ||
feePerKw: 12500, | ||
unsettledBalance: 498730, | ||
totalSatoshisSent: 1338, | ||
totalSatoshisReceived: 499929, | ||
numUpdates: 6, | ||
pendingHtlcsList: [ | ||
{ | ||
incoming: false, | ||
amount: 498730, | ||
hashLock: 'pl8fmsyoSqEQFQCw6Zu9e1aIlFnMz5H+hW2mmh3kRlI=', | ||
expirationHeight: 285, | ||
}, | ||
], | ||
csvDelay: 1802, | ||
pb_private: false, | ||
initiator: true, | ||
chanStatusFlags: 'ChanStatusDefault', | ||
localChanReserveSat: 150000, | ||
remoteChanReserveSat: 150000, | ||
staticRemoteKey: true, | ||
lifetime: 21802, | ||
uptime: 21802, | ||
closeAddress: '', | ||
}, | ||
], | ||
}, | ||
'looprpc.SwapClient.ListSwaps': { | ||
swapsList: [...Array(7)].map((x, i) => ({ | ||
amt: 500000, | ||
id: 'f4eb118383c2b09d8c7289ce21c25900cfb4545d46c47ed23a31ad2aa57ce835', | ||
idBytes: '9OsRg4PCsJ2MconOIcJZAM+0VF1GxH7SOjGtKqV86DU=', | ||
type: i % 3, | ||
state: i, | ||
initiationTime: 1586390353623905000, | ||
lastUpdateTime: 1586398369729857000, | ||
htlcAddress: 'bcrt1qzu4077erkr78k52yuf2rwkk6ayr6m3wtazdfz2qqmd7taa5vvy9s5d75gd', | ||
costServer: 66, | ||
costOnchain: 6812, | ||
costOffchain: 2, | ||
})), | ||
}, | ||
}; |
This file contains hidden or 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,20 @@ | ||
import ChannelAction from 'action/channel'; | ||
import LndApi from 'api/lnd'; | ||
import { Store } from 'store'; | ||
|
||
describe('ChannelAction', () => { | ||
let store: Store; | ||
let channel: ChannelAction; | ||
|
||
beforeEach(() => { | ||
const lndApiMock = new LndApi(); | ||
store = new Store(); | ||
channel = new ChannelAction(store, lndApiMock); | ||
}); | ||
|
||
it('should fetch list of channels', async () => { | ||
expect(store.channels).toEqual([]); | ||
await channel.getChannels(); | ||
expect(store.channels).toHaveLength(1); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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,21 @@ | ||
import NodeAction from 'action/node'; | ||
import LndApi from 'api/lnd'; | ||
import { Store } from 'store'; | ||
|
||
describe('NodeAction', () => { | ||
let store: Store; | ||
let node: NodeAction; | ||
|
||
beforeEach(() => { | ||
const lndApiMock = new LndApi(); | ||
store = new Store(); | ||
node = new NodeAction(store, lndApiMock); | ||
}); | ||
|
||
it('should fetch list of channels', async () => { | ||
expect(store.info).toBeUndefined(); | ||
await node.getInfo(); | ||
expect(store.info).toBeDefined(); | ||
expect(store.info?.alias).toEqual('alice'); | ||
}); | ||
}); |
This file contains hidden or 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,20 @@ | ||
import SwapAction from 'action/swap'; | ||
import LoopApi from 'api/loop'; | ||
import { Store } from 'store'; | ||
|
||
describe('SwapAction', () => { | ||
let store: Store; | ||
let loop: SwapAction; | ||
|
||
beforeEach(() => { | ||
const loopApiMock = new LoopApi(); | ||
store = new Store(); | ||
loop = new SwapAction(store, loopApiMock); | ||
}); | ||
|
||
it('should fetch list of channels', async () => { | ||
expect(store.swaps).toEqual([]); | ||
await loop.listSwaps(); | ||
expect(store.swaps).toHaveLength(7); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.