-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple recipients in rpc send transfer method, closes #…
- Loading branch information
1 parent
b4b1d11
commit a470a57
Showing
8 changed files
with
219 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { formatMoney } from '@app/common/money/format-money'; | ||
import { useCurrentNativeSegwitAddressBalance } from '@app/query/bitcoin/balance/btc-native-segwit-balance.hooks'; | ||
import { Caption } from '@app/ui/components/typography/caption'; | ||
|
||
export function BtcBalance() { | ||
const { balance } = useCurrentNativeSegwitAddressBalance(); | ||
import { BitcoinNativeSegwitAccountLoader } from './account/bitcoin-account-loader'; | ||
import { BitcoinBalanceLoader } from './balance/bitcoin-balance-loader'; | ||
|
||
return <Caption>{formatMoney(balance)}</Caption>; | ||
export function BtcBalance() { | ||
return ( | ||
<BitcoinNativeSegwitAccountLoader current> | ||
{signer => ( | ||
<BitcoinBalanceLoader address={signer.address}> | ||
{balance => <Caption>{formatMoney(balance.balance)}</Caption>} | ||
</BitcoinBalanceLoader> | ||
)} | ||
</BitcoinNativeSegwitAccountLoader> | ||
); | ||
} |
44 changes: 28 additions & 16 deletions
44
src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx
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 |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import { HStack, Stack, styled } from 'leather-styles/jsx'; | ||
|
||
import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; | ||
|
||
import { truncateMiddle } from '@app/ui/utils/truncate-middle'; | ||
|
||
interface SendTransferDetailsProps { | ||
address: string; | ||
amount: string; | ||
recipients: RpcSendTransferRecipient[]; | ||
currentAddress: string; | ||
} | ||
export function SendTransferDetails({ address, amount, currentAddress }: SendTransferDetailsProps) { | ||
export function SendTransferDetails({ recipients, currentAddress }: SendTransferDetailsProps) { | ||
return ( | ||
<Stack border="active" borderRadius="sm" gap="space.04" p="space.05" width="100%"> | ||
<HStack alignItems="center" gap="space.04" justifyContent="space-between"> | ||
<styled.span textStyle="caption.01">From</styled.span> | ||
<styled.span textStyle="label.01">{truncateMiddle(currentAddress)}</styled.span> | ||
</HStack> | ||
<HStack alignItems="center" gap="space.04" justifyContent="space-between"> | ||
<styled.span textStyle="caption.01">To</styled.span> | ||
<styled.span textStyle="label.01">{truncateMiddle(address)}</styled.span> | ||
</HStack> | ||
<HStack alignItems="center" gap="space.04" justifyContent="space-between"> | ||
<styled.span textStyle="caption.01">Amount</styled.span> | ||
<styled.span textStyle="label.01">{amount}</styled.span> | ||
</HStack> | ||
<Stack width="100%"> | ||
{recipients.map(({ address, amount }, index) => ( | ||
<Stack | ||
key={address + index} | ||
border="active" | ||
borderRadius="sm" | ||
gap="space.04" | ||
p="space.05" | ||
width="100%" | ||
> | ||
<HStack alignItems="center" gap="space.04" justifyContent="space-between"> | ||
<styled.span textStyle="caption.01">From</styled.span> | ||
<styled.span textStyle="label.01">{truncateMiddle(currentAddress)}</styled.span> | ||
</HStack> | ||
<HStack alignItems="center" gap="space.04" justifyContent="space-between"> | ||
<styled.span textStyle="caption.01">To</styled.span> | ||
<styled.span textStyle="label.01">{truncateMiddle(address)}</styled.span> | ||
</HStack> | ||
<HStack alignItems="center" gap="space.04" justifyContent="space-between"> | ||
<styled.span textStyle="caption.01">Amount</styled.span> | ||
<styled.span textStyle="label.01">{amount}</styled.span> | ||
</HStack> | ||
</Stack> | ||
))} | ||
</Stack> | ||
); | ||
} |
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
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,70 @@ | ||
import { | ||
convertRpcSendTransferLegacyParamsToNew, | ||
rpcSendTransferParamsSchema, | ||
rpcSendTransferParamsSchemaLegacy, | ||
} from './send-transfer'; | ||
|
||
describe('`sendTransfer` method', () => { | ||
describe('schema validation', () => { | ||
test('that it validates single recipient sends', () => { | ||
const params = { | ||
network: 'mainnet', | ||
account: 0, | ||
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', | ||
amount: '0.0001', | ||
}; | ||
|
||
expect(rpcSendTransferParamsSchemaLegacy.isValidSync(params)).toBeTruthy(); | ||
}); | ||
|
||
test('that it validates multiple recipient sends', () => { | ||
const params = { | ||
network: 'mainnet', | ||
account: 0, | ||
recipients: [ | ||
{ | ||
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', | ||
amount: '0.0001', | ||
}, | ||
{ | ||
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', | ||
amount: '0.0001', | ||
}, | ||
], | ||
}; | ||
|
||
expect(rpcSendTransferParamsSchema.isValidSync(params)).toBeTruthy(); | ||
}); | ||
|
||
test('that it fails validation for missing required fields', () => { | ||
const params = { | ||
network: 'mainnet', | ||
account: 0, | ||
}; | ||
|
||
expect(() => rpcSendTransferParamsSchema.validateSync(params)).toThrow(); | ||
}); | ||
|
||
test('that it converts legacy params to new params', () => { | ||
const legacyParams = { | ||
network: 'mainnet', | ||
account: 0, | ||
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', | ||
amount: '0.0001', | ||
}; | ||
|
||
const newParams = { | ||
network: 'mainnet', | ||
account: 0, | ||
recipients: [ | ||
{ | ||
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', | ||
amount: '0.0001', | ||
}, | ||
], | ||
}; | ||
|
||
expect(convertRpcSendTransferLegacyParamsToNew(legacyParams)).toEqual(newParams); | ||
}); | ||
}); | ||
}); |
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